Why the plugin doesn't see files when files 100% exist in my test folder?
I want to run test for certain files only.
How do I do it with mocha?
My set up:
// test folder. Files are the same. Changed name for the sake of showing you an error
/test
nock.js
nock_test.js
// package.json
"scripts": { "test": "mocha" }
None of these work. All throw the same error:
$ npm test nock
$ npm test nock.js
$ npm test nock_test
$ npm test nock_test.js
Error:
Warning: Could not find any test files matching pattern: nock
Warning: Could not find any test files matching pattern: nock.js
Warning: Could not find any test files matching pattern: nock_test
Warning: Could not find any test files matching pattern: nock_test.js
No test files found
npm ERR! Test failed. See above for more details.
How it can be? No test files matching pattern? It is not even a pattern! It is exactly a file name.
How to run it?
You should be writing test/nock.js/test/test_nock.js instead of just nock.js/test_nock.js. Please let us know if that resolves your issue!
(Mocha supports putting your test files in other folders than test; for example, some projects put test files in the same folders as corresponding source files and with the same name except using .test.js or .spec.js instead of .js at the end of the test file's name. It's a tradeoff between cleanliness of source directories vs ease of association of test and source, but the important thing is Mocha supports both and therefore won't prevent the one by turning lib/someModule.spec.js into test/lib/someModule.spec.js.)
In my project:
"test": "mocha --compilers js:babel-core/register -r ./test/setup.js './src/**/*.spec.js*'"When i run npm test:
Warning: Could not find any test files matching pattern: './src/*/.spec.js*'
Please, help me!
It looks like mocha is including the single quotes in the pattern itself. I was able to get around it by using escaped double quotes:
"test": "mocha --compilers js:babel-core/register -r ./test/setup.js \"./src/**/*.spec.js*\""
Hi ! I have same issue, but here with Circle CI 2.0 (Ubuntu 14.04)
Works fine on MacOSX and Ubuntu 16.04, how could i solve this error with Circle CI environment ? Seems to be a Mocha trick... Thanks a lot !
In my term :
$ eslint .
$ mocha "./src/migrations/index.test.js" --require babel-core/register
Warning: Could not find any test files matching pattern: ./src/migrations/index.test.js
No test files found
error Command failed with exit code 1.
My package.json :
...
"test-migrations": "mocha \"./src/migrations/index.test.js\" --require babel-core/register",
"test": "yarn run lint && yarn run test-migrations && mocha \"./src/index.test.js\" --require babel-core/register",
...
I have a similar issue :
mocha --opts "/c/my-project/mocha.opts" "/c/my-project/src/rest_test/**/*.tsx"
Doesn't work.
However, this does :
mocha --opts "/c/my-project/mocha.opts" "c:/my-project/src/rest_test/**/*.tsx"
(notice the /c/ becoming c:/)
The options path is alright with a unix-notation, but not the test files path.
@xurei's is the only thing I've seen here that could be an actual Mocha bug. I'll try to reproduce this.
@xurei What shell are you using?
If you're in PowerShell, glob (which interprets your glob-containing path, because it's in double-quotes) expects your paths to look like your second example; the first example is not a valid path, AFAICT.
If you're in bash on Windows, then either should work, at least in my limited testing.
@boneskull I'm using Git BASH
My package.json has this:
"test": "mocha server/spec/server-spec.js; RES=$?; kill %1; exit $RES"
And my file structure is:
server
spec
server-spec.js
And, of course, I'm currently in the root directory where the server directory is located, but when I run npm test I get that error:
Warning: Could not find any test files matching pattern: server/spec/server-spec.js;
I'm using a Windows OS. I've tried cmd.exe (Cygwin is installed and added to the environment variables) & Git Bash, but I get the same result... Any idea?
@MuhammadJamaluddin, you _should_ be able to just have:
"scripts": {
"test": "mocha server/spec/server-spec.js"
}
Depending on what version of mocha you're using, you may see something helpful in the debug output by using cross-env and launching it like this:
$ npm install --save-dev cross-env
```json
"scripts": {
"test": "cross-env DEBUG=* mocha server/spec/server-spec.js"
}
Or use a glob and just see what mocha finds... JIC you misspelled something...
```json
"scripts": {
"test": "cross-env DEBUG=* mocha 'server/**/*.js'"
}
Most helpful comment
It looks like mocha is including the single quotes in the pattern itself. I was able to get around it by using escaped double quotes: