fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191
Open
fix(jest): default isolatedModules to true for faster compilation (fixes #1899)#2191
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.
…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
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.
Problem
Reporters upgrading from
@angular-builders/jest@18to@19see 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 → slowisolatedModules: true→ ts-jest uses a fast per-file transpile path → fastWhy 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
transformoptions inresolveForProject()without settingisolatedModules, so ts-jest defaults tofalse. Users have no obvious way to know they need to override this.Fix
Set
isolatedModules: truein 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 testcan opt out via theirjest.config.ts:For most teams, cross-file type checking is better handled by
tsc --noEmitorng build.Breaking Change
This is a BREAKING CHANGE:
isolatedModulesnow defaults totrue, 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
DefaultConfigResolver.resolveForProject()to assertisolatedModules: truein the transform optionsFixes #1899