caolan / caolan/nodeunit

Wrap tests in domain instead of try/catch

Abierto
#217 0 comentarios 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

In several cases, async errors with nodeunit and streams2 only result in the test giving a "test not run or test.done not called". without any sign of the error. What I ended up doing is something like this

``` javascript
Function.prototype.withDomain = function(withStack) {
var fn = this;
return function(test) {
var d = domain.create();
d.on('error', function(e) {
test.fail('test failed with ' + e.message);
if(withStack) {
console.error(e.stack)
}
test.done();
});
d.run(fn.bind(this, test));
}
}

exports['my test'] = function (test) {
setTimeout(function() {
throw new Error('Throwing an error asynchronously');
test.done()
});
}.withDomain()

```

I just thought this was useful enough to be the default.

Guía de contribución

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

Línea de trabajo

The issue provides a Function.prototype.withDomain example and identifies nodeunit tests with streams2 as the affected area. Start by reading nodeunit's asynchronous test execution and error-handling path, then run the existing test suite with an asynchronous stream error. Done means those errors fail the relevant test with a useful message instead of reporting only that test.done was not called.

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

Evaluación

Stack tecnológico
javascript, node.js
Área
testing
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.