Skip to content

fix(jest): pass findRelatedTests files as positional args#2180

Closed
just-jeb wants to merge 2 commits intomasterfrom
fix/jest-find-related-tests-argv
Closed

fix(jest): pass findRelatedTests files as positional args#2180
just-jeb wants to merge 2 commits intomasterfrom
fix/jest-find-related-tests-argv

Conversation

@just-jeb
Copy link
Copy Markdown
Owner

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

Problem

Fixes #2150

Root cause

Angular CLI passes comma-separated CLI values as a single string for array-type schema fields. So:

ng test --find-related-tests file1,file2

...arrives at OptionsConverter as options.findRelatedTests = 'file1,file2' (a string, not an array).

The existing string branch then emits:

--findRelatedTests=file1,file2

But Jest declares --findRelatedTests as a boolean yargs option. When yargs sees --findRelatedTests=file1,file2 for a boolean option, it coerces the value → false, and no positional file paths land in argv._. Result: Pattern: file1,file2 - 0 matches.

Why is this only surfacing now?

This was always broken — it just wasn't widely reported. The feature has been available since the original find-related-tests schema addition (2019), and the README even documents the comma-separated syntax as the correct way to pass multiple files. The bug affects anyone trying to use it.

Fix

Introduce POSITIONAL_ARRAY_OPTIONS — a set of option names that Jest treats as a boolean flag with file paths as trailing positional arguments (parsed via yargs _). For these options, the converter:

  1. Splits the comma-separated string into individual paths
  2. Emits the boolean flag once: --findRelatedTests
  3. Appends the paths as positional args at the end of argv

Result for ng test --find-related-tests file1,file2:

--findRelatedTests file1 file2

Jest yargs parsing: findRelatedTests=true, _=['file1', 'file2']

Also handles array values (e.g. from angular.json) for the same options.

Tests

Added four unit tests to options-converter.spec.ts covering:

  • Comma-separated string (the Angular CLI case)
  • Single file path string
  • Array value (from angular.json)
  • Correct positioning of positional args after other flags

Jest's --findRelatedTests is a boolean flag; the source files
to test are positional arguments (parsed via yargs _), not
repeated --flag value pairs.

Previously, passing --find-related-tests file1,file2 via the
Angular CLI would produce:

  --findRelatedTests file1 --findRelatedTests file2

Jest ignores the repeated flags and sees no positional file
paths, resulting in '0 matches'.

The fix introduces POSITIONAL_ARRAY_OPTIONS — a set of option
names that need this treatment. For these options the converter
emits the boolean flag once and appends the values as trailing
positional args:

  --findRelatedTests file1 file2

Fixes #2150
…om Angular CLI

Angular CLI passes comma-separated CLI values as a single string for
array-type schema fields. So:

  ng test --find-related-tests file1,file2

...arrives at OptionsConverter as options.findRelatedTests = 'file1,file2'
(a string, not an array).

The old string branch emitted:

  --findRelatedTests=file1,file2

But Jest declares --findRelatedTests as a boolean yargs option, so
'=file1,file2' is treated as a boolean coercion → false, and no
positional file paths are collected. Result: '0 matches'.

The fix introduces POSITIONAL_ARRAY_OPTIONS for options that Jest treats
as a boolean flag with file paths as trailing positional args. For these,
the converter:
1. Splits the comma-separated string into individual paths
2. Emits the boolean flag once: --findRelatedTests
3. Appends the paths as positional args at the end of argv

Also handles array values (e.g. from angular.json) for the same options.

Fixes #2150
@just-jeb just-jeb closed this Apr 24, 2026
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.

Angular 20: --findRelatedTests doesn't work

1 participant