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

Viewed 4643

I am currently working on a project where the test files are stored in /code_tests instead of the default /test. I am trying to avoid having to rename the folder but I can't seem to change the default location for the Mocha Test Explorer.

The project is using Typescript on vscode.

The documentation provides this line of code. "mochaExplorer.files": "test/**/*.ts" which I assume would need to be changed to "mochaExplorer.files": "code_tests/**/*.ts" but I can't seem to find where to store this command for it to work as intended.

3 Answers

add these to vscode settings.json

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

Well if you don't have .vscode folder in you project structure, create one. And in .vscode/settings.json add the following

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

I ran into a similar problem and thought I had configured my .mocharc.json file correctly. However, I found that I needed to specify the files that I wanted tested as "spec": "path/to/files/*.extension" instead of "files": "path/to/files/*.extension".

It appears that "files" is an older specification, which seemed to work fine at the command line, but doesn't work for some tools like in VS Code Mocha Explorer.

Related