caolan / caolan/nodeunit

Wrap tests in domain instead of try/catch

Offen
#217 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
1.9k
Forks
359
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, node.js
Bereich
testing
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
28/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.