Add --related-to flag to run only tests affected by changed files#3470
Open
stevenmini2019 wants to merge 1 commit into
Open
Add --related-to flag to run only tests affected by changed files#3470stevenmini2019 wants to merge 1 commit into
stevenmini2019 wants to merge 1 commit into
Conversation
Implements avajs#1986. The new `--related-to <files>` CLI flag runs only the test files that (transitively) import the given source files, mirroring `jest --findRelatedTests`. It builds an import graph for the discovered test files and selects those connected to the changed sources, which makes it useful for pre-commit hooks (e.g. lint-staged) that only want to run affected tests. - New lib/related-tests.js with createRelatedTestSelector() - Wired into lib/cli.js as a testFileSelector - Unit tests under test/related-tests/ - Documented in docs/05-command-line.md
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.
Summary
Implements #1986 by adding a
--related-to <files>CLI flag that runs only the test files which (transitively) import the given source files — the AVA equivalent ofjest --findRelatedTests.This is intended for pre-commit hooks (e.g.
lint-staged) where you only want to run the tests that could be affected by the files that changed, instead of the whole suite.How it works
lib/related-tests.jsexposescreateRelatedTestSelector(relatedTo, projectDir).source file → test filesand keeps only the test files connected to any of the files passed to--related-to.lib/cli.jsas the existingtestFileSelectorhook onApi#run, so it composes with other patterns/--matchfilters.Notes / limitations
import type {…}) are followed as well, which can make the selection slightly over-inclusive but never under-inclusive.--related-tocan be combined with a glob or--match.Test plan
test/related-tests/test.jsunit-tests the selector: single-file selection, multi-file selection, transitive imports, interaction with an existing selection filter, empty input, and space/comma-separated inputs.ava --related-to <source>runs only the related test file(s) out of the full discovered set, including the transitive case wheresrc/foo.jsimportssrc/bar.js.