Skip to content

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

Open
just-jeb wants to merge 2 commits intomasterfrom
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 intomasterfrom
fix/1899-isolated-modules-default

Conversation

@just-jeb
Copy link
Copy Markdown
Owner

Problem

Reporters upgrading from @angular-builders/jest@18 to @19 see dramatic test run slowdowns (e.g. 2 min → 15 min). The root cause is not the builder version itself — it is the interaction between Angular 19 complexity and ts-jest's compilation path.

How ts-jest decides which path to take:

  • isolatedModules: false (previous implicit default) → ts-jest creates a TypeScript LanguageService and builds a full cross-file Program for every test file → slow
  • isolatedModules: true → ts-jest uses a fast per-file transpile path → fast

Why Angular 19 made this worse: Angular 19 introduced signals, new control flow syntax, and standalone-by-default components. These produce significantly richer TypeScript that gives the language service much more work per file. The slowness was latent before; Angular 19 made it visible.

Why the builder is responsible: The builder constructs the transform options in resolveForProject() without setting isolatedModules, so ts-jest defaults to false. Users have no obvious way to know they need to override this.

Fix

Set isolatedModules: true in the builder's default transformer options. This matches the recommendation in jest-preset-angular's own docs and example apps since v14.4.0.

Users who need cross-file type checking during ng test can opt out via their jest.config.ts:

transform: {
  '^.+\\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', { isolatedModules: false }]
}

For most teams, cross-file type checking is better handled by tsc --noEmit or ng build.

Breaking Change

This is a BREAKING CHANGE: isolatedModules now defaults to true, disabling cross-file TypeScript type checking during jest runs. This PR is intentionally targeting the next major version and should not be merged into the current major.

Tests

  • Updated unit tests for DefaultConfigResolver.resolveForProject() to assert isolatedModules: true in the transform options
  • All 35 unit tests pass, no regressions

Fixes #1899

 #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.
…exHtmlTransformer (fixes #1899)

- Add target.configuration to factory plugin example in README (alongside existing target.project)
- Update indexHtmlTransformer examples (JS and TS) to include the target param with comments
- Add integration test 'target-options-in-plugin-and-transformer' that builds with a real
  factory plugin and indexHtmlTransformer, both using target.configuration, then verifies
  the value appears in the JS bundle and index.html meta tag
- Add esbuild/define-configuration-plugin.js and esbuild/configuration-transformer.js
  to sanity-esbuild-app as the test fixtures
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.

Performance regression on jest tests after upgrading to Angular 19

1 participant