test_runner: change-aware test selection
Nessuno ha ancora preso questa issue.
- Lingua principale
- JavaScript
- Stelle
- 122k
- Fork
- 37.3k
- Merge medio
- 4g 2h
- PR unite (30g)
- 283
Descrizione
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 dynamicimport(), 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia dal punto di ingresso node --test, dall’implementazione esistente di --watch e da run({ files }); poi traccia il resolver usato dal test runner. Il lavoro è completo quando i test vengono selezionati tramite dipendenze statiche dei moduli, mentre i test con dipendenze opache o modifiche globali ai pacchetti vengono eseguiti in modo conservativo, con copertura per i casi CJS e di dipendenze invisibili indicati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- cli, testing
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100