fix(jest): pass findRelatedTests files as trailing positional args (fixes #1859)#2185
Closed
fix(jest): pass findRelatedTests files as trailing positional args (fixes #1859)#2185
Conversation
added 2 commits
April 24, 2026 19:12
Angular CLI delivers --find-related-tests=a,b as a single-element array containing the comma-joined string ['a,b']. The existing Array.isArray branch emitted '--findRelatedTests a,b' as one positional, which Jest couldn't match — resulting in '0 matches' and no tests running. Fix: introduce POSITIONAL_ARRAY_OPTIONS set for flags that Jest treats as a boolean + trailing positional args. For these options the converter: 1. Emits the boolean flag once (--findRelatedTests) 2. Splits any comma-joined string into individual paths 3. Appends all paths as positionals at the end of argv This preserves the existing space-separated multi-file behaviour (Angular CLI delivers a proper array there) while adding support for the comma-separated form used in angular.json or with --flag=a,b CLI syntax. Also adds an integration test case reproducing the exact failure (multi-project-find-related-comma) which failed on master and passes with this fix. Fixes #2150
Regression tests covering: - Multi-file array input → single --findRelatedTests flag + trailing positionals - Comma-separated paths (Angular CLI inline angular.json style) → split + positionals - Single file → --findRelatedTests + one positional These tests fail on master and pass with the POSITIONAL_ARRAY_OPTIONS fix.
Jest treats --findRelatedTests as a boolean flag; source files must be passed as positional arguments (yargs `_`), not as repeated flag values. Before: --findRelatedTests file1.ts --findRelatedTests file2.ts → Jest sees no source files → runs ALL tests in the project After: --findRelatedTests file1.ts file2.ts → Jest correctly filters to related tests only Introduces POSITIONAL_ARRAY_OPTIONS set for options that follow this flag+positionals pattern. Adds unit tests covering single-file and multi-file inputs. Fixes #1859
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.
Problem
When using
ng test --find-related-tests file1.ts file2.ts, Jest runs all test files in the project instead of filtering to related tests.Root cause
Jest treats
--findRelatedTestsas a boolean flag — source files are passed as positional arguments (parsed via yargs_), not as repeated--flag valuepairs.The
OptionsConverterwas handlingfindRelatedTestsvia the generic array branch:Fix
Introduces
POSITIONAL_ARRAY_OPTIONS— a set of options whose values should be emitted as trailing positional args after a single boolean flag.findRelatedTestsis the only member.Tests
Unit tests added to
options-converter.spec.ts(fail on master, pass with fix):[src/foo.spec.ts]→[--findRelatedTests, src/foo.spec.ts][src/foo.spec.ts, src/bar.spec.ts]→[--findRelatedTests, src/foo.spec.ts, src/bar.spec.ts]The existing
multi-project-find-relatedintegration test (space-separated multi-file) continues to pass.Closes #1859