nodejs / nodejs/node

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

Abierto
#59,940 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

test_runner
Lenguaje dominante
JavaScript
Estrellas
122k
Forks
37.3k
Merge medio
4 d 2 h
PR fusionados (30 d)
283

Descripción

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 =)

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el comportamiento con el test.js descrito y node --test "test.js", y empieza por el procesamiento del informe de pending-promise en el test runner. Rastrea cómo se representan los sitios de llamada de las promesas y las llamadas asíncronas dependientes, y define la salida para que incluya las ubicaciones de origen y cualquier traza de dependencias relevante.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
testing
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Tranquilo
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.