fix(jest): pass findRelatedTests files as positional args#2180
Closed
fix(jest): pass findRelatedTests files as positional args#2180
Conversation
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
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
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
OptionsConverterasoptions.findRelatedTests = 'file1,file2'(a string, not an array).The existing string branch then emits:
But Jest declares
--findRelatedTestsas a boolean yargs option. When yargs sees--findRelatedTests=file1,file2for a boolean option, it coerces the value →false, and no positional file paths land inargv._. 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-testsschema 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:--findRelatedTestsargvResult for
ng test --find-related-tests 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.tscovering:angular.json)