nodejs / nodejs/node

test_runner: change-aware test selection

Abierto
#66,006 2 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

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?

node --test always runs every test file. There is no way to run only the tests affected by a change.

--watch does this, but only while it stays running. CI, a pre-commit hook, or a branch diff all start cold and run everything.

Jest (--onlyChanged) and Vitest (--changed) both do this.

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

Run only the test files whose module graph reaches a given set of files.

$ node --test --related=src/util.ts               # tests that depend on a file
$ git diff --name-only | node --test --related=-  # tests affected by a change

Graph-aware, not path-based: a test that imports a module that imports the changed file is selected. Conservative by default, so anything the graph cannot see has to run, and a change to package.json or a lockfile disables filtering entirely.

Paths rather than a --changed=<rev> flag, because that would mean core shelling out to git. There is no VCS dependency anywhere in lib/ today and I don't think this justifies introducing one. --changed can be layered on later if the team wants it.

Things to figure out
  • CJS. Static imports can be extracted from an ES module without executing it. There is no equivalent for require(), since the bundled lexer reports exports rather than requires. CJS files would be opaque: any test reaching one always runs. Correct, but a CJS-heavy project gets little out of this.
  • Invisible dependencies. A test that reads a fixture with fs, or uses dynamic import(), cannot be selected statically. Those have to resolve to "run it".

Under-selection is the failure mode that matters. Silently skipping a test the change broke is worse than not having the feature.

What alternatives have you considered?

Userland: a wrapper computing the list and passing it to run({ files }). Every such tool has to reimplement module resolution, and gets TypeScript, subpath imports and node_modules boundaries subtly wrong. The resolver is already in core.

--test-rerun-failures covers rerunning what failed, not running what a change could break.

cc @nodejs/test_runner

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

Comienza con el punto de entrada node --test, la implementación existente de --watch y run({ files }); después, sigue el resolver utilizado por el ejecutor de pruebas. Se considera terminado cuando se seleccionen las pruebas mediante dependencias de módulos estáticas, mientras que las pruebas con dependencias opacas o cambios globales de paquetes se ejecuten de forma conservadora, con cobertura para los casos CJS y de dependencias invisibles indicados.

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

Evaluación

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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.