mysticatea / npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
MIT License
5.72k stars 240 forks source link

unable to use npm-run-all with mocha and chai #168

Closed vboulaye closed 5 years ago

vboulaye commented 5 years ago

Hello,

I am working on a test project with the default svelte template that uses npm-run-all.

I encountered a strange issue when adding mocha+chai to the package.json. It fails when running tests using npm test with Error: Cannot find module 'expect.js'

Removing the npm-run-all dependency makes the problem disappear (mocha and chai are installed).

I made a small project to reproduce it: https://github.com/vboulaye/npm-run-all-test

The full error stack is the following:

/home/user/dev/misc/npm-run-all-test/ko/node_modules/yargs/yargs.js:1163
      else throw err
           ^

Error: Cannot find module 'expect.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/user/dev/misc/npm-run-all-test/ko/node_modules/memorystream/test/memorystream.test.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at /home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/mocha.js:330:36
    at Array.forEach (<anonymous>)
    at Mocha.loadFiles (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/mocha.js:327:14)
    at Mocha.run (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/mocha.js:804:10)
    at Object.exports.singleRun (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/cli/run-helpers.js:207:16)
    at exports.runMocha (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/cli/run-helpers.js:300:13)
    at Object.exports.handler.argv [as handler] (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/cli/run.js:296:3)
    at Object.runCommand (/home/user/dev/misc/npm-run-all-test/ko/node_modules/yargs/lib/command.js:242:26)
    at Object.parseArgs [as _parseArgs] (/home/user/dev/misc/npm-run-all-test/ko/node_modules/yargs/yargs.js:1087:28)
    at Object.parse (/home/user/dev/misc/npm-run-all-test/ko/node_modules/yargs/yargs.js:566:25)
    at Object.exports.main (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/lib/cli/cli.js:63:6)
    at Object.<anonymous> (/home/user/dev/misc/npm-run-all-test/ko/node_modules/mocha/bin/_mocha:10:23)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
    at Module.load (internal/modules/cjs/loader.js:598:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
    at Function.Module._load (internal/modules/cjs/loader.js:529:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
    at startup (internal/bootstrap/node.js:285:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
npm ERR! Test failed.  See above for more details.
TehShrike commented 5 years ago

It's not npm-run-all, it's your glob pattern. **/*.test.js matches every .test.js file in your node_modules directory – and npm-run-all depends on memorystream, which has a file named memorystream.test.js.

jcollum-nike commented 5 years ago

If that doesn't fix it try using _mocha CLI (part of Mocha package). IIRC it runs better in automation.

vboulaye commented 5 years ago

I did not know that the glob pattern applied to the node_modules directory too! (I also changed the executable to _mocha, but changing the pattern to src/**/*.test.js did fix the issue) Thanks a lot.

jcollum-nike commented 5 years ago

@vboulaye https://globster.xyz/ -- for testing globs