nodejs / nodejs/node

The assertion module should signals failures through messages to the test runner

Đang mở
#52,033 12 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

assert feature request test_runner
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.3k
Merge trung bình
4 ngày 2 giờ
Pull request đã merge (30 ngày)
283

Mô tả

What is the problem this feature will solve?

The assertion module signals failures via exceptions. This may causes some subtle issues during program testing, since the "exception channel" is also used by the program under test which may catch the exceptions generated by failing assertions resulting in weird test behavior.

import {test} from "node:test";
import assert from "node:assert";

function function_under_test(callback, value) {
    let r = 0;
    try {
        r = callback(value);
    } catch (error) {
       //log error...
    }
    //continue executing operations...
}

test("weird test supposed to fail, but it doesn't", function () {
    function_under_test(function (v) {
        assert.fail("BOOM!");
    }, 4);
});

test passes...

What is the feature you are proposing to solve the problem?

When in a test runner context provide the assertion module via the testContext object:

import {test} from "node:test";
import assert from "node:assert";

function function_under_test(callback, value) {
    let r = 0;
    try {
        r = callback(value);
    } catch (error) {
       //log error...
    }
    //continue executing operations...
}

test("weird test", function (testContext) {
    function_under_test(function (v) {
        testContext.assert.fail("BOOM!");
    }, 4);
});

and signal the failures via messages between testContext and assert methods.

What alternatives have you considered?

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc API testContext của node:test và module node:assert, sau đó kiểm tra cách các lỗi assertion đến được test runner. Xác định interface assertion của test-context và xác minh rằng code đang được kiểm thử không thể bắt các lỗi, trong khi runner vẫn báo cáo chúng.

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
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
32/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.