Skip to content

fix(jest): emit --findRelatedTests with positional file args (fixes #2150, #1859)#2237

Open
just-jeb wants to merge 2 commits into
masterfrom
fix/find-related-tests-positional
Open

fix(jest): emit --findRelatedTests with positional file args (fixes #2150, #1859)#2237
just-jeb wants to merge 2 commits into
masterfrom
fix/find-related-tests-positional

Conversation

@just-jeb
Copy link
Copy Markdown
Owner

PR Checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

ng test --find-related-tests file1,file2 (the form documented in packages/jest/README.md:193) emits --findRelatedTests=file1,file2 to Jest. Jest treats --findRelatedTests with an = value as a boolean flag and drops the value, so no filtering happens.

The array form (findRelatedTests: ['file1', 'file2']) emits --findRelatedTests file1 --findRelatedTests file2. That happens to work because each repeated --findRelatedTests enables the mode and each value becomes a positional, but it's accidental — re-listing the flag isn't the documented contract.

Issue numbers: #2150, #1859. Re-implements the fix from the closed #2185.

What is the new behavior?

A POSITIONAL_ARRAY_OPTIONS set in options-converter.ts flags Jest options that take positional file args. findRelatedTests is the only one today. The converter:

  1. Pushes --findRelatedTests to the flag list
  2. Splits each value on commas (so the comma syntax works)
  3. Appends all paths as positionals at the end of argv

Both findRelatedTests: 'file1,file2', findRelatedTests: ['file1,file2'], and findRelatedTests: ['file1', 'file2'] now produce [--findRelatedTests, file1, file2].

Unit tests in options-converter.spec.ts cover single file, comma-separated, multi-flag array, single-string, mixed-with-other-flag, and doubled-comma forms.

Integration tests in packages/jest/tests/integration.js:

  • A new multi-project-find-related-comma exercises the comma form documented in the README.
  • A new multi-project-find-related-single actually verifies filtering (1 suite, 1 test). The pre-existing test with two source files was a false-green — the library has exactly two specs, so even broken filtering still produced "2 suites".

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Pre-existing array form keeps producing the same positionals, just emitted via the new positional-args code path. The previously-broken comma form now works.

Other information

N/A

…2150, #1859)

ng test --find-related-tests file1,file2 was emitting --findRelatedTests=file1,file2,
which Jest interprets as a boolean flag with the value discarded, so no filtering
happened. The README documents the comma-separated syntax as the builder's public
API; the builder now translates both array and comma-string forms into Jest's
positional-args calling convention.

Adds unit tests for single file, comma-separated, multi-flag array, single-string
and mixed-with-flag forms. Adds integration tests for the comma-separated form and
a single-file form that genuinely verifies filtering (1 suite, 1 test).
…s for --findRelatedTests

The findRelatedTests describe block in options-converter.spec.ts checked the
internal CLI array returned by convertToCliArgs — an implementation detail.
Three integration tests in integration.js already cover the behavioral outcome:
Jest receives positional file args and finds only the related specs. Remove the
redundant unit assertions so the test suite reflects observable user behavior.
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.

1 participant