fatal errors in test callbacks are not displayed (with fix)
- 主要言語
- JavaScript
- スター
- 1.9k
- フォーク
- 359
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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);
```
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
lib/track.js から始め、報告にある t.js の例を使って問題を再現します。callback エラーに対する nodeunit の出力を、捕捉されない例外のスタックと既存の undone-test 診断を含めて、期待される出力と比較します。致命的な callback エラーと行番号が表示されれば、issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 48/100