Supply AbortController signal to tests

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

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

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, node.js
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách truy vết cách tham số test flags và phần xử lý onCleanup hiện có được triển khai. Kiểm tra các test liên quan đến hành vi cleanup, sau đó thêm signal của AbortController vào các flags được truyền cho test và xác minh rằng lab hủy nó khi cleanup chạy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

feature
Support plan
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no
Context
  • node version: 14+
  • module version: 24.3.2
  • environment (e.g. node, browser, native): node 14+
  • used with (e.g. hapi application, another framework, standalone, ...):
  • any other relevant information:
What problem are you trying to solve?

Simpler cleanup of failed (or time outed) tests.

Do you have a new or modified API suggestion to solve the problem?

Add an AbortController signal property to the flags parameter. This way a test can pass it on, eg.:

it('performs a fetch', async ({ signal }) => {

    const req = http.request('http://example.org', { signal });
    const [res] = await Events.onceee(req, 'response');           // Crashes since `onceee` does not exist.

    expect(res.statusCode).to.equal(200);
});

Without the signal, the code crashes before any event emitters are added, which obviously causes the test to fail. However, the request continues processing. If it errors at any point, it will cause a process uncaughtException, which will cause whatever subsequent test that is running to fail.

With the signal, which lab should trigger at the same time as calling onCleanup, it will be guaranteed to cause a process uncaughtException, but this time it should be an immediate AbortError which can be ignored, causing no further harm. This is on top of the obvious effect of aborting the no longer relevant request.

Note: This feature overlaps with the existing onCleanup flag. Any code using non-async onCleanup, can assign the logic as an event listener:

it('does something', async ({ signal }) => {

    signal.addEventListener('abort', () => {

        /* onCleanup logic goes here */
     });

     // or even simpler

    signal.onabort = () => {

        /* onCleanup logic goes here */
     };
});
Ngôn ngữ chính
JavaScript
Star
737
Fork
177
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

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.

Issue khác của hapijs/lab

Tất cả issue của hapijs/lab

Issue tương tự

Thêm issue về JavaScript

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.