I have this (in gulpfile.js):
var gulp = require("gulp"); var mocha = require("gulp-mocha"); gulp.task("test", function() { gulp .src(["./**/*_test.js", "!./node_modules/**/*.js"]); });
and it works.
I want to replicate the same behavior, excluding "node_modules" folder, from mocha command, running npm test (in package.json):
"scripts": { "test": "mocha **\\*_test.js !./node_modules/**/*.js*", }
and it doesn't work.
I'm using Windows.
Any suggestion?
This inclusive ability is available in Mocha by appending . skip() to the suite or to specific test cases. The skipped tests will be marked as "pending" in the test results.
If you just want to run one test from your entire list of test cases then, you can write only ahead of your test case. If you want to run all the test cases which are inside one describe section, then you can also write only to describe as well. describe.
Mocha does not run individual tests in parallel. That means if you hand Mocha a single, lonely test file, it will spawn a single worker process, and that worker process will run the file. If you only have one test file, you'll be penalized for using parallel mode. Don't do that.
Mocha will run the tests in the order the describe calls execute.
I was able to solve this using globbing patterns in the argument to mocha
. Like you I didn't want to put all my tests under a single tests
folder. I wanted them in the same directory as the class they were testing. My file structure looked like this:
project |- lib |- class1.js |- class1.test.js |- node_modules |- lots of stuff...
Running this from the project
folder worked for me:
mocha './{,!(node_modules)/**}/*.test.js'
Which match any *.test.js
file in the tree, so long is its path isn't rooted at ./node_modules/
.
This is an online tool for testing glob patterns that I found useful.
You can exclude files in mocha by passing opts
mocha -h|grep -i exclude --exclude <file> a file or glob pattern to ignore (default: ) mocha --exclude **/*-.jest.js
Additionally, you can also create a test/mocha.opts
file and add it there
# test/mocha.opts --exclude **/*-test.jest.js --require ./test/setup.js
If you want to exclude a particular file type you could do something like this
// test/setup.js require.extensions['.graphql'] = function() { return null }
This is useful when processing extensions with a module loader such as webpack that mocha does not understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With