@@ -184,7 +184,6 @@ describe("code-view worker lifecycle", () => {
184184 vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
185185 // Pins the pool at two workers whatever machine runs the suite.
186186 Object . defineProperty ( navigator , "hardwareConcurrency" , { configurable : true , value : 2 } ) ;
187- vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" ] } ) ;
188187 const initialize = WorkerPoolManager . prototype . initialize ;
189188 vi . spyOn ( WorkerPoolManager . prototype , "initialize" ) . mockImplementation ( function (
190189 this : WorkerPoolManager ,
@@ -197,6 +196,7 @@ describe("code-view worker lifecycle", () => {
197196 } ) ;
198197
199198 afterEach ( async ( ) => {
199+ if ( ! vi . isFakeTimers ( ) ) vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" ] } ) ;
200200 await unmountAll ( ) ;
201201 await vi . runOnlyPendingTimersAsync ( ) ;
202202 vi . useRealTimers ( ) ;
@@ -228,6 +228,9 @@ describe("code-view worker lifecycle", () => {
228228 expect ( pool . getFileResultCache ( files [ 1 ] ! ) ) . toBeDefined ( ) ;
229229 await vi . waitFor ( ( ) => expect ( codeFile ( "answer.ts" ) ) . toContain ( "answer" ) ) ;
230230
231+ // Worker startup uses real time. Only advance the clock once highlighting
232+ // has finished, so idle expiry cannot also expire a worker startup timer.
233+ vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" ] } ) ;
231234 await view . render ( renderViews ( 1 ) ) ;
232235 expect ( pool . getStats ( ) . totalWorkers ) . toBe ( 2 ) ;
233236 expect ( testState . terminations ) . toBe ( 0 ) ;
@@ -249,6 +252,7 @@ describe("code-view worker lifecycle", () => {
249252 expect ( pool . getStats ( ) . totalWorkers ) . toBe ( 0 ) ;
250253 expect ( testState . terminations ) . toBe ( 2 ) ;
251254
255+ vi . useRealTimers ( ) ;
252256 await view . render ( renderViews ( 1 ) ) ;
253257 const reopenedPool = [ ...testState . pools . keys ( ) ] [ 1 ] ! ;
254258 await act ( async ( ) => testState . pools . get ( reopenedPool ) ) ;
@@ -277,6 +281,7 @@ describe("code-view worker lifecycle", () => {
277281 } ) ;
278282
279283 it ( "keeps an initializing pool until its last view closes and ignores late responses" , async ( ) => {
284+ vi . useFakeTimers ( { toFake : [ "setTimeout" , "clearTimeout" ] } ) ;
280285 testState . holdInitialization = true ;
281286 const held = new Promise < void > ( ( resolve ) => {
282287 testState . onInitializationHeld = resolve ;
0 commit comments