fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191
Open
just-jeb wants to merge 2 commits into
Open
fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191just-jeb wants to merge 2 commits into
just-jeb wants to merge 2 commits into
Conversation
#1899) Angular 19 introduced signals, new control flow syntax, and standalone-by-default components. These produce significantly more complex TypeScript that causes the ts-jest language service (used when isolatedModules: false) to build a full cross-file Program per test file, resulting in severe slowdowns (reports of 2 min → 15 min test runs). Root cause: when isolatedModules is false (previously the implicit default), ts-jest instantiates a TypeScript LanguageService and rebuilds a full Program for each file. Angular 19+'s richer type surface makes this path prohibitively slow. Fix: set isolatedModules: true in the builder's default transformer options. This switches ts-jest to its fast per-file transpile path, matching the recommendation from jest-preset-angular's own example apps since v14.4.0. Cross-file type checking is better served by tsc --noEmit or ng build. Users who need the previous behaviour can opt out in their jest.config.ts: transform: { '^.+\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', { isolatedModules: false }] } BREAKING CHANGE: isolatedModules now defaults to true. This disables cross-file TypeScript type checking during jest runs. Targeted for the next major version.
c66e849 to
2a9ef37
Compare
…on test Remove isolatedModules:true assertions from the unit spec — they tested implementation details (object shape), not user-visible behavior. Replace with targeted assertions on tsconfig path resolution, which is the actual behavioral contract of the resolver. Add isolated-modules-default integration test entry that proves Angular component tests still pass end-to-end with isolatedModules:true active, providing the behavioral regression guard for #1899.
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.
PR Checklist
PR Type
What is the current behavior?
Angular 19 introduced signals, new control flow syntax, and standalone-by-default components. With
isolatedModules: false(today's default),ts-jestbuilds a full cross-file Program per test file, producing severe slowdowns — reports of 2-minute test runs ballooning to 15 minutes after the upgrade.jest-preset-angularhas been recommendingisolatedModules: truesince v14.4.0 and ships it as the default in their A19+ presets.Issue Number: #1899
What is the new behavior?
isolatedModules: trueis set in the default per-project ts-jest transform config. Users can still override via their ownjest.config.{js,ts,...}.Does this PR introduce a breaking change?
isolatedModules: truedisallows certain TS patterns:const enumcannot be inlined across files — must be regularenumor runtime-evaluatedtypemodifier (export type { X }rather thanexport { X }whenXis a type)const enumdeclarations from.d.tsfiles (uncommon) requirepreserveValueImportsThese produce loud TS compile errors at test time, not silent miscompiles. Ships in the next major.
CHANGELOG migration note (draft)
Other information
Branch was force-pushed to drop the unrelated custom-esbuild changes that belonged in PR #2192. Only the jest commit remains.