Skip to content

Commit ba0a2f0

Browse files
committed
fix(@angular/build): re-enable code splitting for unit tests
Re-enables esbuild code splitting for unit test builds by removing `disableCodeSplitting` and resolving the underlying live export binding issue when chunks are loaded by Vitest under Zone.js (#33728): 1. Ensures test spec files are treated as ES modules by appending `export {};` in the Angular compiler plugin if absent. In Zone.js applications, downleveled `async` functions capture module-level `this` via `__async(this, ...)`. Without an explicit export, esbuild misclassified spec files as CommonJS and wrapped them in `__commonJS`, which led to lazy `__esm` initializers for shared dependencies. 2. In the Vitest in-memory provider plugin, eagerly invokes any lazy `__esm` initializers detected in chunks when loaded for `vite-node`. Because `vite-node` statically captures exports upon initial chunk evaluation, eagerly executing the initializers ensures exported values are populated before consumers read them. 3. Enforces `namedChunks: false` for unit test builds to ensure chunks consistently match chunk naming patterns. closes #33948
1 parent c3cefba commit ba0a2f0

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

packages/angular/build/src/tools/esbuild/angular/compiler-plugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,5 +884,7 @@ const SPECS_REGEXP = /\.(?:spec|test)\.[cm]?[jt]sx?$/;
884884
* (https://github.com/angular/angular-cli/issues/33728). Adding an empty export guarantees the file is bundled as an ES module.
885885
*/
886886
function ensureTestFileEsm(request: string, contents: string): string {
887-
return SPECS_REGEXP.test(request) ? contents + '\nexport {};\n' : contents;
887+
return SPECS_REGEXP.test(request) && !contents.includes('export {};')
888+
? contents + '\nexport {};\n'
889+
: contents;
888890
}

0 commit comments

Comments
 (0)