test_runner: change-aware test selection
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 272
Mô tả
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
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với entry point node --test, phần triển khai --watch hiện có và run({ files }); sau đó lần theo resolver được test runner sử dụng. Hoàn thành có nghĩa là chọn các test thông qua các dependency tĩnh của module, đồng thời chạy các test có dependency không thể quan sát hoặc các thay đổi toàn cục đối với package theo cách thận trọng, với coverage cho các trường hợp CJS và dependency ẩn đã nêu.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, node.js
- Lĩnh vực
- cli, testing
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100