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

Correct way of using nodemon with test runners? #496

Closed
mstade opened this issue Feb 8, 2015 · 12 comments · Fixed by #1381 · 4 remaining pull requests
Closed

Correct way of using nodemon with test runners? #496

mstade opened this issue Feb 8, 2015 · 12 comments · Fixed by #1381 · 4 remaining pull requests
Labels
stale no activity for 2 weeks

Comments

@mstade
Copy link

mstade commented Feb 8, 2015

When running tests using mocha or the likes, if the tests fail, and thus the runner exits with a non-zero status code, nodemon seems to think there's something broken with the process and dies without watching for changes. Is there a way to opt out of this behavior?

@mstade
Copy link
Author

mstade commented Feb 8, 2015

Here's the output, btw. As you can see, I use a script defined in package.json to run nodemon and mocha (nodemon -x "_mocha -R min $@",) not sure if this makes a difference.

$ npm run test-dev

> funkis@0.1.4 test-dev /Users/mstade/dev/funkis
> nodemon -x "_mocha -R min $@"

8 Feb 15:57:48 - [nodemon] v1.3.6
8 Feb 15:57:48 - [nodemon] to restart at any time, enter `rs`
8 Feb 15:57:48 - [nodemon] watching: *.*
8 Feb 15:57:48 - [nodemon] starting `_mocha -R min `


  545 passing (670ms)
  2 failing

  1) Protocol when called with an empty signatures object should throw a TypeError:
     AssertionError: function (rest) { return apply(fn, this, argc, arguments) } must throw function TypeError() { [native code] }
      at Context.<anonymous> (/Users/mstade/dev/funkis/test/Protocol.js:15:39)
      at Test.Runnable.run (/Users/mstade/dev/funkis/node_modules/mocha/lib/runnable.js:221:32)
      at Runner.runTest (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:374:10)
      at /Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:452:12
      at next (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:299:14)
      at /Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:309:7
      at next (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:247:23)
      at Immediate._onImmediate (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:321:17)

  2) Protocol when called with a name, and some signatures should set immutable and enumerable properties on the protocol:
     TypeError: Signatures must be an object.
      at TypeError (native)
      at new Protocol (/Users/mstade/dev/funkis/lib/Protocol.js:8:34)
      at Protocol (/Users/mstade/dev/funkis/lib/Protocol.js:5:12)
      at Context.<anonymous> (/Users/mstade/dev/funkis/test/Protocol.js:21:15)
      at Test.Runnable.run (/Users/mstade/dev/funkis/node_modules/mocha/lib/runnable.js:221:32)
      at Runner.runTest (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:374:10)
      at /Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:452:12
      at next (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:299:14)
      at /Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:309:7
      at next (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:247:23)
      at Immediate._onImmediate (/Users/mstade/dev/funkis/node_modules/mocha/lib/runner.js:276:5)
      at processImmediate [as _immediateCallback] (timers.js:321:17)



util.error: Use console.error instead
[nodemon] failed to start process, possible issue with exec arguments
exception in nodemon killing node
Error: Uncaught, unspecified "error" event.
    at Error (native)
    at emit (events.js:78:13)
    at ChildProcess.<anonymous> (/Users/mstade/dev/funkis/node_modules/nodemon/lib/monitor/run.js:133:11)
    at ChildProcess.emit (events.js:101:17)
    at Process.ChildProcess._handle.onexit (child_process.js:1038:12)

----------------------------------------------------------
If appropriate, please file an error with the output from:
$ node /Users/mstade/dev/funkis/node_modules/.bin/nodemon -x _mocha -R min  --dump
At http://github.com/remy/nodemon/issues/new
----------------------------------------------------------


