Nodemon: Cara yang benar menggunakan nodemon dengan test runner?

Dibuat pada 8 Feb 2015  ·  12Komentar  ·  Sumber: remy/nodemon

Saat menjalankan tes menggunakan moka atau sejenisnya, jika tes gagal, dan dengan demikian pelari keluar dengan kode status bukan nol, nodemon tampaknya berpikir ada sesuatu yang rusak dengan proses dan mati tanpa melihat perubahan. Apakah ada cara untuk menyisih dari perilaku ini?

stale

Komentar yang paling membantu

Bagi siapa pun yang datang nanti, Anda dapat mengatasi masalah ini hanya dengan menambahkan || true untuk mengelabui nodemon agar menganggapnya berhasil.

nodemon --exec "your_command_stuff || true"

Semua 12 komentar

Ini outputnya, btw. Seperti yang Anda lihat, saya menggunakan skrip yang ditentukan dalam package.json untuk menjalankan nodemon dan mocha ( nodemon -x "_mocha -R min $@" ,) tidak yakin apakah ini membuat perbedaan.

$ 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

Ya, ini _harus_ bekerja. Saya melakukan hal serupa pada proyek lain. Saya punya _feeling_ yang berkaitan dengan $@ . Apa yang Anda harapkan dari nilai ini?

Saya kadang-kadang menggunakannya untuk cakupan tes mana yang dijalankan, dan untuk memberikan parameter tambahan ke Mocha jika saya perlu. Tapi itu berfungsi dengan baik, ini hanya gagal setiap kali ada pengecualian dalam kode saya, baik karena saya melemparkannya sendiri atau karena booboo. Saya sebelumnya menggunakan mocha -w tetapi sangat buruk dalam menangani pengecualian dan juga tidak mengambil perubahan di tempat lain dalam proyek yang dilakukan nodemon dengan indah.

Saya akan melihat apakah saya dapat membuat kasus repro yang lebih kecil dalam beberapa hari ke depan. Saya ingin mengatakan bahwa saya juga dapat melihat tentang perbaikan dan PR, tetapi saya khawatir saya mungkin tidak akan punya waktu untuk itu, jadi saya lebih suka tidak terlalu menjanjikan.

@mstade Saya pikir ini adalah regresi dengan 1.3.x. Membuat saya kembali ke 1.2.x.

Saya mengalami masalah yang sama ketika saya melakukan $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)  

Skrip package.json saya

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

Bagi siapa pun yang datang nanti, Anda dapat mengatasi masalah ini hanya dengan menambahkan || true untuk mengelabui nodemon agar menganggapnya berhasil.

nodemon --exec "your_command_stuff || true"

Sepertinya ini adalah duplikat dari #627 di mana mereka melaporkan ini terjadi secara khusus ketika proses keluar dengan kode kesalahan 2. ENOENT: No such file or directory

@jayphelps terima kasih banyak.

skrip pengujian saya terlihat seperti ini, semoga membantu seseorang!

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

Masalah ini secara otomatis ditandai sebagai menganggur dan basi karena tidak ada aktivitas terbaru. Ini akan ditutup secara otomatis jika tidak ada aktivitas lebih lanjut yang terjadi. Jika menurut Anda ini salah, atau masalah masih berlanjut, cukup kirimkan balasan di komentar dan
Terima kasih telah berkontribusi <3

Coba gunakan ini

nodemon --exec mocha -R min

jangan gunakan tanda kutip tunggal atau ganda

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

Dan jika Anda menjalankan:

npm test dir/file.js

dir/file.js akan ditambahkan ke skrip pengujian, sehingga Anda dapat menguji file individual.

Menyimpan file Anda dua kali dengan cepat akan menjalankan tes dua kali juga, yang mungkin tidak diinginkan.

Ini berhasil untuk saya:
"start": "nodemon ./bin/www --exec mocha ./test.js -R min"

Apakah halaman ini membantu?
0 / 5 - 0 peringkat