fatal errors in test callbacks are not displayed (with fix)
- Langage dominant
- JavaScript
- Étoiles
- 1.9k
- Forks
- 359
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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);
```
Guide de contribution
Aucun guide de contribution indexé pour ce dépôt
Piste de recherche
Commencez par lib/track.js et reproduisez le problème en utilisant l’exemple t.js du rapport. Comparez la sortie de nodeunit pour l’erreur du callback avec la sortie attendue, y compris la pile de l’exception non interceptée et le diagnostic undone-test existant ; l’issue est terminée lorsque l’erreur fatale du callback et le numéro de ligne sont affichés.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- javascript
- Domaine
- testing-qa
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- À l'abandon
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 48/100