@@ -342,6 +342,41 @@ namespace ts.projectSystem {
342342 }
343343 }
344344
345+ function patchHostTimeouts ( host : TestFSWithWatch . TestServerHostTrackingWrittenFiles , session : TestSession | TestProjectService ) {
346+ const originalCheckTimeoutQueueLength = host . checkTimeoutQueueLength ;
347+ const originalRunQueuedTimeoutCallbacks = host . runQueuedTimeoutCallbacks ;
348+ const originalRunQueuedImmediateCallbacks = host . runQueuedImmediateCallbacks ;
349+
350+ host . checkTimeoutQueueLengthAndRun = checkTimeoutQueueLengthAndRun ;
351+ host . checkTimeoutQueueLength = checkTimeoutQueueLength ;
352+ host . runQueuedTimeoutCallbacks = runQueuedTimeoutCallbacks ;
353+ host . runQueuedImmediateCallbacks = runQueuedImmediateCallbacks ;
354+
355+ function checkTimeoutQueueLengthAndRun ( expected : number ) {
356+ session . baselineHost ( `Before checking timeout queue length (${ expected } ) and running` ) ;
357+ originalCheckTimeoutQueueLength . call ( host , expected ) ;
358+ originalRunQueuedTimeoutCallbacks . call ( host ) ;
359+ session . baselineHost ( `After checking timeout queue length (${ expected } ) and running` ) ;
360+ }
361+
362+ function checkTimeoutQueueLength ( expected : number ) {
363+ session . baselineHost ( `Checking timeout queue length: ${ expected } ` ) ;
364+ originalCheckTimeoutQueueLength . call ( host , expected ) ;
365+ }
366+
367+ function runQueuedTimeoutCallbacks ( timeoutId ?: number ) {
368+ session . baselineHost ( `Before running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
369+ originalRunQueuedTimeoutCallbacks . call ( host , timeoutId ) ;
370+ session . baselineHost ( `After running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
371+ }
372+
373+ function runQueuedImmediateCallbacks ( checkCount ?: number ) {
374+ session . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
375+ originalRunQueuedImmediateCallbacks . call ( host , checkCount ) ;
376+ session . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
377+ }
378+ }
379+
345380 export interface TestSessionOptions extends server . SessionOptions {
346381 logger : Logger ;
347382 }
@@ -357,6 +392,7 @@ namespace ts.projectSystem {
357392 super ( opts ) ;
358393 this . logger = opts . logger ;
359394 this . testhost = TestFSWithWatch . changeToHostTrackingWrittenFiles ( this . host as TestServerHost ) ;
395+ patchHostTimeouts ( this . testhost , this ) ;
360396 }
361397
362398 getProjectService ( ) {
@@ -408,29 +444,6 @@ namespace ts.projectSystem {
408444 this . hostDiff = this . testhost . snap ( ) ;
409445 this . testhost . writtenFiles . clear ( ) ;
410446 }
411-
412- checkTimeoutQueueLengthAndRun ( expected : number ) {
413- this . baselineHost ( `Before checking timeout queue length (${ expected } ) and running` ) ;
414- this . testhost . checkTimeoutQueueLengthAndRun ( expected ) ;
415- this . baselineHost ( `After checking timeout queue length (${ expected } ) and running` ) ;
416- }
417-
418- checkTimeoutQueueLength ( expected : number ) {
419- this . baselineHost ( `Checking timeout queue length: ${ expected } ` ) ;
420- this . testhost . checkTimeoutQueueLength ( expected ) ;
421- }
422-
423- runQueuedTimeoutCallbacks ( timeoutId ?: number ) {
424- this . baselineHost ( `Before running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
425- this . testhost . runQueuedTimeoutCallbacks ( timeoutId ) ;
426- this . baselineHost ( `After running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
427- }
428-
429- runQueuedImmediateCallbacks ( checkCount ?: number ) {
430- this . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
431- this . testhost . runQueuedImmediateCallbacks ( checkCount ) ;
432- this . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
433- }
434447 }
435448
436449 export function createSession ( host : server . ServerHost , opts : Partial < TestSessionOptions > = { } ) {
@@ -513,6 +526,7 @@ namespace ts.projectSystem {
513526 ...opts
514527 } ) ;
515528 this . testhost = TestFSWithWatch . changeToHostTrackingWrittenFiles ( this . host as TestServerHost ) ;
529+ patchHostTimeouts ( this . testhost , this ) ;
516530 this . baselineHost ( "Creating project service" ) ;
517531 }
518532
@@ -528,29 +542,6 @@ namespace ts.projectSystem {
528542 this . hostDiff = this . testhost . snap ( ) ;
529543 this . testhost . writtenFiles . clear ( ) ;
530544 }
531-
532- checkTimeoutQueueLengthAndRun ( expected : number ) {
533- this . baselineHost ( `Before checking timeout queue length (${ expected } ) and running` ) ;
534- this . testhost . checkTimeoutQueueLengthAndRun ( expected ) ;
535- this . baselineHost ( `After checking timeout queue length (${ expected } ) and running` ) ;
536- }
537-
538- checkTimeoutQueueLength ( expected : number ) {
539- this . baselineHost ( `Checking timeout queue length: ${ expected } ` ) ;
540- this . testhost . checkTimeoutQueueLength ( expected ) ;
541- }
542-
543- runQueuedTimeoutCallbacks ( timeoutId ?: number ) {
544- this . baselineHost ( `Before running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
545- this . testhost . runQueuedTimeoutCallbacks ( timeoutId ) ;
546- this . baselineHost ( `After running timeout callback${ timeoutId === undefined ? "s" : timeoutId } ` ) ;
547- }
548-
549- runQueuedImmediateCallbacks ( checkCount ?: number ) {
550- this . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
551- this . testhost . runQueuedImmediateCallbacks ( checkCount ) ;
552- this . baselineHost ( `Before running immediate callbacks${ checkCount === undefined ? "" : ` and checking length (${ checkCount } )` } ` ) ;
553- }
554545 }
555546
556547 export function createProjectService ( host : TestServerHost , options ?: Partial < TestProjectServiceOptions > ) {
@@ -854,14 +845,14 @@ namespace ts.projectSystem {
854845 Debug . assert ( session . logger . logs . length ) ;
855846 for ( let i = 0 ; i < files . length ; i ++ ) {
856847 if ( existingTimeouts !== undefined ) {
857- session . checkTimeoutQueueLength ( existingTimeouts + 1 ) ;
858- session . runQueuedTimeoutCallbacks ( host . getNextTimeoutId ( ) - 1 ) ;
848+ host . checkTimeoutQueueLength ( existingTimeouts + 1 ) ;
849+ host . runQueuedTimeoutCallbacks ( host . getNextTimeoutId ( ) - 1 ) ;
859850 }
860851 else {
861- session . checkTimeoutQueueLengthAndRun ( 1 ) ;
852+ host . checkTimeoutQueueLengthAndRun ( 1 ) ;
862853 }
863- if ( ! skip ?. [ i ] ?. semantic ) session . runQueuedImmediateCallbacks ( 1 ) ;
864- if ( ! skip ?. [ i ] ?. suggestion ) session . runQueuedImmediateCallbacks ( 1 ) ;
854+ if ( ! skip ?. [ i ] ?. semantic ) host . runQueuedImmediateCallbacks ( 1 ) ;
855+ if ( ! skip ?. [ i ] ?. suggestion ) host . runQueuedImmediateCallbacks ( 1 ) ;
865856 }
866857 }
867858
0 commit comments