feat(test): add --changed and --related flags to deno test#35199
Open
lunadogbot wants to merge 2 commits into
Open
feat(test): add --changed and --related flags to deno test#35199lunadogbot wants to merge 2 commits into
lunadogbot wants to merge 2 commits into
Conversation
Capture the actual ask, prior art (Vitest, Jest, Nx, Turborepo, Bazel/Pants/Gradle), what already exists in the codebase (watch-mode affected selection, has_graph_root_local_dependent_changed, workspace graph), a recommended design, and edge cases. Refs #28182
Add Vitest-style dependency-aware test selection to `deno test` as a one-shot (non-watch) run: - `--changed[=<ref>]`: run only test modules affected by files changed in git. With no value it uses the working tree (staged, unstaged and untracked); with a ref it also includes committed changes since the merge-base (`<ref>...HEAD`), matching Vitest/Jest. - `--related=<files>`: run only test modules that depend on the given source files, without consulting git. Both reuse the module graph and the existing `has_graph_root_local_dependent_changed` walk that watch mode already uses to find dependents, so selection works across workspace members (a test in one member that imports another member's changed source is selected). A changed `.env` file disables filtering (any test may read it), mirroring watch mode. A module that is itself a changed/related file is always kept. Both flags conflict with --watch (watch already does continuous dependency-aware reruns). When nothing is affected the run exits 0 with a message instead of erroring. Closes #28182
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #28182
Adds Vitest-style dependency-aware test selection to
deno testas a one-shot(non-watch) run. The issue asked for a way to run only the tests affected by a
change once — watch mode already does dependency-aware reruns, but continuously,
which isn't the workflow the reporter wanted.
Flags
--changed[=<ref>]— run only test modules affected by files changed ingit. With no value it uses the working tree (staged, unstaged and untracked);
with a ref (
--changed=main,--changed=HEAD~1) it additionally includescommitted changes since the merge-base (
<ref>...HEADthree-dot form),matching Vitest and Jest.
--related=<files>— run only test modules that depend on the givensource files, without consulting git (Vitest's
--related).How it works
Both flags resolve a set of changed/related file paths and then filter the
collected test specifiers, reusing the module graph and the existing
has_graph_root_local_dependent_changedwalk that watch mode already uses tofind dependents. Because Deno builds a single module graph spanning the whole
workspace, selection works across workspace members — a test in one member
that imports another member's changed source is selected automatically.
Design details, mostly following prior art (Vitest/Jest/Nx/Turborepo):
.envfile disables filtering (any test may read it), mirroring theexisting watch-mode escape hatch.
dependents fail typecheck anyway).
--watch(watch already does continuousdependency-aware reruns).
0with a message instead of erroring,matching Vitest's behavior with
--changed.Changes
cli/args/flags.rs— flag definitions, parsing,TestFlags::{changed,related}cli/tools/test/mod.rs— git change detection (changed_files_from_git),collect_changed_paths,filter_specifiers_by_changed, wired intorun_teststests/specs/test/{related,changed}— spec tests (hermetic--related;git-based
--changed)Test plan
cargo build/cargo clippy(clean under-D clippy::all) /rustfmt--changed,--related, and the--watchconflict--changed,--changed=<ref>,--related, clean-tree (no-affected message),cross-workspace (editing
b/mod.tsrana/a_test.ts+b/b_test.ts),and self-changed test file
--relatedspec output validated byte-for-byte against the built binaryGenerated by Claude Code