caolan / caolan/nodeunit

fatal errors in test callbacks are not displayed (with fix)

Aperta
#279 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
JavaScript
Stelle
1.9k
Fork
359
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Fatal errors in callbacks defined in the test functions are not displayed,
only the "test.done() not called" diagnostic is shown. It's useful to have
the error and line number too. (If not in a callback, the error is reported
as expected.)

To reproduce the issue, create a file t.js:

```
module.exports = {
test: function(t) {
var x;
setTimeout(function() {
x.a = 1;
}, 1);
}
}
```

Current nodeunit outputs:

```
% nodeunit t.js

t.js

FAILURES: Undone tests (or their setups/teardowns):
- test

To fix this, make sure all tests call test.done()
```

with the propsed fix it outputs:

```
% nodeunit t.js

t.js
Uncaught exception:
TypeError: Cannot set property 'a' of undefined
at null._onTimeout (/home/andras/node/t.js:5:21)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

FAILURES: Undone tests (or their setups/teardowns):
- test

To fix this, make sure all tests call test.done()
```

The proposed fix:

```
diff --git a/lib/track.js b/lib/track.js
index 5af98ad..f699fce 100644
--- a/lib/track.js
+++ b/lib/track.js
@@ -27,6 +27,11 @@ exports.createTracker = function (on_exit) {
}
};

+ // AR: display errors in callbacks defined within the tests
+ process.on('uncaughtException', function(e) {
+ console.log("Uncaught exception:\n" + e.stack);
+ });
+
process.on('exit', function() {
on_exit = on_exit || exports.default_on_exit;
on_exit(tracker);
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia con lib/track.js e riproduci il problema usando l’esempio t.js del report. Confronta l’output di nodeunit per l’errore del callback con l’output previsto, inclusi lo stack dell’eccezione non intercettata e la diagnostica undone-test esistente; l’issue è completata quando vengono visualizzati l’errore fatale del callback e il numero di riga.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.