how to configure gulp-mocha with the following mocha.opts configuration?

389 Views Asked by At

I am trying to run mocha with gulp with the configuration existed before. moch.opts has the following line.

--timeout 999999
--ui tdd
--full-trace
--recursive
--compilers js:babel-register

how to add them here :

    gulp.task('test', function() {
        return gulp.src('sampleTest/*.js', { read: false })
            .pipe(mocha());
    });
3

There are 3 best solutions below

0
jacobq On

I believe you can either create properties on the options object passed to gulp-mocha or you can just have it read the options file. In my case, I didn't want to duplicate things like --recursive or --require test/_init.js, but I did want to override the reporter, so I use the code shown below:

gulp.task('test', ['compile'], function() {
    return gulp.src([], { read: false })
        .pipe(mocha({
            opts: 'test/mocha.opts',
            reporter: 'min'
        }))
        .on('error', gutil.log);
});

You may want to modify this so that it doesn't assume the default path to test files (e.g. test/*.js), but in my simple case I didn't even need to pass a path to mocha. I'm just using gulp to trigger it (as if I had run on the command line something like mocha --opts test/mocha.opts --reporter min)

1
user2347763 On

add the setTimeout call after the mocha call

.pipe(mocha(),setTimeout(function() {

}, 999999))
0
lihome On

Options are passed directly to the mocha binary, so you can use any its command-line options in a camelCased form. this is the document link

gulp.task('test', ['compile'], function() {
return gulp.src([], { read: false })
    .pipe(mocha({
        timeout: 999999,
        fullTrace: true,
        reporter: 'min'
    }))
    .on('error', gutil.log);
});