Nodemon: ¿Forma correcta de usar nodemon con los corredores de prueba?

Creado en 8 feb. 2015  ·  12Comentarios  ·  Fuente: remy/nodemon

Al ejecutar pruebas con mocha o similares, si las pruebas fallan y, por lo tanto, el corredor sale con un código de estado distinto de cero, nodemon parece pensar que hay algo roto con el proceso y muere sin estar atento a los cambios. ¿Hay alguna forma de optar por no participar en este comportamiento?

stale

Comentario más útil

Para cualquiera que venga más tarde, puede solucionar este problema simplemente agregando || true para engañar a nodemon haciéndole creer que tuvo éxito.

nodemon --exec "your_command_stuff || true"

Todos 12 comentarios

Aquí está la salida, por cierto. Como puede ver, utilizo un script definido en package.json para ejecutar nodemon y mocha ( nodemon -x "_mocha -R min $@" ,) no estoy seguro de si esto hace una diferencia.

$ 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

Sí, esto debería funcionar. Hago algo similar en otros proyectos. Tengo un _sentimiento_ que tiene que ver con el $@ . ¿Cuál espera que sea el valor de esto?

A veces lo uso para determinar qué pruebas se ejecutan y para pasar parámetros adicionales a Mocha si es necesario. Pero eso funciona bien, esto solo falla siempre que hay excepciones en mi código, ya sea porque las lanzo yo mismo o por booboos. Anteriormente usé mocha -w pero era notoriamente malo en el manejo de excepciones y tampoco recogió cambios en otras partes del proyecto, lo que nodemon hace maravillosamente.

Veré si puedo crear un caso de reproducción más pequeño en los próximos días. Me gustaría decir que también podría ver acerca de una solución y un PR, pero me temo que probablemente no tenga tiempo para eso, así que preferiría no hacer promesas excesivas.

@mstade Creo que esta es una regresión con 1.3.x. Me hizo volver a 1.2.x.

Encuentro el mismo problema cuando hago la prueba de ejecución $ npm

[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)  

Mi script package.json

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

Para cualquiera que venga más tarde, puede solucionar este problema simplemente agregando || true para engañar a nodemon haciéndole creer que tuvo éxito.

nodemon --exec "your_command_stuff || true"

Parece que esto es un duplicado de # 627 donde informan que esto sucede específicamente cuando el proceso sale con el código de error 2. ENOENT: No such file or directory

@jayphelps muchas gracias.

mi secuencia de comandos de prueba se ve así, ¡con suerte, ayudará a alguien!

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

Este problema se ha marcado automáticamente como inactivo y obsoleto porque no ha tenido ninguna actividad reciente. Se cerrará automáticamente si no se produce más actividad. Si cree que esto está mal, o que el problema persiste, simplemente envíe una respuesta en los comentarios y
Gracias por contribuir <3

Intenta usar esto

nodemon --exec mocha -R min

no use comillas simples o dobles

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

Y si corres:

npm test dir/file.js

dir/file.js se agregará al script de prueba, por lo que puede probar archivos individuales.

Si guarda su archivo dos veces rápidamente, las pruebas también se ejecutarán dos veces, lo que podría no ser deseable.

Esto funcionó para mí:
"start": "nodemon ./bin/www --exec mocha ./test.js -R min"

¿Fue útil esta página
0 / 5 - 0 calificaciones