fix(@angular/build): enable code splitting for vitest browser tests - #33949
Merged
alan-agius4 merged 1 commit intoAug 27, 2026
Merged
Conversation
alan-agius4
force-pushed
the
fix-build-vitest-code-splitting
branch
3 times, most recently
from
August 27, 2026 11:59
cfaa501 to
2c03d17
Compare
alan-agius4
force-pushed
the
fix-build-vitest-code-splitting
branch
from
August 27, 2026 12:04
2c03d17 to
e3d55b2
Compare
alan-agius4
force-pushed
the
fix-build-vitest-code-splitting
branch
2 times, most recently
from
August 27, 2026 12:14
3dd7aa1 to
c3cefba
Compare
alan-agius4
marked this pull request as ready for review
August 27, 2026 12:34
There was a problem hiding this comment.
Code Review
This pull request removes the disableCodeSplitting option and resolves ESM binding issues in Vitest/Vite SSR runs. It does this by eagerly invoking __esm initializers in chunk/bundle outputs within the Vitest plugin, and by introducing ensureTestFileEsm in the Angular compiler plugin to append export {}; to test spec files lacking export statements so they are treated as ES modules. The feedback suggests making ensureTestFileEsm idempotent by checking if the file already contains import or export statements before appending export {}; to prevent duplicate appends.
alan-agius4
force-pushed
the
fix-build-vitest-code-splitting
branch
3 times, most recently
from
August 27, 2026 13:09
18757a9 to
15f4dfc
Compare
clydin
approved these changes
Aug 27, 2026
Enables code splitting for Vitest browser tests while keeping it disabled for Node-based tests (JSDOM/Happy-DOM). Vitest's Node-based module loading emulation (vite-node) is not fully spec compliant and lacks live ESM bindings across chunk boundaries, which can cause uninitialized exports and break mocking. In browser tests, however, the real browser adheres to the ECMAScript spec, so code splitting can be safely enabled there.
alan-agius4
force-pushed
the
fix-build-vitest-code-splitting
branch
from
August 27, 2026 13:33
15f4dfc to
0635ef4
Compare
Collaborator
Author
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.
Enables code splitting for Vitest browser tests while keeping it disabled for Node-based tests (JSDOM/Happy-DOM).
Vitest's Node-based module loading emulation (
vite-node) is not fully spec compliant and lacks live ESM bindings across chunk boundaries, which can cause uninitialized exports and break mocking. In browser tests, however, the real browser adheres to the ECMAScript spec, so code splitting can be safely enabled there.