-
-
Save timoxley/1721593 to your computer and use it in GitHub Desktop.
// this will find all files ending with _test.js and run them with Mocha. Put this in your package.json | |
"scripts": { | |
"test": "find ./tests -name '*_test.js' | xargs mocha -R spec" | |
}, | |
Does this work in windows? isnt find command for linux ?
I have test:unix : ""test:": "NODE_ENV=testing ./node_modules/mocha/bin/mocha $(find ./test -path '.tests') --reporter spec", -- which works for linux,
I have "test:win": "set NODE_ENV=testing&& node node_modules/mocha/bin/mocha **dont know what to replace it with here ** --reporter spec",
-- Answering my own concern
replacing $(find ./test -path '.tests') with mocha ./test --recursive -- works in Windows
@Byloor, Near as I can tell, your solution seems to work on both Windows and *NIX systems. This is the form I used:
"unit": "cross-env NODE_ENV=test LOG_LEVEL=silent nyc mocha ./test/unit -name '*_test.js' --recursive --compilers js:babel-core/register -R spec"
@lxjwlt, Gracias! This was the simple fix for me. Single quotes also allow you to avoid escaping.
"scripts": {
"test": "mocha --require test-setup.js './**/*.spec.js'"
}
Single quotes are not working for me in Windows 10.
mocha './**/*.spec.js'
Warning: Could not find any test files matching pattern: './**/*.spec.js'
No test files found
npm ERR! Test failed. See above for more details.
@lxjwlt, Gracias! This was the simple fix for me. Single quotes also allow you to avoid escaping.
"scripts": { "test": "mocha --require test-setup.js './**/*.spec.js'" }
Also, to avoid using a pipe, you can use this version of find
:
"scripts": {
"test": "find src -name '*.spec.js' -exec mocha --require @babel/register {} \\;"
}
Where:
src
is the folder where to find your unit test scripts.*.spec.js
is the regular expression that will match the files you want to use withmocha
.@babel/register
a register to use (for instance for TypeScript:--require ts-node/register
).
In case anyone is interested, I actually switched to jest, because it seems to have a much easier test script.
"scripts": {
"test": "jest"
}
That's it ๐
Thank you very much!
it works for me to wrap glob path into quotes
"scripts": { "test": "mocha \"test/**/*.spec.js\"" }
๐
it works for me to wrap glob path into quotes
"scripts": { "test": "mocha \"test/**/*.spec.js\"" }
Thanks, it worked! ๐
anyone among you does web automation with mocha framework with java script?I cant find enough source online.I need help!
anyone among you do web automation with a mocha framework with javascript?I can't find enough sources online. I need help!
@alitarlaaci1981 you can connect me in this regard, I use mocha with JS.
[email protected]
it works for me to wrap glob path into quotes
"scripts": { "test": "mocha \"test/**/*.spec.js\"" }
๐
it works for me to wrap glob path into quotes
"scripts": { "test": "mocha \"test/**/*.spec.js\"" }๐
OMG, Thank you!
Without escaped quotes, it behaves totally different, and I thought that I have issues with NYC. I could not generate a proper code coverage report, and it derived me nearly insane.
for me its working using --recursive
"scripts": {
"test": "mocha --recursive --exit"
}
@lxjwlt thanks mate, it works perfectly