sebv / spawn-mocha-parallel

Spawn mocha child processes in parallel
MIT License
7 stars 6 forks source link

ENOENT error #3

Open dsernst opened 9 years ago

dsernst commented 9 years ago

I can't get this module to work. Every time I try to run the gulp task I get this error in my console:

➜  BC git:(spawn-mocha gulp test-mocha
[19:46:47] Using gulpfile /mnt/BC/gulpfile.js
[19:46:47] Starting 'test-mocha'...
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn /mnt/BC/node_modules/spawn-mocha-parallel/node_modules/.bin/mocha ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
    at child_process.js:1137:20
    at process._tickCallback (node.js:355:11)

Here's the code trying to run it:

'use strict';

var gulp = require('gulp');
var mochaStream = require('spawn-mocha-parallel').mochaStream;
var mocha = mochaStream({concurrency: 10});

gulp.task('test-mocha', 'Runs the integration tests, in parallel!', function () {
  return gulp.src('test/integration/aaa.js', {read: true})
    .pipe(gulp.dest('aaaa'))
    .pipe(mocha)
    .on('error', console.error);
});

Do you have any idea why it is throwing back this ENOENT every time?

dsernst commented 9 years ago

aaa.js is just a simple file to get something to work, to rule out the case that the complexity of the existing tests was leading to a problem. Here's what it looks like:

describe('something', function () {
  it('works', function () {

  });
});
dsernst commented 9 years ago

And the .pipe(gulp.dest('aaaa')) bit does a simple copy to rule out the possibility that there is a typo in the path to the file, or that the file is missing.

The task does successfully copy aaa.js to that destination folder, ruling out the possibility that the file isn't there — like ENOENT would usually suggest.

dsernst commented 9 years ago

Ah! Figured something out!

I wanted to run this module's own tests to see if anything was working. So I went into its folder, and tried to run its gulp test:

spawn-mocha-parallel dsernst$ gulp test
module.js:338
    throw err;
          ^
Error: Cannot find module 'q'

so I did an npm install from within that folder.

After doing that, running its own gulp test worked and it passed all its own tests. Then, switching back to my projects root, and trying to gulp mocha-test task again, it worked this time!

VICTORY

So it would seem this package has some sort of dependency problem, and it's silently failing because of it.

kevin-miles commented 9 years ago

@dsernst When using this module if you ever come across failures/errors try running the same tests with just mocha. In a couple scenarios using spawn-mocha-parallel wouldn't output good information about what the error/failure was about. Running the test with mocha itself usually gives me what I need for debugging.

marin-liovic commented 8 years ago

Is there a reason why "q" isn't installed immediately? I had this same problem...

jeffhall4 commented 7 years ago

The problem is not with this modules dependencies but that by default it is looking inside this modules node_modules dir for the mocha dependency rather than in the higher level one. I suspect this will have worked with npm 2 but now with npm 3 the sub dependencies are flat and mocha can't be found where this module is looking for it.

In order to work around this you can use the undocumented 'bin' param that allows you to change the default location of mocha.

e.g. adapting the readme example and assuming a project layout of --node_modules --gulp.js

In the gulp.js:

var path = require('path');
var mochaStream = require('spawn-mocha-parallel').mochaStream;
var mocha = mochaStream({
  concurrency: 10,
  bin: path.join(__dirname, 'node_modules', '.bin', 'mocha')
});
gulp.task('test-mocha', function() {
  return gulp.src('**/*-specs.js', {read: false}) 
    .pipe(mocha)
    .on('error', console.error)
});