Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading to version 4 mocha tests no longer run #156

Open
miroslawmajka opened this issue Feb 23, 2017 · 20 comments
Open

After upgrading to version 4 mocha tests no longer run #156

miroslawmajka opened this issue Feb 23, 2017 · 20 comments

Comments

@miroslawmajka
Copy link

miroslawmajka commented Feb 23, 2017

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",
@miroslawmajka miroslawmajka changed the title After upgrading to version 4 no longer run After upgrading to version 4 mocha tests no longer run Feb 23, 2017
@pleerock
Copy link

same here

@hooddanielc
Copy link
Contributor

hooddanielc commented Feb 24, 2017

👍 I have the same issue

Here is an example app that reproduces this issue

Installing gulp-mocha@v3.0.1 fixes my issues.

@tkirda
Copy link

tkirda commented Feb 24, 2017

Just add:

mocha({
    compilers: 'js:babel-core/register',
  // ...
})

@hooddanielc
Copy link
Contributor

@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?

@tkirda
Copy link

tkirda commented Feb 25, 2017

Look at my sample, compilers is not an object, but a string value: compilers: 'js:babel-core/register'

@hooddanielc
Copy link
Contributor

hooddanielc commented Feb 25, 2017

Sorry, I made a typo above >.<

@tkirda the below works with mocha@4.0.1

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!

@pleerock
Copy link

what about users who dont use babel?

@hooddanielc
Copy link
Contributor

@miroslawmajka Have you tried deleting your node_modules folder and reinstalling with npm install?

@miroslawmajka
Copy link
Author

@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.

@hooddanielc
Copy link
Contributor

@miroslawmajka your problem is almost certainty IPC related. I think it has something to do with this commit. 3e55175 . Multi platform IPC has given me a lot of problems before especiallly when developing after Linux implementations.

Maybe execa might be the issue.

@hooddanielc
Copy link
Contributor

@miroslawmajka what happens when you run gulp-mocha's unit test?

@miroslawmajka
Copy link
Author

C:\Development\gulp-mocha-test\node_modules\gulp-mocha>npm test

> gulp-mocha@4.0.1 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?

@hooddanielc
Copy link
Contributor

hooddanielc commented Feb 25, 2017

@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.

@miroslawmajka
Copy link
Author

@hooddanielc all passed (4 tests). Not sure why it wouldn't work inside the project.

@hooddanielc
Copy link
Contributor

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.

@miroslawmajka
Copy link
Author

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.

@hooddanielc
Copy link
Contributor

Do your tests typically take a really long time? What is the average time spent on completing test?

@miroslawmajka
Copy link
Author

Depends, UI tests take up to 20 minutes, API tests usually up to 4 (that's Mocha and Cucumber times put together).

@mamont
Copy link
Contributor

mamont commented Feb 28, 2017

I've made a PR which restores a previous behavior:
#160

@adiii717
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants