fix(vitest-runner): match Vitest 5 test name separator when filtering tests - #6214
Open
scolladon wants to merge 1 commit into
Open
fix(vitest-runner): match Vitest 5 test name separator when filtering tests#6214scolladon wants to merge 1 commit into
scolladon wants to merge 1 commit into
Conversation
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.
Fixes #6210
On Vitest 5 the per-test name filter matches nothing, so every mutant with per-test coverage runs zero tests and is reported Survived.
Vitest 5 matches
testNamePatternagainst the full chain joined with' > '. The runner builds both the test id and the filter regex fromcollectTestName, which joins with a single space, so the pattern never matches and the mutant run selects no tests.Change
collectTestName/toRawTestIdtake the separator as a parameter, defaulting to the current' 'so nothing changes below Vitest 5. The runner derives it once from the running Vitest version — reusing thesemver.satisfies(vitestWrapper.version, …)approach already used forisGreaterThanVitest4Point1— and both ends use it:testNameSeparator, so the ids recorded inmutantCoverageare built with it;convertTestToTestResult, so the ids reported back match those keys.Both ends must agree, or the coverage keys and the filter would disagree again.
Verification
Reproduced against a real project (~1,700 unit tests, Vitest 5.0.0, runner 10.0.0), scoped to one source file:
testsCompleted{ Ignored: 1, Survived: 23 }{ Ignored: 1, Killed: 23 }coveredBywas correctly populated (2-37 tests per mutant) in both cases — coverage analysis was never the problem, only the filter. The patched run is also faster (25s vs 41s), because it runs the selected test instead of the whole file's worth of nothing.Isolated with a small probe driving
createVitestthe way the runner does, on Vitest 5.0.0:testNamePatternbuilt from' '(current behaviour)' > 'Setting
project.config.testNamePatternaftercreateVitest, and passing cwd-relative paths toctx.start(), both still work on Vitest 5 — only the separator is wrong.Tests
test-helpers.spec.ts:toRawTestIdjoins the suite chain with the given separator.vitest-runner.spec.ts: the runner provides' 'for Vitest <5 and' > 'for >=5. Verified discriminating — moving the threshold to>=6.0.0fails exactly the>=5.0.0case.npm run test:unit(35) andnpm run test:integration(33) pass. Note the repo's dev dependency is Vitest 4.1.11, where this change is a deliberate no-op, so CI here exercises only the backward-compatible path — the Vitest 5 behaviour is covered by the version-gate unit tests above rather than by a live Vitest 5 run.Related
#6146 is complementary: it stops a zero-test mutant run being reported as survived at all. With that in place this bug would have surfaced as a loud failure rather than a silently collapsed score.