test_runner: allow adapters to handle individual unhandled promise rejections
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 48/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- javascript, node.js
- 領域
- testing-qa
研究方向
從 node:test runner 目前對未處理 rejection 的處理開始,以 jsdom WPT adapter 情境和列出的程序層級替代方案作為重現脈絡。定義對已認領、未認領、拋出錯誤和延遲 rejection 的涵蓋範圍;完成的標準是,針對性測試確認已認領的 rejection 不會中止外層 test,而不相關的 rejection 維持目前行為。
由索引模型根據 Issue 內容生成。
描述
What is the problem this feature will solve?
(AI disclosure: text written by GPT-6 Astra Extra High, then read, tweaked, and signed-off on by @domenic.)
We are migrating jsdom's tests to node:test. Our Web Platform Tests adapter runs each WPT file inside a jsdom instance, waits for the embedded testharness.js harness to finish, and checks its results against our expectations.
Some WPTs deliberately produce unhandled rejections in iframe windows. These do not necessarily constitute failures of the parent window's test harness. Other rejections should become harness failures, which the adapter needs to evaluate against expected failures for unimplemented functionality.
Currently, node:test fails and aborts the enclosing test when it observes an unhandled rejection, before our adapter can finish evaluating the WPT. Adding our own process.on("unhandledRejection") listener does not prevent the test runner from independently failing the test.
We need a supported way for an embedded test harness to take responsibility for selected rejections, while preserving normal test-runner failure handling for unrelated rejections.
What is the feature you are proposing to solve the problem?
A per-test hook that can handle individual unhandled rejections before the test runner automatically fails or aborts the test.
For example, the API could look like this:
test("embedded harness", {
onUnhandledRejection(reason, promise) {
if (!adapter.ownsPromise(promise)) {
return false;
}
adapter.recordUnhandledRejection(reason, promise);
return true;
}
}, async () => {
await adapter.run();
adapter.assertExpectedResults();
});
The important capabilities would be:
- The hook receives both the rejection reason and the actual promise, allowing the adapter to identify ownership.
- Returning
trueindicates that the adapter accepts responsibility for the rejection. The test runner does not automatically fail or abort the test for that rejection. - Returning
falseorundefinedpreserves current behavior. Throwing from the hook fails the test.
A couple more points GPT-6 Astra Extra High thought were important to include, but seem obvious to @domenic
- Rejections are attributed to the originating test's asynchronous context, including rejections reported after that test finishes. A claimed late rejection should not independently cause the test file to fail; unclaimed late rejections should retain current behavior.
- The hook controls only the test runner's response. It does not suppress other process listeners or change the process's configured unhandled-rejection policy.
This would let adapters classify rejections and finish checking their results without requiring Node to understand the embedded harness's semantics. The adapter would remain responsible for waiting for relevant rejection notifications before completing its test.
What alternatives have you considered?
Stuff that doesn't work that we tried
- Adding a process-level
unhandledRejectionlistener, including a prepended listener. The test runner still receives the event and fails the test. - Using
--unhandled-rejections=none. This suppresses warnings, but does not prevent the test runner from failing the test. - Using
expectFailure. This still lets the runner fail and abort the test instead of letting the embedded harness finish evaluating its results.
Stuff that works but is icky
- Wrapping
process.emitto intercept selected rejection events. Small probes work on Node 22, 24, and 26 while preserving failure handling for unrelated rejections, but this requires monkeypatching and depends on the runner's reporting mechanism. - Using
node:domain. This can redirect rejections, but the API is deprecated and affects more than rejection reporting. - Running the embedded harness in a separate process. This provides control over rejection handling, but adds process management and communication infrastructure.
- Skipping the affected tests. This avoids the immediate failures but loses regression coverage compared to mocha.
- 主要語言
- JavaScript
- 星號
- 122k
- 分支
- 38.4k
- 平均合併
- 4 天 10 小時
- 30 天內合併 PR
- 276
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
nodejs/node 的其他 Issue
-
doc
難度 1/5 1 小時以內 新手友好度 90/100
維護者通常 1 天內回覆
-
doc
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
build
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
nodejs/node#65994 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
-
feature request
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 1 天內回覆
相似的 Issue
-
bug
難度 1/5 1 小時以內 新手友好度 92/100
PedestrianDynamics/pyFDS-Evac#476 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
aiko-chan-ai/DiscordBotClient#380 ·
-
Offisielle trær未關閉
難度 2/5 1-3 小時 新手友好度 65/100
-
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 3 天內回覆
-
Add: Atlas TV未關閉channels:add check:passed
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 4 天內回覆