I switched to Gulp not too long ago and I setup a watch task to run my mocha tests as soon as one of the code or spec files are saved.
For a couple of weeks I couldn't understand what I was doing wrong and why my tests eventually kept on failing in the watch task but were fine when run from the CLI with mocha test.
I eventually discovered that it's because gulp-mocha runs the tests in the same process as Gulp and so mocha's state isn't 100% reset between runs.
Then I came across gulp-spawn-mocha which addresses this very issue.
The README should come with a warning when using gulp-mocha in a watch task. I wasted a lot of time trying to figure it out and was almost ready to give up Gulp.
I switched to Gulp not too long ago and I setup a watch task to run my mocha tests as soon as one of the code or spec files are saved.
For a couple of weeks I couldn't understand what I was doing wrong and why my tests eventually kept on failing in the watch task but were fine when run from the CLI with
mocha test.I eventually discovered that it's because
gulp-mocharuns the tests in the same process as Gulp and so mocha's state isn't 100% reset between runs.Then I came across
gulp-spawn-mochawhich addresses this very issue.The README should come with a warning when using
gulp-mochain a watch task. I wasted a lot of time trying to figure it out and was almost ready to give up Gulp.