Nodemon: Correct way of using nodemon with test runners?

Created on 8 Feb 2015  ·  12Comments  ·  Source: remy/nodemon

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?

stale

Most helpful comment

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"

All 12 comments

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

> [email protected] 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! [email protected] test-dev: `nodemon -x "_mocha -R min $@"`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

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?

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.

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

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"  
 },

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"

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

@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'"

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

Try using this

nodemon --exec mocha -R min

do not use single or double quotes

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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

olalonde picture olalonde  ·  3Comments

Autre31415 picture Autre31415  ·  4Comments

giacomorebonato picture giacomorebonato  ·  5Comments

ehmicky picture ehmicky  ·  4Comments

Makoehle picture Makoehle  ·  3Comments