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

Error: spawn mocha ENOENT #4824

Closed
alamban opened this issue Jan 31, 2022 · 2 comments
Closed

Error: spawn mocha ENOENT #4824

alamban opened this issue Jan 31, 2022 · 2 comments

Comments

@alamban
Copy link

alamban commented Jan 31, 2022

Prerequisites

  • [x ] Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • [x ] Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • [x ] 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
  • [x ] Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

I am trying to run a plan in the Bamboo Pipeline to execute the unit test cases in my project. However, the run is failing and resulting in the following error.

Error: spawn mocha ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn mocha',
path: 'mocha',
spawnargs: [ 'test/utils/index.spec.js', '--config', '.mocharc.js' ]
}

Steps to Reproduce

I am using the agent environment to perform this operation. This is the command I am using to run the test cases in bamboo using shell script.

docker-compose run --rm web nyc --reporter=lcov --reporter=text mocha test/**/*.js --config .mocharc.js

Expected behavior: Perform the unit tests.

Actual behavior: An error is occurring.

Error: spawn mocha ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:274:19)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21)
Emitted 'error' event on ChildProcess instance at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:280:12)
at onErrorNT (internal/child_process.js:469:16)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -2,
code: 'ENOENT',
syscall: 'spawn mocha',
path: 'mocha',
spawnargs: [ 'test/utils/index.spec.js', '--config', '.mocharc.js' ]
}

Reproduces how often: [What percentage of the time does it reproduce?]

Versions

  • The output of mocha --version 9.2.0 and node node_modules/.bin/mocha --version: 9.2.0
  • The output of node --version: 14
  • Your operating system
    • name and version: Bamboo Pipeline
    • architecture (32 or 64-bit):
  • Your shell (e.g., bash, zsh, PowerShell, cmd):
  • Your browser and version (if running browser tests): Google Chrome V 95.0.4638.69
  • Any third-party Mocha-related modules (and their versions):
  • Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version):

Additional Information

@juergba
Copy link
Member

juergba commented Jan 31, 2022

@alamban please note, this is Mocha's issue tracker, not a help forum.

I have no idea what a Bamboo pipeline is. I would assume that your docker doesn't find mocha's executable, see ENOENT (no such file or directory ?). Play around with different paths, relative and absolute.

@dominikschreiber
Copy link

For anyone coming here from a google search: we experienced the same problem upgrading from mocha 9 to mocha 10. We had the following in our test setup:

require('child_process').spawn('./node_modules/mocha/bin/mocha', args)

This worked with mocha until mocha 9 and broke with exactly the error reported in this incident with mocha 10.

#4863 renamed bin/mocha to bin/mocha.js (and correctly marked the change as incompatible, but we did not immediately see the change or its implications). So, for mocha 10, there are two migration options:

/* 1 */ require('child_process').spawn('./node_modules/mocha/bin/mocha.js', args); // (relies on shebang in mocha.js as well)
/* 2 */ require('child_process').spawn('node', ['./node_modules/mocha/bin/mocha', ...args]); // (our preferred migration)

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

3 participants