caolan / caolan/nodeunit

process.exit before console buffer flushed in Windows

Abierto
#282 1 comentario 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
JavaScript
Estrellas
1.9k
Forks
359
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Symptoms

If any test fails, not all the console output is shown (console output is truncated).

Problem does not show up in standard Windows `cmd`, but does show up if tests are run from Cygwin or within Sublime Text build system. In Cygwin, if the output is piped to a file instead of being displayed on the console then all the results show in the file, even though they did not show in the console when not piped.
## Environment
- nodeunit 0.9.0,
- node 0.10.17
- Windows 7
## Minimal Example

I have the following test file, `tests.js`:

```
for (var i = 0; i < 30; i++)
console.log('' + i);

exports.dummy = function(test) {
test.fail();
test.done();
}
```

Running from Cygwin, the result is:

```
$ nodeunit tests.js
0
```

(I.e., only the first console.log appears). But if I remove the `test.fail` line then all the output appears.
## Cause

My guess of the cause is given in the title. It appears that under different circumstances, sometimes the node console is _asynchronous_ (perhaps due to the way Windows pipes work, I'm not sure), and doesn't flush the output after every write. When a test fails, [line 130 in nodeunit/nodeunit](https://github.com/caolan/nodeunit/blob/60b7d67250a8005fcca6d71a18697c9bdc6613bd/bin/nodeunit#L130) `process.exit(1);` seems to recognize the error and exit the process, but `process.exit` does not seem to always wait for the console output to be received by the terminal. To confirm this hypothesis, if I remove the `process.exit` line, then the output is displayed correctly.
## Solution

A work-around seems to be to change [lines 128-132](https://github.com/caolan/nodeunit/blob/60b7d67250a8005fcca6d71a18697c9bdc6613bd/bin/nodeunit#L128-132) to the following:

```
testrunner.run(files, options, function(err) {
if (err) {
process.on('exit', function() {
process.exit(1);
});
}
});
```

This seems to produce the correct error code for the process and also show all the output. I don't know if there are any other side effects of not ending the process immediately in the callback function.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza en bin/nodeunit alrededor de las líneas 128-132, especialmente en process.exit(1) de la línea 130, y reproduce el problema con el tests.js proporcionado bajo Cygwin. Confirma que las ejecuciones fallidas muestran toda la salida de la consola y siguen devolviendo el código de salida 1; la solución alternativa existente proporciona el comportamiento esperado que se debe verificar.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
cli, operating-systems, testing
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.