Update Jest entry patterns for Jest 30#1808
Merged
Merged
Conversation
Member
|
Thank you! 👌 |
Member
|
🚀 This pull request is included in v6.18.0. See Release 6.18.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
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.
Support Jest 30 test file extensions
Summary
Align the Jest plugin's default entry patterns with Jest 30 by recognizing
.mjs,.cjs,.mts, and.ctstest files.Background
Jest 30 updated its default
testMatchandtestRegexpatterns to recognize.mjs,.cjs,.mts, and.ctsfiles without requiring a custom configuration.Knip's default Jest entry patterns only recognized
.js,.jsx,.ts, and.tsxfiles. As a result, in projects that use Jest 30 without a customtestMatch, Jest could execute a file such asmodule.test.mtswhile Knip did not recognize it as a Jest entry file. This could cause Knip to incorrectly report the test file as unused.Changes
Update the default Jest entry patterns from:
to:
The optional
?(c|m)segment preserves support for the existing extensions while adding support for:.mjs.cjs.mts.ctsProjects that define a custom
testMatchcontinue to use that configuration. This change only affects the default entry patterns used whentestMatchis not configured.Test coverage
Add
module.test.mtsto the existingjest3fixture. The previous pattern does not recognize this file as a Jest entry, while the updated pattern does.Update the expected
processedandtotalcounters from 3 to 4 to verify that Knip discovers the new fixture file.The following checks pass:
pnpm exec tsx --test test/plugins/jest.test.ts test/plugins/jest2.test.ts test/plugins/jest3.test.tspnpm exec oxlint src/plugins/jest/index.ts test/plugins/jest3.test.tspnpm exec oxfmt --check src/plugins/jest/index.ts test/plugins/jest3.test.tsReferences
testMatchconfiguration