Repository navigation
Transpile tests without type checking in jest - #472
Merged
Merged
Conversation
ts-jest type checked test files with settings that differ from tsc (`moduleResolution` falls back to `node10`, which ignores `exports`), so packages that publish types only via `exports` (e.g. chalk 6) failed with TS2307 in jest although tsc passes. Test files are already type checked by `tsc` and ts-loader in the build, so let ts-jest only transpile them. `module: commonjs` keeps `import()` compiled to `require()`, so ESM-only packages can still be mocked with `jest.mock`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atm-snag2
force-pushed
the
jest-resolve-exports-only-packages
branch
from
November 11, 2026 02:21
b5c97e1 to
7ce83a5
Compare
Contributor
Author
Verification (7ce83a5)Node 24.22.1 / pnpm 10.34.7, The fix makes jest pass with chalk 6On the head of #467 (e14a187, chalk 6.0.1), switching only
No regression on
|
jest.config.js on main |
Tests | Time | TS151002 lines |
|---|---|---|---|
| Before this PR | 251 passed | 15.3 s, 13.2 s | 222, 211 |
| This PR | 251 passed | 3.6 s | 0 |
The TS151002 count varies between runs because of parallel workers; the point is that it is printed without this PR and not printed with it.
module: "commonjs" is required
With isolatedModules: true only (keeping module: Node16), 12 tests in publish.test.ts, error-handler.test.ts and app.test.ts fail with:
TypeError: A dynamic import callback was invoked without --experimental-vm-modules
Type errors in test files are still caught by the build
Added const x: number = "x"; to a test file and ran the build that the build job runs:
| Test file | Command | Result |
|---|---|---|
src/lib/error-handler.test.ts |
pnpm run build:server (tsc --build) |
fails with TS2322 |
src/client/lib/embed-init-scripts.test.ts |
pnpm run build:client (webpack, ts-loader) |
fails with TS2322 |
Not verified yet
After this PR is merged, #467 needs to be rebased by Dependabot and its CI checked.
atm-snag2
marked this pull request as ready for review
November 11, 2026 03:35
atm-snag2
requested review from
a team and
tsuzuki-takaaki
and removed request for
a team
November 11, 2026 03:37
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.
What
Stop type checking in jest and let ts-jest only transpile test files (
isolatedModules: true,module: "commonjs"). Type checking stays withtscand ts-loader, which use the same settings as production.Why
The chalk 6 bump (#467) fails in jest with
TS2307: Cannot find module 'chalk' or its corresponding type declarations.main/typesin its package.json and exposes its types only throughexports.moduleResolutionis not set, it usesnode10, which does not readexports.tsc(module: Node16) readsexports, so lint and build pass and runtime is not affected. Only the type check inside jest fails.The type check inside jest duplicates
tscwith different settings, sotscand jest can disagree like this again on future bumps. It also prints aTS151002warning for every transpiled file and makes jest slow.How
buildjob:tsc --buildcoverssrcexceptsrc/client, and webpack's ts-loader coverssrc/client. Type errors in test files are still caught there. Only runningpnpm testalone no longer reports them.module: "commonjs"is required. WithisolatedModules: trueandmodule: Node16,await import("chalk")is kept as a real dynamicimport(), which fails under jest without--experimental-vm-modules, andjest.mockfor ESM-only packages (chalk, chokidar) stops working.tsconfigoption is merged on top ofcompilerOptionsintsconfig.json, sotscis not affected.Verification results are posted as a comment.
Refs