@@ -2315,63 +2315,97 @@ declare module "fs" {
2315
2315
describe ( "tsc-watch console clearing" , ( ) => {
2316
2316
const currentDirectoryLog = "Current directory: / CaseSensitiveFileNames: false\n" ;
2317
2317
const fileWatcherAddedLog = [
2318
- "FileWatcher:: Added:: WatchInfo: f.ts 250 Source file\n" ,
2318
+ "FileWatcher:: Added:: WatchInfo: / f.ts 250 Source file\n" ,
2319
2319
"FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 Source file\n"
2320
2320
] ;
2321
2321
2322
+ const file : File = {
2323
+ path : "/f.ts" ,
2324
+ content : ""
2325
+ } ;
2326
+
2322
2327
function getProgramSynchronizingLog ( options : CompilerOptions ) {
2323
2328
return [
2324
2329
"Synchronizing program\n" ,
2325
2330
"CreatingProgramWith::\n" ,
2326
- " roots: [\"f.ts\"]\n" ,
2331
+ " roots: [\"/ f.ts\"]\n" ,
2327
2332
` options: ${ JSON . stringify ( options ) } \n`
2328
2333
] ;
2329
2334
}
2330
2335
2331
- function checkConsoleClearing ( options : CompilerOptions = { } ) {
2332
- const file = {
2333
- path : "f.ts" ,
2334
- content : ""
2335
- } ;
2336
- const files = [ file , libFile ] ;
2337
- const disableConsoleClear = options . diagnostics || options . extendedDiagnostics || options . preserveWatchOutput ;
2336
+ function isConsoleClearDisabled ( options : CompilerOptions ) {
2337
+ return options . diagnostics || options . extendedDiagnostics || options . preserveWatchOutput ;
2338
+ }
2339
+
2340
+ function verifyCompilation ( host : WatchedSystem , options : CompilerOptions , initialDisableOptions ?: CompilerOptions ) {
2341
+ const disableConsoleClear = isConsoleClearDisabled ( options ) ;
2338
2342
const hasLog = options . extendedDiagnostics || options . diagnostics ;
2339
- const host = createWatchedSystem ( files ) ;
2340
- createWatchOfFilesAndCompilerOptions ( [ file . path ] , host , options ) ;
2341
- checkOutputErrorsInitial ( host , emptyArray , disableConsoleClear , hasLog ? [
2343
+ checkOutputErrorsInitial ( host , emptyArray , initialDisableOptions ? isConsoleClearDisabled ( initialDisableOptions ) : disableConsoleClear , hasLog ? [
2342
2344
currentDirectoryLog ,
2343
2345
...getProgramSynchronizingLog ( options ) ,
2344
2346
...( options . extendedDiagnostics ? fileWatcherAddedLog : emptyArray )
2345
2347
] : undefined ) ;
2346
-
2347
- file . content = "//" ;
2348
- host . reloadFS ( files ) ;
2348
+ host . modifyFile ( file . path , "//" ) ;
2349
2349
host . runQueuedTimeoutCallbacks ( ) ;
2350
2350
checkOutputErrorsIncremental ( host , emptyArray , disableConsoleClear , hasLog ? [
2351
- "FileWatcher:: Triggered with /f.ts1 :: WatchInfo: f.ts 250 Source file\n" ,
2351
+ "FileWatcher:: Triggered with /f.ts 1 :: WatchInfo: / f.ts 250 Source file\n" ,
2352
2352
"Scheduling update\n" ,
2353
- "Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1 :: WatchInfo: f.ts 250 Source file\n"
2353
+ "Elapsed:: 0ms FileWatcher:: Triggered with /f.ts 1 :: WatchInfo: / f.ts 250 Source file\n"
2354
2354
] : undefined , hasLog ? getProgramSynchronizingLog ( options ) : undefined ) ;
2355
2355
}
2356
2356
2357
+ function checkConsoleClearingUsingCommandLineOptions ( options : CompilerOptions = { } ) {
2358
+ const files = [ file , libFile ] ;
2359
+ const host = createWatchedSystem ( files ) ;
2360
+ createWatchOfFilesAndCompilerOptions ( [ file . path ] , host , options ) ;
2361
+ verifyCompilation ( host , options ) ;
2362
+ }
2363
+
2357
2364
it ( "without --diagnostics or --extendedDiagnostics" , ( ) => {
2358
- checkConsoleClearing ( ) ;
2365
+ checkConsoleClearingUsingCommandLineOptions ( ) ;
2359
2366
} ) ;
2360
2367
it ( "with --diagnostics" , ( ) => {
2361
- checkConsoleClearing ( {
2368
+ checkConsoleClearingUsingCommandLineOptions ( {
2362
2369
diagnostics : true ,
2363
2370
} ) ;
2364
2371
} ) ;
2365
2372
it ( "with --extendedDiagnostics" , ( ) => {
2366
- checkConsoleClearing ( {
2373
+ checkConsoleClearingUsingCommandLineOptions ( {
2367
2374
extendedDiagnostics : true ,
2368
2375
} ) ;
2369
2376
} ) ;
2370
2377
it ( "with --preserveWatchOutput" , ( ) => {
2371
- checkConsoleClearing ( {
2378
+ checkConsoleClearingUsingCommandLineOptions ( {
2372
2379
preserveWatchOutput : true ,
2373
2380
} ) ;
2374
2381
} ) ;
2382
+
2383
+ describe ( "when preserveWatchOutput is true in config file" , ( ) => {
2384
+ const compilerOptions : CompilerOptions = {
2385
+ preserveWatchOutput : true
2386
+ } ;
2387
+ const configFile : File = {
2388
+ path : "/tsconfig.json" ,
2389
+ content : JSON . stringify ( { compilerOptions } )
2390
+ } ;
2391
+ const files = [ file , configFile , libFile ] ;
2392
+ it ( "using createWatchOfConfigFile " , ( ) => {
2393
+ const host = createWatchedSystem ( files ) ;
2394
+ createWatchOfConfigFile ( configFile . path , host ) ;
2395
+ // Initially console is cleared if --preserveOutput is not provided since the config file is yet to be parsed
2396
+ verifyCompilation ( host , compilerOptions , { } ) ;
2397
+ } ) ;
2398
+ it ( "when createWatchProgram is invoked with configFileParseResult on WatchCompilerHostOfConfigFile" , ( ) => {
2399
+ const host = createWatchedSystem ( files ) ;
2400
+ const reportDiagnostic = createDiagnosticReporter ( host ) ;
2401
+ const optionsToExtend : CompilerOptions = { } ;
2402
+ const configParseResult = parseConfigFileWithSystem ( configFile . path , optionsToExtend , host , reportDiagnostic ) ! ;
2403
+ const watchCompilerHost = createWatchCompilerHostOfConfigFile ( configParseResult . options . configFilePath ! , optionsToExtend , host , /*createProgram*/ undefined , reportDiagnostic , createWatchStatusReporter ( host ) ) ;
2404
+ watchCompilerHost . configFileParsingResult = configParseResult ;
2405
+ createWatchProgram ( watchCompilerHost ) ;
2406
+ verifyCompilation ( host , compilerOptions ) ;
2407
+ } ) ;
2408
+ } ) ;
2375
2409
} ) ;
2376
2410
2377
2411
describe ( "tsc-watch with different polling/non polling options" , ( ) => {
0 commit comments