Nodemon: 将 nodemon 与测试运行器一起使用的正确方法?

创建于 2015-02-08  ·  12评论  ·  资料来源: remy/nodemon

当使用 mocha 或类似工具运行测试时,如果测试失败,因此运行程序以非零状态代码退出,nodemon 似乎认为进程有问题并在没有观察更改的情况下死亡。 有没有办法选择退出这种行为?

stale

最有用的评论

对于以后进来的任何人,您可以通过附加|| true来诱使 nodemon 认为它成功来解决此问题。

nodemon --exec "your_command_stuff || true"

所有12条评论

这是输出,顺便说一句。 如您所见,我使用 package.json 中定义的脚本来运行 nodemon 和 mocha ( nodemon -x "_mocha -R min $@" ,) 不确定这是否有所不同。

$ 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

是的,这_应该_工作。 我在其他项目上做了类似的事情。 我有一种_感觉_这与$@ 。 你期望它的价值是多少?

我有时使用它来确定运行哪些测试的范围,并在需要时将其他参数传递给 Mocha。 但这工作正常,只有在我的代码中有异常时才会失败,要么是因为我自己抛出它们,要么是因为 booboos。 我以前使用过mocha -w但它在处理异常方面是出了名的糟糕,并且也没有在项目的其他地方发现 nodemon 做得很好的变化。

我会看看我能否在接下来的几天里想出一个更小的复制案例。 我想说我也可以看到修复和公关,但我担心我可能没有时间这样做,所以宁愿不要过度承诺。

@mstade我认为这是 1.3.x 的回归。 让我回到 1.2.x。

我在执行 $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)  

我的 package.json 脚本

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

对于以后进来的任何人,您可以通过附加|| true来诱使 nodemon 认为它成功来解决此问题。

nodemon --exec "your_command_stuff || true"

看起来这是#627 的副本,他们报告说当进程以错误代码 2 退出时会发生这种情况。 ENOENT: No such file or directory

@jayphelps非常感谢。

我的测试脚本看起来像这样,希望它会帮助某人!

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

此问题已自动标记为空闲和陈旧,因为它最近没有任何活动。 如果没有进一步的活动发生,它将自动关闭。 如果您认为这是错误的,或者问题仍然存在,只需在评论中弹出回复, @remy将(尝试!)跟进。
感谢您的贡献 <3

尝试使用这个

nodemon --exec mocha -R min

不要使用单引号或双引号

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

如果你运行:

npm test dir/file.js

dir/file.js将附加到测试脚本中,因此您可以测试单个文件。

快速保存文件两次也会使测试运行两次,这可能是不可取的。

这对我有用:
"start": "nodemon ./bin/www --exec mocha ./test.js -R min"

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

maotora picture maotora  ·  4评论

remy picture remy  ·  5评论

Exeteres picture Exeteres  ·  4评论

fabianMendez picture fabianMendez  ·  4评论

olalonde picture olalonde  ·  3评论