@@ -20,6 +20,8 @@ import {
2020import {
2121 changeToHostTrackingWrittenFiles ,
2222 File ,
23+ SerializeOutputOrder ,
24+ StateLogger ,
2325 TestServerHost ,
2426 TestServerHostTrackingWrittenFiles ,
2527} from "./virtualFileSystemWithWatch" ;
@@ -63,13 +65,12 @@ export interface TscWatchCompile extends TscWatchCompileBase {
6365export const noopChange : TscWatchCompileChange = {
6466 caption : "No change" ,
6567 edit : ts . noop ,
66- timeouts : sys => sys . logTimeoutQueueLength ( ) ,
68+ timeouts : ts . noop ,
6769} ;
6870
69- export type SystemSnap = ReturnType < TestServerHost [ "snap" ] > ;
7071function tscWatchCompile ( input : TscWatchCompile ) {
7172 it ( "tsc-watch:: Generates files matching the baseline" , ( ) => {
72- const { sys, baseline, oldSnap } = createBaseline ( input . sys ( ) ) ;
73+ const { sys, baseline } = createBaseline ( input . sys ( ) ) ;
7374 const {
7475 scenario,
7576 subScenario,
@@ -92,7 +93,6 @@ function tscWatchCompile(input: TscWatchCompile) {
9293 commandLineArgs,
9394 sys,
9495 baseline,
95- oldSnap,
9696 getPrograms,
9797 baselineSourceMap,
9898 baselineDependencies,
@@ -102,44 +102,21 @@ function tscWatchCompile(input: TscWatchCompile) {
102102 } ) ;
103103}
104104
105- export interface TestServerHostWithTimeoutLogging {
106- logTimeoutQueueLength ( ) : void ;
107- }
108-
109- export type TscWatchSystem = TestServerHostTrackingWrittenFiles & TestServerHostWithTimeoutLogging ;
105+ export type TscWatchSystem = TestServerHostTrackingWrittenFiles ;
110106
111- function changeToTestServerHostWithTimeoutLogging ( inputHost : TestServerHostTrackingWrittenFiles , baseline : string [ ] ) : TscWatchSystem {
112- const host = inputHost as TscWatchSystem ;
113- const originalRunQueuedTimeoutCallbacks = host . runQueuedTimeoutCallbacks ;
114- const originalRunQueuedImmediateCallbacks = host . runQueuedImmediateCallbacks ;
115- host . runQueuedTimeoutCallbacks = runQueuedTimeoutCallbacks ;
116- host . runQueuedImmediateCallbacks = runQueuedImmediateCallbacks ;
117- host . logTimeoutQueueLength = logTimeoutQueueLength ;
107+ function changeToTestServerHostWithTimeoutLogging ( host : TestServerHostTrackingWrittenFiles , baseline : string [ ] ) : TscWatchSystem {
108+ const logger : StateLogger = {
109+ log : s => baseline . push ( s ) ,
110+ logs : baseline ,
111+ } ;
112+ host . timeoutCallbacks . switchToBaseliningInvoke ( logger , SerializeOutputOrder . BeforeDiff ) ;
113+ host . immediateCallbacks . switchToBaseliningInvoke ( logger , SerializeOutputOrder . BeforeDiff ) ;
118114 return host ;
119-
120- function logTimeoutQueueLength ( ) {
121- baseline . push ( host . timeoutCallbacks . log ( ) ) ;
122- baseline . push ( host . immediateCallbacks . log ( ) ) ;
123- }
124-
125- function runQueuedTimeoutCallbacks ( timeoutId ?: number ) {
126- baseline . push ( `Before running ${ host . timeoutCallbacks . log ( ) } ` ) ;
127- if ( timeoutId !== undefined ) baseline . push ( `Invoking ${ host . timeoutCallbacks . callbackType } callback:: timeoutId:: ${ timeoutId } :: ${ host . timeoutCallbacks . map [ timeoutId ] . args [ 0 ] } ` ) ;
128- originalRunQueuedTimeoutCallbacks . call ( host , timeoutId ) ;
129- baseline . push ( `After running ${ host . timeoutCallbacks . log ( ) } ` ) ;
130- }
131-
132- function runQueuedImmediateCallbacks ( ) {
133- baseline . push ( `Before running ${ host . immediateCallbacks . log ( ) } ` ) ;
134- originalRunQueuedImmediateCallbacks . call ( host ) ;
135- baseline . push ( `After running ${ host . immediateCallbacks . log ( ) } ` ) ;
136- }
137115}
138116
139117export interface BaselineBase {
140118 baseline : string [ ] ;
141119 sys : TscWatchSystem ;
142- oldSnap : SystemSnap ;
143120}
144121
145122export interface Baseline extends BaselineBase , CommandLineCallbacks {
@@ -153,9 +130,9 @@ export function createBaseline(system: TestServerHost, modifySystem?: (sys: Test
153130 const sys = changeToTestServerHostWithTimeoutLogging ( changeToHostTrackingWrittenFiles ( initialSys ) , baseline ) ;
154131 baseline . push ( `currentDirectory:: ${ sys . getCurrentDirectory ( ) } useCaseSensitiveFileNames: ${ sys . useCaseSensitiveFileNames } ` ) ;
155132 baseline . push ( "Input::" ) ;
156- sys . diff ( baseline ) ;
133+ sys . serializeState ( baseline , SerializeOutputOrder . None ) ;
157134 const { cb, getPrograms } = commandLineCallbacks ( sys ) ;
158- return { sys, baseline, oldSnap : sys . snap ( ) , cb, getPrograms } ;
135+ return { sys, baseline, cb, getPrograms } ;
159136}
160137
161138export function createSolutionBuilderWithWatchHostForBaseline ( sys : TestServerHost , cb : ts . ExecuteCommandLineCallbacks ) {
@@ -208,13 +185,10 @@ function updateWatchHostForBaseline<T extends ts.BuilderProgram>(host: ts.WatchC
208185}
209186
210187export function applyEdit ( sys : BaselineBase [ "sys" ] , baseline : BaselineBase [ "baseline" ] , edit : TscWatchCompileChange [ "edit" ] , caption ?: TscWatchCompileChange [ "caption" ] ) {
211- const oldSnap = sys . snap ( ) ;
212188 baseline . push ( `Change::${ caption ? " " + caption : "" } ` , "" ) ;
213189 edit ( sys ) ;
214190 baseline . push ( "Input::" ) ;
215- sys . diff ( baseline , oldSnap ) ;
216- sys . serializeWatches ( baseline ) ;
217- return sys . snap ( ) ;
191+ sys . serializeState ( baseline , SerializeOutputOrder . AfterDiff ) ;
218192}
219193
220194export interface RunWatchBaseline < T extends ts . BuilderProgram > extends BaselineBase , TscWatchCompileBase < T > {
@@ -230,7 +204,6 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
230204 getPrograms,
231205 sys,
232206 baseline,
233- oldSnap,
234207 baselineSourceMap,
235208 baselineDependencies,
236209 edits,
@@ -243,21 +216,19 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
243216 getPrograms,
244217 oldPrograms : ts . emptyArray ,
245218 sys,
246- oldSnap,
247219 baselineSourceMap,
248220 baselineDependencies,
249221 } ) ;
250222
251223 if ( edits ) {
252224 for ( const { caption, edit, timeouts, symlinksNotReflected, skipStructureCheck } of edits ) {
253- oldSnap = applyEdit ( sys , baseline , edit , caption ) ;
225+ applyEdit ( sys , baseline , edit , caption ) ;
254226 timeouts ( sys , programs , watchOrSolution ) ;
255227 programs = watchBaseline ( {
256228 baseline,
257229 getPrograms,
258230 oldPrograms : programs ,
259231 sys,
260- oldSnap,
261232 baselineSourceMap,
262233 baselineDependencies,
263234 caption,
@@ -291,7 +262,6 @@ export function watchBaseline({
291262 getPrograms,
292263 oldPrograms,
293264 sys,
294- oldSnap,
295265 baselineSourceMap,
296266 baselineDependencies,
297267 caption,
@@ -300,21 +270,18 @@ export function watchBaseline({
300270 symlinksNotReflected,
301271} : WatchBaseline ) {
302272 if ( baselineSourceMap ) generateSourceMapBaselineFiles ( sys ) ;
303- sys . serializeOutput ( baseline ) ;
304273 const programs = getPrograms ( ) ;
305- baselinePrograms ( baseline , programs , oldPrograms , baselineDependencies ) ;
306- sys . serializeWatches ( baseline ) ;
307- baseline . push ( `exitCode:: ExitStatus.${ ts . ExitStatus [ sys . exitCode as ts . ExitStatus ] } ` , "" ) ;
308- sys . diff ( baseline , oldSnap ) ;
309274 sys . writtenFiles . forEach ( ( value , key ) => {
310275 assert . equal ( value , 1 , `Expected to write file ${ key } only once` ) ;
311276 } ) ;
277+ sys . serializeState ( baseline , SerializeOutputOrder . BeforeDiff ) ;
278+ baselinePrograms ( baseline , programs , oldPrograms , baselineDependencies ) ;
279+ baseline . push ( `exitCode:: ExitStatus.${ ts . ExitStatus [ sys . exitCode as ts . ExitStatus ] } ` , "" ) ;
312280 // Verify program structure and resolution cache when incremental edit with tsc --watch (without build mode)
313281 if ( resolutionCache && programs . length ) {
314282 ts . Debug . assert ( programs . length === 1 ) ;
315283 verifyProgramStructureAndResolutionCache ( caption ! , sys , programs [ 0 ] [ 0 ] , resolutionCache , useSourceOfProjectReferenceRedirect , symlinksNotReflected ) ;
316284 }
317- sys . writtenFiles . clear ( ) ;
318285 return programs ;
319286}
320287function verifyProgramStructureAndResolutionCache (
0 commit comments