npm ERR! Darwin 14.1.0
npm ERR! argv "/usr/local/opt/nvm/versions/io.js/v1.0.4/bin/iojs" "/usr/local/opt/nvm/versions/io.js/v1.0.4/bin/npm" "run" "test-dev"
npm ERR! node v1.0.4
npm ERR! npm  v2.3.0
npm ERR! code ELIFECYCLE
npm ERR! funkis@0.1.4 test-dev: `nodemon -x "_mocha -R min $@"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the funkis@0.1.4 test-dev script 'nodemon -x "_mocha -R min $@"'.
npm ERR! This is most likely a problem with the funkis package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nodemon -x "_mocha -R min $@"
npm ERR! You can get their info via:
npm ERR!     npm owner ls funkis
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/mstade/dev/funkis/npm-debug.log

@remy
Copy link
Owner

remy commented Feb 11, 2015

Yeah, this should work. I do something similar on other projects. I've got a feeling it's to do with the $@. What are you expecting the value of this to be?

@mstade
Copy link
Author

mstade commented Feb 11, 2015

I use it sometimes to scope which tests get run, and to pass additional parameters to Mocha should I need to. But that works fine, this only ever fails whenever there are exceptions in my code, either because I throw them myself or because of booboos. I previously used mocha -w but it was notoriously bad at handling exceptions and also didn't pick up changes elsewhere in the project which nodemon does beautifully.

I'll see if I can come up with a smaller repro case in the next few days. I'd like to say I'd also be able too see about a fix and a PR, but I fear I probably won't have time for that so would rather not overpromise.

@alexbepple
Copy link

@mstade I think this is a regression with 1.3.x. Made me go back to 1.2.x.

@paragasu
Copy link

I encounter the same problem when i do $npm run test

[nodemon] failed to start process, possible issue with exec arguments     
events.js:146                                                                        
    throw err;                                                                     
    ^                                                                             

Error: Uncaught, unspecified "error" event. (2)    
   at emit (events.js:144:17)        
   at ChildProcess.<anonymous> (/usr/lib/node_modules/nodemon/lib/monitor/run.js:124:11)      
   at emitTwo (events.js:87:13)        
   at ChildProcess.emit (events.js:172:7)     
   at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)  

My package.json script

"scripts": {
    "server": "nodemon ./server.js localhost 5000",  
    "test": "PORT=8000 nodemon --ext js --watch ./ --exec 'mocha ./test' --delay 1"  
 },

@jayphelps
Copy link

For anyone coming in later, you can work-around this issue by just appending || true to trick nodemon into thinking it succeeded.

nodemon --exec "your_command_stuff || true"

@joeysino
Copy link

It looks like this is a duplicate of #627 where they report this happens specifically when the processes exits with error code 2. ENOENT: No such file or directory

@ultrox
Copy link

ultrox commented Aug 26, 2017

@jayphelps thank you very much.

my test script looks like this, hopefully, it will help someone!

"test": "nodemon --watch . --exec 'mocha ./test/index.js || true'"

@stale
Copy link

stale bot commented Dec 5, 2017

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the stale no activity for 2 weeks label Dec 5, 2017
@stale stale bot closed this as completed Dec 12, 2017
@mycodingx
Copy link

Try using this

nodemon --exec mocha -R min

do not use single or double quotes

remy pushed a commit that referenced this issue Jul 17, 2018
Only exit after code 2 if it happened quickly; improve messaging (recommend `||exit 1`)

If nodemon exits _quickly_ on code 2, then it'll bail and warn. If it's after ~500ms, then it assumes that the sub-process intentionally used exit 2 (like mocha or stylelint), it won't bail and treat it as a failure (like a crash).

Props to @joeytwiddle

Fixes #496 
Fixes #627
@akashagarwal7
Copy link

"test": "NODE_ENV=test nodemon --exec mocha --exit -R spec"

And if you run:

npm test dir/file.js

dir/file.js will be appended to the test script, hence you can test individual files.

Saving your file twice quickly will run the tests twice as well, which might be undesirable.

@mariothedev
Copy link

mariothedev commented Aug 24, 2019

This worked for me:
"start": "nodemon ./bin/www --exec mocha ./test.js -R min"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment