简体   繁体   中英

How to configure mocha to find all test files recursively?

How can I configure mocha to find all test files in my project directory and not only the test files at the test folder in the root directory?

currently, I'm using npm scripts in package.json:

"test": "mocha"

and running using the following command:

npm run test

To find all test files in your src directory, say, then you should be able to use a pattern like this:

mocha "src/**/*.test.js"

...and make sure your test files have a .test.js file extension so they differ from your other .js files.

(Note the double quotes around the pattern)

this works for me, finding all test files in all directories except the node_modules

mocha \"./{,!(node_modules)/**/}*.test.js\"

for clarification, this glop expression says:

Take all files which end with .test.js in the current directory - which is the root - or in any subdirectory of the current directory, regardless of depth, except for ones that exists in ./node_modules folder.

For me "test": "./src/**/*.test.js" was not working, I've to add escaped quotes in the directory pattern

{
 "scripts": {
    "test": "mocha \"./src/tests/**/*.test.js\""
  }
}

I was testing this out and wanted to try to run only one of the test files(not it tests, but actual separate files) in the terminal using mocha, but can't seem to come around it.

I attached a screenshot below for explanation.

What I want to do is have only my test for killer robot run and not the app test.

VS code image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM