fatal errors in test callbacks are not displayed (with fix)
- Ngôn ngữ chính
- JavaScript
- Star
- 1.9k
- Fork
- 359
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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);
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu với lib/track.js và tái hiện vấn đề bằng ví dụ t.js trong báo cáo. So sánh đầu ra của nodeunit đối với lỗi callback với đầu ra mong đợi, bao gồm cả stack của exception chưa được bắt và chẩn đoán undone-test hiện có; issue được hoàn tất khi lỗi callback nghiêm trọng và số dòng được hiển thị.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- testing-qa
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 48/100