Skip to content

Commit 4ed63e5

Browse files
committed
Add test for preserveWatchOutput on command line
#26873
1 parent 4cf746c commit 4ed63e5

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/testRunner/unittests/tsbuildWatchMode.ts

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace ts.tscWatch {
22
export import libFile = TestFSWithWatch.libFile;
33
function createSolutionBuilder(system: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
44
const host = createSolutionBuilderWithWatchHost(system);
5-
return ts.createSolutionBuilder(host, rootNames, defaultOptions || { dry: false, force: false, verbose: false, watch: true });
5+
return ts.createSolutionBuilder(host, rootNames, defaultOptions || { watch: true });
66
}
77

88
function createSolutionBuilderWithWatch(host: WatchedSystem, rootNames: ReadonlyArray<string>, defaultOptions?: BuildOptions) {
@@ -95,11 +95,11 @@ namespace ts.tscWatch {
9595
const allFiles: ReadonlyArray<File> = [libFile, ...core, ...logic, ...tests, ...ui];
9696
const testProjectExpectedWatchedFiles = [core[0], core[1], core[2], ...logic, ...tests].map(f => f.path);
9797

98-
function createSolutionInWatchMode(allFiles: ReadonlyArray<File>) {
98+
function createSolutionInWatchMode(allFiles: ReadonlyArray<File>, defaultOptions?: BuildOptions, disableConsoleClears?: boolean) {
9999
const host = createWatchedSystem(allFiles, { currentDirectory: projectsLocation });
100-
createSolutionBuilderWithWatch(host, [`${project}/${SubProject.tests}`]);
100+
createSolutionBuilderWithWatch(host, [`${project}/${SubProject.tests}`], defaultOptions);
101101
verifyWatches(host);
102-
checkOutputErrorsInitial(host, emptyArray);
102+
checkOutputErrorsInitial(host, emptyArray, disableConsoleClears);
103103
const outputFileStamps = getOutputFileStamps(host);
104104
for (const stamp of outputFileStamps) {
105105
assert.isDefined(stamp[1], `${stamp[0]} expected to be present`);
@@ -351,32 +351,42 @@ function myFunc() { return 100; }`);
351351
}
352352
});
353353

354-
it("reports errors in all projects on incremental compile", () => {
355-
const host = createSolutionInWatchMode(allFiles);
356-
const outputFileStamps = getOutputFileStamps(host);
354+
describe("reports errors in all projects on incremental compile", () => {
355+
function verifyIncrementalErrors(defaultBuildOptions?: BuildOptions, disabledConsoleClear?: boolean) {
356+
const host = createSolutionInWatchMode(allFiles, defaultBuildOptions, disabledConsoleClear);
357+
const outputFileStamps = getOutputFileStamps(host);
357358

358-
host.writeFile(logic[1].path, `${logic[1].content}
359+
host.writeFile(logic[1].path, `${logic[1].content}
359360
let y: string = 10;`);
360361

361-
host.checkTimeoutQueueLengthAndRun(1); // Builds logic
362-
const changedLogic = getOutputFileStamps(host);
363-
verifyChangedFiles(changedLogic, outputFileStamps, emptyArray);
364-
host.checkTimeoutQueueLength(0);
365-
checkOutputErrorsIncremental(host, [
366-
`sample1/logic/index.ts(8,5): error TS2322: Type '10' is not assignable to type 'string'.\n`
367-
]);
362+
host.checkTimeoutQueueLengthAndRun(1); // Builds logic
363+
const changedLogic = getOutputFileStamps(host);
364+
verifyChangedFiles(changedLogic, outputFileStamps, emptyArray);
365+
host.checkTimeoutQueueLength(0);
366+
checkOutputErrorsIncremental(host, [
367+
`sample1/logic/index.ts(8,5): error TS2322: Type '10' is not assignable to type 'string'.\n`
368+
], disabledConsoleClear);
368369

369-
host.writeFile(core[1].path, `${core[1].content}
370+
host.writeFile(core[1].path, `${core[1].content}
370371
let x: string = 10;`);
371372

372-
host.checkTimeoutQueueLengthAndRun(1); // Builds core
373-
const changedCore = getOutputFileStamps(host);
374-
verifyChangedFiles(changedCore, changedLogic, emptyArray);
375-
host.checkTimeoutQueueLength(0);
376-
checkOutputErrorsIncremental(host, [
377-
`sample1/core/index.ts(5,5): error TS2322: Type '10' is not assignable to type 'string'.\n`,
378-
`sample1/logic/index.ts(8,5): error TS2322: Type '10' is not assignable to type 'string'.\n`
379-
]);
373+
host.checkTimeoutQueueLengthAndRun(1); // Builds core
374+
const changedCore = getOutputFileStamps(host);
375+
verifyChangedFiles(changedCore, changedLogic, emptyArray);
376+
host.checkTimeoutQueueLength(0);
377+
checkOutputErrorsIncremental(host, [
378+
`sample1/core/index.ts(5,5): error TS2322: Type '10' is not assignable to type 'string'.\n`,
379+
`sample1/logic/index.ts(8,5): error TS2322: Type '10' is not assignable to type 'string'.\n`
380+
], disabledConsoleClear);
381+
}
382+
383+
it("when preserveWatchOutput is not used", () => {
384+
verifyIncrementalErrors();
385+
});
386+
387+
it("when preserveWatchOutput is passed on command line", () => {
388+
verifyIncrementalErrors({ preserveWatchOutput: true, watch: true }, /*disabledConsoleClear*/ true);
389+
});
380390
});
381391
// TODO: write tests reporting errors but that will have more involved work since file
382392
});

0 commit comments

Comments
 (0)