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に渡したりするために使用することがあります。 しかし、それは問題なく機能します。これは、自分で例外をスローするか、ブーブーが原因で、コードに例外がある場合にのみ失敗します。 以前はmocha -wいましたが、例外の処理が悪かったことで有名であり、nodemonが美しく行うプロジェクトの他の場所での変更も取得しませんでした。

今後数日で、より小さな再現ケースを考え出すことができるかどうかを確認します。 修正やPRについても見ることができると言いたいのですが、おそらくそのための時間がないのではないかと心配しているので、約束しすぎないでください。

@mstadeこれは

$ 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がテストスクリプトに追加されるため、個々のファイルをテストできます。

ファイルをすばやく2回保存すると、テストも2回実行されますが、これは望ましくない場合があります。

これは私のために働いた:
"start": "nodemon ./bin/www --exec mocha ./test.js -R min"

このページは役に立ちましたか?
0 / 5 - 0 評価