nodejs / nodejs/node

Unexpected behaviour of `beforeEach` outside of suite without test isolation

Abierto
#61,854 7 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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

Descripción

What is the problem this feature will solve?

In test runners such as jest or vitest, callbacks passed to the methods before, after, beforeEach or afterEach not wrapped in any describe, are called only when tests in their module are about to start or end. That's also the current behaviour when --test-isolation=process. Unfortunately, when the --test-isolation is none, the callbacks we pass to those 4 functions are added as global callbacks and they start to be called before/after each test in any file.

That's unexpected behaviour and it makes it more difficult to migrate from other test runners to node test runner or from the default --test-isolation=process.

What is the feature you are proposing to solve the problem?

Each module should be wrapped in a suite by default, so the callbacks don't leak to the other test modules. The only exception should be callbacks that we pass to those 4 methods in the global setup file(or its imports I guess).

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

Empieza trazando cómo el ejecutor de pruebas de Node.js gestiona los callbacks before, after, beforeEach y afterEach con --test-isolation=process y --test-isolation=none. Comprueba el comportamiento existente entre módulos de prueba separados, incluido el setup global y sus imports. Se considera terminado cuando los callbacks a nivel de módulo ya no se ejecuten para las pruebas de otros módulos, mientras que los callbacks del setup global conserven su ámbito previsto.

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

Evaluación

Stack tecnológico
javascript
Área
testing-qa
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
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.