Skip to content

Update Jest entry patterns for Jest 30#1808

Merged
webpro merged 1 commit into
webpro-nl:mainfrom
gwagjiug:fix/jest-30-test-extensions
Jun 22, 2026
Merged

Update Jest entry patterns for Jest 30#1808
webpro merged 1 commit into
webpro-nl:mainfrom
gwagjiug:fix/jest-30-test-extensions

Conversation

@gwagjiug

Copy link
Copy Markdown
Contributor

Support Jest 30 test file extensions

Summary

Align the Jest plugin's default entry patterns with Jest 30 by recognizing .mjs, .cjs, .mts, and .cts test files.

Background

Jest 30 updated its default testMatch and testRegex patterns to recognize .mjs, .cjs, .mts, and .cts files without requiring a custom configuration.

Knip's default Jest entry patterns only recognized .js, .jsx, .ts, and .tsx files. As a result, in projects that use Jest 30 without a custom testMatch, Jest could execute a file such as module.test.mts while 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:

**/__tests__/**/*.[jt]s?(x)
**/?(*.)+(spec|test).[jt]s?(x)

to:

**/__tests__/**/*.?(c|m)[jt]s?(x)
**/?(*.)+(spec|test).?(c|m)[jt]s?(x)

The optional ?(c|m) segment preserves support for the existing extensions while adding support for:

  • .mjs
  • .cjs
  • .mts
  • .cts

Projects that define a custom testMatch continue to use that configuration. This change only affects the default entry patterns used when testMatch is not configured.

Test coverage

Add module.test.mts to the existing jest3 fixture. The previous pattern does not recognize this file as a Jest entry, while the updated pattern does.

Update the expected processed and total counters 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.ts
  • pnpm exec oxlint src/plugins/jest/index.ts test/plugins/jest3.test.ts
  • pnpm exec oxfmt --check src/plugins/jest/index.ts test/plugins/jest3.test.ts

References

@webpro

webpro commented Jun 22, 2026

Copy link
Copy Markdown
Member

Thank you! 👌

@webpro webpro merged commit d2caedd into webpro-nl:main Jun 22, 2026
12 checks passed
@webpro

webpro commented Jun 22, 2026

Copy link
Copy Markdown
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.

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.

2 participants