@@ -13,11 +13,14 @@ import { OutputHashing } from '../../../application/schema';
1313import { NormalizedUnitTestBuilderOptions , injectTestingPolyfills } from '../../options' ;
1414import { findTests , getTestEntrypoints } from '../../test-discovery' ;
1515import { RunnerOptions } from '../api' ;
16+ import { u } from 'tar' ;
1617
1718function createTestBedInitVirtualFile (
1819 providersFile : string | undefined ,
1920 projectSourceRoot : string ,
21+ polyfills : string [ ] = [ ] ,
2022) : string {
23+ const usesZoneJS = polyfills . includes ( 'zone.js' ) ;
2124 let providersImport = 'const providers = [];' ;
2225 if ( providersFile ) {
2326 const relativePath = path . relative ( projectSourceRoot , providersFile ) ;
@@ -28,15 +31,15 @@ function createTestBedInitVirtualFile(
2831
2932 return `
3033 // Initialize the Angular testing environment
31- import { NgModule } from '@angular/core';
34+ import { NgModule${ usesZoneJS ? ', provideZoneChangeDetection' : '' } } from '@angular/core';
3235 import { getTestBed, ɵgetCleanupHook as getCleanupHook } from '@angular/core/testing';
3336 import { BrowserTestingModule, platformBrowserTesting } from '@angular/platform-browser/testing';
3437 ${ providersImport }
3538 // Same as https://github.com/angular/angular/blob/05a03d3f975771bb59c7eefd37c01fa127ee2229/packages/core/testing/srcs/test_hooks.ts#L21-L29
3639 beforeEach(getCleanupHook(false));
3740 afterEach(getCleanupHook(true));
3841 @NgModule({
39- providers,
42+ providers: [ ${ usesZoneJS ? 'provideZoneChangeDetection(), ' : '' } ...providers] ,
4043 })
4144 export class TestModule {}
4245 getTestBed().initTestEnvironment([BrowserTestingModule, TestModule], platformBrowserTesting(), {
@@ -113,7 +116,11 @@ export async function getVitestBuildOptions(
113116
114117 buildOptions . polyfills = injectTestingPolyfills ( buildOptions . polyfills ) ;
115118
116- const testBedInitContents = createTestBedInitVirtualFile ( providersFile , projectSourceRoot ) ;
119+ const testBedInitContents = createTestBedInitVirtualFile (
120+ providersFile ,
121+ projectSourceRoot ,
122+ buildOptions . polyfills ,
123+ ) ;
117124
118125 return {
119126 buildOptions,
0 commit comments