I'm trying to use the gulp-mocha module but can't figure out a good way to pass over the compilers flag. Is there a way to include this in my gulp task? Maybe in a separate pipe somehow?
Example if running mocha from command line (works fine)
mocha --compilers .:my_compiler.js test/**/*.js
Example if using gulp-mocha (but where can I specify a compiler)?
gulp.task('test', function () {
gulp.src(["test/**/*.js"], {
read: false
})
.pipe(mocha({
reporter: 'spec'
}))
.pipe(exit());
});
I don't see a compilers option under the gulp-mocha plugin, so I'm thinking I need to somehow add the compilers by appending the text through a pipe somehow?
I just noticed the docs at the bottom state -
I added a require statement for my own compiler at the top of my gulp file
require('./my_compiler');
and this seemed to work.Use
require('babel-core/register');
at the start of the gulpfileThe top answer relies on using the require hook. This will only work in the current process, and not if you run Mocha tests in a separate process, as with
gulp-spawn-mocha
.This is how you pass compilers into the mocha module:
Mocha will loop through the elements of the
compilers
property and split on:
. It will treat the string before it as the extensions to follow, and will inject everything after it into arequire()
statement.Justin Maat, you don't need to modify your
gulpfile.js
. You just need to use--require
when usinggulp
fromCLI
:Do you notice the difference? And to save you a few keystrokes, add this to your
.bashrc
or.zshrc
:and next time, you can use
gulp
as normalFor anyone trying it now
and on top of the gulp file (gulpfile.js)
run your test and it should work