test_runner: allow adapters to handle individual unhandled promise rejections
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 48/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- javascript, node.js
- Domínio
- testing-qa
Direção de pesquisa
Comece pelo tratamento atual de rejections não tratadas do runner node:test, usando o cenário do adaptador WPT do jsdom e as alternativas em nível de processo listadas como contexto de reprodução. Defina a cobertura para rejections reivindicadas, não reivindicadas, que lançam erros e tardias; considera-se concluído quando testes focados confirmarem que as rejections reivindicadas não abortam o teste envolvente, enquanto rejections não relacionadas mantêm o comportamento atual.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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.
- Linguagem predominante
- JavaScript
- Estrelas
- 122k
- Forks
- 37.4k
- Merge médio
- 4d 3h
- PRs com merge (30d)
- 279
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de nodejs/node
-
doc
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
build
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
-
feature request
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
Todas as issues de nodejs/node
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
-
Theme loads third-party resources on every page (jsdelivr web font, cdnjs Font Awesome) – GDPR Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
docToolchain/docToolchain#1705 ·
-
Timezone select lists one option per character; duplicate "Failed" reason; shared tracker popover id Abertabug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
nightscout/nocturne#1414 ·
-
bug v2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
modelcontextprotocol/inspector#2458 · 1 comentário ·
-
Mend: dependency security vulnerability status: needs triage 🕵️♀️
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
carbon-design-system/ibm-products#9907 ·