Reputation: 737
I am trying to run mocha tests on linux > @ test C:\Users\wd.ssh\tel\qa_test\mocha-api-tests
Error: No test files found: "test/" npm ERR! Test failed. See above for more details.
here is my package.json
{
"scripts": {
"test": "mocha --reporter mocha-junit-reporter --timeout 60000 --exit",
},
"dependencies": {
"cassandra-driver": "3.5.0",
"chai": "4.2.0",
"chai-http": "4.2.0",
"express": "4.16.4",
"mocha-junit-reporter": "1.18.0",
"request-promise": "4.2.2"
}
}
commands used: npm install --global mocha npm i and to run the tests I'm using npm test
Project structure:
Upvotes: 47
Views: 65471
Reputation: 59
Mocha automatically searches for folder called test and should be in root folder as package.json
Upvotes: 6
Reputation: 37
Also had this problem and this worked for me:
./node_modules/mocha/bin/mocha -r esm -r ts-node/register "src/**/*Test.ts"
Upvotes: 1
Reputation: 129
I fixed the same problem ...
"test": "mocha -r ts-node/register 'tests/**/*.ts'"
Upvotes: 5
Reputation: 4758
One reason this happened to me with saving the test file without extension. Yep, I did it once and Mocha couldn't detect the file and run the tests. Make sure it has at least .js as extension. Notice that some IDEs may already show the file as JS (as it detects the file content), but you still need to have the extension of the file as JS.
Upvotes: 2
Reputation: 49729
If there is no test file directly in the test folder, you will get that error.
Solution is add "--recursive" option to your test in the package.json.
"scripts": {
"test": "mocha --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",
},
this will tell mocha that "look recursively for the test files"
Upvotes: 8
Reputation: 8443
seeing your project structure, seems that you have one test.js
so mocha should target this file.
"scripts": {
"test": "mocha test.js --reporter mocha-junit-reporter --timeout 60000 --exit",
},
If you want to add more test files, it is better to put them inside test directory e.g. /test
and must change the target to test files inside the directory.
"scripts": {
"test": "mocha 'test/**/*.js' --recursive --reporter mocha-junit-reporter --timeout 60000 --exit",
},
Hope it helps
Upvotes: 44
Reputation: 111
you need to provide the path to the test folder. try this:
"scripts": {
"test": "mocha qa_test/**/*.js --reporter mocha-junit-reporter --timeout 60000 --exit",
},
npm test
Upvotes: 11