当不在默认的“/test”文件夹中时,将 Mocha Test Explorer 与 VScode 一起使用

Using Mocha Test Explorer with VScode when not in default `/test' folder

我目前正在开发一个项目,其中测试文件存储在 /code_tests 而不是默认的 /test。我试图避免重命名文件夹,但我似乎无法更改 Mocha 测试资源管理器的默认位置。

该项目正在 vscode 上使用 Typescript。

文档提供了这行代码。 "mochaExplorer.files": "test/**/*.ts" 我认为需要更改为 "mochaExplorer.files": "code_tests/**/*.ts" 但我似乎无法找到存储此命令的位置以使其按预期工作。

将这些添加到 vscode settings.json

"mochaExplorer.require": "ts-node/register",
"mochaExplorer.files": "code_tests/**/*.ts",

好吧,如果您的项目结构中没有 .vscode 文件夹,请创建一个。并在 .vscode/settings.json 添加以下内容

"mochaExplorer.require": "ts-node/register",
"mochaExplorer.files": "tests/**/*.ts",

我 运行 遇到了类似的问题,并认为我已经配置了我的 .mocharc.json 文件 correctly。但是,我发现我需要将要测试的文件指定为 "spec": "path/to/files/*.extension" 而不是 "files": "path/to/files/*.extension".

看来 "files" 是一个较旧的规范,它似乎在命令行下运行良好,但不适用于某些工具,例如 VS Code Mocha Explorer。