gulp-mocha
gulp-mocha copied to clipboard
After upgrading to version 4 mocha tests no longer run
The program just hangs with gulp-mocha version 4:
$ gulp test-ping
2017-02-23 11:25:08.592 - info: Using "qa" environment for tests.
[11:25:08] Using gulpfile C:\Development\project\gulpfile.js
[11:25:08] Starting 'test-ping'...
Task:
const gulp = require('gulp');
const mocha = require('gulp-mocha');
gulp.task('ping-task, () => gulp
.src(['ping-tests.js'], {read: false})
.pipe(mocha({
reporter: 'spec',
timeout: 90000,,
useColors: true
})));
Upon downgrading to 3.0.1 all works fine.
System: Windows 10 Node: 6.10.0
Some of the relevant gulp package:
"gulp": "^3.9.1",
"gulp-cucumber": "0.0.22",
"gulp-mocha": "^4.0.1",
"gulp-webdriver": "^2.0.3",
same here
👍 I have the same issue
Here is an example app that reproduces this issue
Installing [email protected]
fixes my issues.
Just add:
mocha({
compilers: 'js:babel-core/register',
// ...
})
@tkirda I tried that along with many other suggestion. I made an example app that reproduces issue here.
This is the gulpfile.js
const register = require('babel-core/register');
const gulp = require('gulp');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
gulp.task('test-with-suggested', () => {
gulp.src('./src/**/*.js')
.pipe(mocha({
compilers: {
js: 'js:babel-core/register'
}
}));
});
gulp.task('test-with-js-property', () => {
gulp.src('./src/**/*.js')
.pipe(mocha({
compilers: {
js: 'js:babel-core/register'
}
}));
});
gulp.task('test-with-register', () => {
gulp.src('./src/**/*.js')
.pipe(mocha({
compilers: {
js: register
}
}));
});
gulp.task('test-with-babel', () => {
gulp.src('./src/**/*.js')
.pipe(mocha({
compilers: {
js: babel
}
}));
});
What am I doing wrong?
Look at my sample, compilers is not an object, but a string value: compilers: 'js:babel-core/register'
Sorry, I made a typo above >.<
@tkirda the below works with [email protected]
const gulp = require('gulp');
const babel = require('gulp-babel');
const mocha = require('gulp-mocha');
gulp.task('test-with-suggested', () => {
gulp.src('./test/**/*.js')
.pipe(mocha({
compilers: 'js:babel-core/register'
}));
});
I expect this question to come up a lot, so I created a pull request.
Many Thanks!
what about users who dont use babel?
@miroslawmajka Have you tried deleting your node_modules folder and reinstalling with npm install?
@hooddanielc Yes, just tried that exact scenario with deleting node_modules and installing version 4.0.1 of gulp mocha. Tests eventually run but with the following error message:
[15:56:25] Using gulpfile C:\Development\tp-automation\gulpfile.js
[15:56:25] Starting 'test-ping'...
[15:56:47] 'test-ping' errored after 23 s
[15:56:47] Error in plugin 'gulp-mocha'
Message:
spawn undefined ENOENT
Details:
errno: ENOENT
code: ENOENT
syscall: spawn undefined
killed: false
Going back to 3.0.1 again as this isn't stable. We have no intention in using babel as it has proven to be very slow in our automated test scenarios.
@miroslawmajka your problem is almost certainty IPC related. I think it has something to do with this commit. https://github.com/sindresorhus/gulp-mocha/commit/3e551754a1b3ed090b77d77368f690a3c38614c0 . Multi platform IPC has given me a lot of problems before especiallly when developing after Linux implementations.
Maybe execa might be the issue.
@miroslawmajka what happens when you run gulp-mocha's unit test?
C:\Development\gulp-mocha-test\node_modules\gulp-mocha>npm test
> [email protected] test C:\Development\gulp-mocha-test\node_modules\gulp-mocha
> xo && mocha
Warning: Could not find any test files matching pattern: test
No test files found
npm ERR! Test failed. See above for more details.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
@miroslawmajka Please clone gulp-mocha
outside of your project and run the tests. You shouldn't have to install any global modules.
git clone https://github.com/sindresorhus/gulp-mocha.git
cd gulp-mocha
npm i
npm test
If you install your modules locally, any script commands defined in package.json will look in your local node_modules/.bin folder automatically.
@hooddanielc all passed (4 tests). Not sure why it wouldn't work inside the project.
I have a feeling this issue is caused by outdated global modules. Try adding your global modules to your package.json. npm might be doing some magic.
Install gulp and mocha locally
''' npm i --save-dev mocha npm Im --save-dev gulp '''
Uninstall global modules
''' npm uninstall -g mocha npm uninstall -g gulp '''
Execute local gulp
''' ./node_modules/.bin/gulp test '''
If you don't like typing all that out you can either add a test property to scripts object in package.json like gulp-mocha does or just make sure you keep updating your global modules which can be a confusing waist of time sometimes.
BTW, I would reconsider using babel with gulp. It's gotten a lot better and faster. Hope this helps because I'm out of ides. Good luck.
After uninstalling global mocha and gulp this started working again. Installed both global modules and still works. So that's out of the way. The downside now is that all our Mocha tests run but the actual output with gulp-mocha 4.0.1 only appears when all is finished. No realtime results using the spec reporter.
So this is partially resolved by having to remove the global mocha and gulp modules (old stuff cached there?) but you cannot see realtime progress of your tests.
Do your tests typically take a really long time? What is the average time spent on completing test?
Depends, UI tests take up to 20 minutes, API tests usually up to 4 (that's Mocha and Cucumber times put together).
I've made a PR which restores a previous behavior: https://github.com/sindresorhus/gulp-mocha/pull/160
I have the same issue just install mocha globally and resolve the issue.
First I was trying to run mocha from the local module.
npm i mocha -g