Skip to content

fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191

Open
just-jeb wants to merge 2 commits into
masterfrom
fix/1899-isolated-modules-default
Open

fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191
just-jeb wants to merge 2 commits into
masterfrom
fix/1899-isolated-modules-default

Conversation

@just-jeb
Copy link
Copy Markdown
Owner

@just-jeb just-jeb commented Apr 27, 2026

PR Checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

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-jest builds 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-angular has been recommending isolatedModules: true since v14.4.0 and ships it as the default in their A19+ presets.

Issue Number: #1899

What is the new behavior?

isolatedModules: true is set in the default per-project ts-jest transform config. Users can still override via their own jest.config.{js,ts,...}.

Does this PR introduce a breaking change?

[x] Yes
[ ] No

isolatedModules: true disallows certain TS patterns:

  • const enum cannot be inlined across files — must be regular enum or runtime-evaluated
  • Type-only re-exports require the type modifier (export type { X } rather than export { X } when X is a type)
  • Ambient const enum declarations from .d.ts files (uncommon) require preserveValueImports

These produce loud TS compile errors at test time, not silent miscompiles. Ships in the next major.

CHANGELOG migration note (draft)

BREAKING (jest): ts-jest isolatedModules now defaults to true. If your test suite uses const enum across files, or relies on type-only re-exports without the type modifier, you'll get TS compile errors. Either fix the call site (recommended — see TypeScript handbook) or restore the old behavior in your jest config:

transform: { '^.+\\.(ts|mjs|js|html)$': ['jest-preset-angular', { tsconfig: '<rootDir>/tsconfig.spec.json', isolatedModules: false }] }

Other information

Branch was force-pushed to drop the unrelated custom-esbuild changes that belonged in PR #2192. Only the jest commit remains.

Copy link
Copy Markdown
Owner Author

@just-jeb just-jeb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Includes unrelated changes from #2192

 #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.
@just-jeb just-jeb force-pushed the fix/1899-isolated-modules-default branch 2 times, most recently from c66e849 to 2a9ef37 Compare May 17, 2026 14:19
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant