• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1namespace ts.tscWatch {
2    describe("unittests:: tsc-watch:: console clearing", () => {
3        const scenario = "consoleClearing";
4        const file: File = {
5            path: "/f.ts",
6            content: ""
7        };
8
9        const makeChangeToFile: TscWatchCompileChange[] = [{
10            caption: "Comment added to file f",
11            change: sys => sys.modifyFile(file.path, "//"),
12            timeouts: runQueuedTimeoutCallbacks,
13        }];
14
15        function checkConsoleClearingUsingCommandLineOptions(subScenario: string, commandLineOptions?: string[]) {
16            verifyTscWatch({
17                scenario,
18                subScenario,
19                commandLineArgs: ["--w", file.path, ...commandLineOptions || emptyArray],
20                sys: () => createWatchedSystem([file, libFile]),
21                changes: makeChangeToFile,
22            });
23        }
24
25        checkConsoleClearingUsingCommandLineOptions("without --diagnostics or --extendedDiagnostics");
26        checkConsoleClearingUsingCommandLineOptions("with --diagnostics", ["--diagnostics"]);
27        checkConsoleClearingUsingCommandLineOptions("with --extendedDiagnostics", ["--extendedDiagnostics"]);
28        checkConsoleClearingUsingCommandLineOptions("with --preserveWatchOutput", ["--preserveWatchOutput"]);
29
30        describe("when preserveWatchOutput is true in config file", () => {
31            const compilerOptions: CompilerOptions = {
32                preserveWatchOutput: true
33            };
34            const configFile: File = {
35                path: "/tsconfig.json",
36                content: JSON.stringify({ compilerOptions })
37            };
38            const files = [file, configFile, libFile];
39            it("using createWatchOfConfigFile ", () => {
40                const baseline = createBaseline(createWatchedSystem(files));
41                const watch = createWatchOfConfigFile(configFile.path, baseline.sys);
42                // Initially console is cleared if --preserveOutput is not provided since the config file is yet to be parsed
43                runWatchBaseline({
44                    scenario,
45                    subScenario: "when preserveWatchOutput is true in config file/createWatchOfConfigFile",
46                    commandLineArgs: ["--w", "-p", configFile.path],
47                    ...baseline,
48                    getPrograms: () => [[watch.getCurrentProgram().getProgram(), watch.getCurrentProgram()]],
49                    changes: makeChangeToFile,
50                    watchOrSolution: watch
51                });
52            });
53            verifyTscWatch({
54                scenario,
55                subScenario: "when preserveWatchOutput is true in config file/when createWatchProgram is invoked with configFileParseResult on WatchCompilerHostOfConfigFile",
56                commandLineArgs: ["--w", "-p", configFile.path],
57                sys: () => createWatchedSystem(files),
58                changes: makeChangeToFile,
59            });
60        });
61    });
62}
63