Skip to content

fix(jest): pass findRelatedTests files as trailing positional args (fixes #1859)#2185

Closed
just-jeb wants to merge 3 commits intomasterfrom
fix/find-related-tests-comma-separated
Closed

fix(jest): pass findRelatedTests files as trailing positional args (fixes #1859)#2185
just-jeb wants to merge 3 commits intomasterfrom
fix/find-related-tests-comma-separated

Conversation

@just-jeb
Copy link
Copy Markdown
Owner

@just-jeb just-jeb commented Apr 25, 2026

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 --findRelatedTests as a boolean flag — source files are passed as positional arguments (parsed via yargs _), not as repeated --flag value pairs.

The OptionsConverter was handling findRelatedTests via the generic array branch:

// Before (wrong):
--findRelatedTests file1.ts --findRelatedTests file2.ts
// Jest sees: findRelatedTests=true, _=[] → runs ALL tests

// After (correct):
--findRelatedTests file1.ts file2.ts
// Jest sees: findRelatedTests=true, _=["file1.ts", "file2.ts"] ✓

Fix

Introduces POSITIONAL_ARRAY_OPTIONS — a set of options whose values should be emitted as trailing positional args after a single boolean flag. findRelatedTests is the only member.

Tests

Unit tests added to options-converter.spec.ts (fail on master, pass with fix):

  • Single file: [src/foo.spec.ts][--findRelatedTests, src/foo.spec.ts]
  • Multiple files: [src/foo.spec.ts, src/bar.spec.ts][--findRelatedTests, src/foo.spec.ts, src/bar.spec.ts]

The existing multi-project-find-related integration test (space-separated multi-file) continues to pass.

Closes #1859

Houston (Jeb's AI agent) 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
@just-jeb just-jeb changed the title fix(jest): pass findRelatedTests files as positional args (fixes #1859, #2150) fix(jest): pass findRelatedTests files as trailing positional args (fixes #1859) Apr 25, 2026
@just-jeb just-jeb closed this Apr 25, 2026
@just-jeb just-jeb deleted the fix/find-related-tests-comma-separated branch April 25, 2026 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ng test <project> --find-related-tests <test-file-path>

1 participant