nodejs / nodejs/node

coverage testing blocked by promise should report where that promise came from

Aperta
#59,940 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

test_runner
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

Version

24.8.0

Platform
macos sequioa
Subsystem

test runner

What steps will reproduce the bug?

create any dir and put a test.js file in it with content:

import test, { describe } from "node:test";
import assert from "node:assert/strict";

describe(`project testing`, async () => {
  test(`this'll hang`, async () => {
    const value = await new Promise((resolve) => {
      console.log(`looks like this'll never resolve()`);
    });
    assert.equal(value, true);
  });
});

Then run this with node --test "test.js"

Obviously this'll never finish, so hit ctrl-c, which triggers the final report and shows:

^C✖ test.js (1376.646ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 0
ℹ cancelled 1
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 1379.56475

✖ failing tests:

test at test.js:1:1
✖ test.js (1376.646ms)
  'Promise resolution is still pending but the event loop has already resolved'

And, sure: that's true... but this message also isn't information, because it tells us nothing that lets us fix the problem.

Which promise is still pending? Which file, line, and column and the promise invocation be found on? Because Node knows where promise call sites are, and it should include that information in the error report.

How often does it reproduce? Is there a required condition?

This is how things work right now.

What is the expected behavior? Why is that the expected behavior?

The error should be:

test at test.js:6:18
✖ test.js (1598.681125ms)
  'Promise resolution is still pending but the event loop has already resolved'

explicitly showing the line things went wrong on.

And if there is a promise pending because of some dependency of a dependency, it should show that entire trace: if test.js is awaiting getInfo() imported from ./utils.js and that calls getNetworkDeviceNames() imported from ./utils/network.js and that has a promise that never resolves, then this error should let folks find that problem:

test at test.js:6:18
  at utils.js:20:14
  at utils/network.js:112:25
✖ test.js (1598.681125ms)
  'Promise resolution is still pending but the event loop has already resolved'

Or however traces should be made to look for this functionality. The important part is that it's informative so that we can fix bugs. After all, that's the whole point of using node --test =)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci il comportamento con il test.js descritto e node --test "test.js", quindi parti dalla gestione del report di pending-promise da parte del test runner. Traccia il modo in cui sono rappresentati i siti di chiamata delle promise e le chiamate asincrone dipendenti, e definisci l’output in modo che includa le posizioni di origine e qualsiasi traccia delle dipendenze rilevante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript
Ambito
testing
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.