From b7b48569447779399c922f5fd9b2a055375b07e8 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 25 May 2021 17:01:06 -0700 Subject: [PATCH] Refactor tsbuild watch tests (#44258) --- src/testRunner/tsconfig.json | 9 +- .../tsbuildWatch/configFileErrors.ts | 60 ++++ src/testRunner/unittests/tsbuildWatch/demo.ts | 90 +++++ .../tsbuildWatch/moduleResolution.ts | 56 ++++ .../unittests/tsbuildWatch/noEmitOnError.ts | 46 +++ .../programUpdates.ts} | 316 +----------------- .../unittests/tsbuildWatch/reexport.ts | 39 +++ .../watchEnvironment.ts | 2 +- 8 files changed, 313 insertions(+), 305 deletions(-) create mode 100644 src/testRunner/unittests/tsbuildWatch/configFileErrors.ts create mode 100644 src/testRunner/unittests/tsbuildWatch/demo.ts create mode 100644 src/testRunner/unittests/tsbuildWatch/moduleResolution.ts create mode 100644 src/testRunner/unittests/tsbuildWatch/noEmitOnError.ts rename src/testRunner/unittests/{tsbuild/watchMode.ts => tsbuildWatch/programUpdates.ts} (71%) create mode 100644 src/testRunner/unittests/tsbuildWatch/reexport.ts rename src/testRunner/unittests/{tsbuild => tsbuildWatch}/watchEnvironment.ts (96%) diff --git a/src/testRunner/tsconfig.json b/src/testRunner/tsconfig.json index 439b447d639..3b8cc22af21 100644 --- a/src/testRunner/tsconfig.json +++ b/src/testRunner/tsconfig.json @@ -135,8 +135,13 @@ "unittests/tsbuild/resolveJsonModule.ts", "unittests/tsbuild/sample.ts", "unittests/tsbuild/transitiveReferences.ts", - "unittests/tsbuild/watchEnvironment.ts", - "unittests/tsbuild/watchMode.ts", + "unittests/tsbuildWatch/configFileErrors.ts", + "unittests/tsbuildWatch/demo.ts", + "unittests/tsbuildWatch/moduleResolution.ts", + "unittests/tsbuildWatch/noEmitOnError.ts", + "unittests/tsbuildWatch/programUpdates.ts", + "unittests/tsbuildWatch/reexport.ts", + "unittests/tsbuildWatch/watchEnvironment.ts", "unittests/tsc/composite.ts", "unittests/tsc/declarationEmit.ts", "unittests/tsc/incremental.ts", diff --git a/src/testRunner/unittests/tsbuildWatch/configFileErrors.ts b/src/testRunner/unittests/tsbuildWatch/configFileErrors.ts new file mode 100644 index 00000000000..2d0bb90c4cb --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/configFileErrors.ts @@ -0,0 +1,60 @@ +namespace ts.tscWatch { + describe("unittests:: tsbuildWatch:: watchMode:: configFileErrors:: reports syntax errors in config file", () => { + function build(sys: WatchedSystem) { + sys.checkTimeoutQueueLengthAndRun(1); // build the project + sys.checkTimeoutQueueLength(0); + } + verifyTscWatch({ + scenario: "configFileErrors", + subScenario: "reports syntax errors in config file", + sys: () => createWatchedSystem( + [ + { path: `${projectRoot}/a.ts`, content: "export function foo() { }" }, + { path: `${projectRoot}/b.ts`, content: "export function bar() { }" }, + { + path: `${projectRoot}/tsconfig.json`, + content: Utils.dedent` +{ + "compilerOptions": { + "composite": true, + }, + "files": [ + "a.ts" + "b.ts" + ] +}` + }, + libFile + ], + { currentDirectory: projectRoot } + ), + commandLineArgs: ["--b", "-w"], + changes: [ + { + caption: "reports syntax errors after change to config file", + change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, ",", `, + "declaration": true,`), + timeouts: build, + }, + { + caption: "reports syntax errors after change to ts file", + change: sys => replaceFileText(sys, `${projectRoot}/a.ts`, "foo", "fooBar"), + timeouts: build, + }, + { + caption: "reports error when there is no change to tsconfig file", + change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, "", ""), + timeouts: build, + }, + { + caption: "builds after fixing config file errors", + change: sys => sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ + compilerOptions: { composite: true, declaration: true }, + files: ["a.ts", "b.ts"] + })), + timeouts: build, + } + ] + }); + }); +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuildWatch/demo.ts b/src/testRunner/unittests/tsbuildWatch/demo.ts new file mode 100644 index 00000000000..a648f084cd0 --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/demo.ts @@ -0,0 +1,90 @@ +namespace ts.tscWatch { + describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => { + const projectLocation = `${TestFSWithWatch.tsbuildProjectsLocation}/demo`; + let coreFiles: File[]; + let animalFiles: File[]; + let zooFiles: File[]; + let solutionFile: File; + let baseConfig: File; + let allFiles: File[]; + before(() => { + coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]); + animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]); + zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]); + solutionFile = projectFile("tsconfig.json"); + baseConfig = projectFile("tsconfig-base.json"); + allFiles = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile, baseConfig, { path: libFile.path, content: libContent }]; + }); + + after(() => { + coreFiles = undefined!; + animalFiles = undefined!; + zooFiles = undefined!; + solutionFile = undefined!; + baseConfig = undefined!; + allFiles = undefined!; + }); + + verifyTscWatch({ + scenario: "demo", + subScenario: "updates with circular reference", + commandLineArgs: ["-b", "-w", "-verbose"], + sys: () => { + const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); + sys.writeFile(coreFiles[0].path, coreFiles[0].content.replace( + "}", + `}, + "references": [ + { + "path": "../zoo" + } + ]` + )); + return sys; + }, + changes: [ + { + caption: "Fix error", + change: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content), + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // build core + sys.checkTimeoutQueueLengthAndRun(1); // build animals + sys.checkTimeoutQueueLengthAndRun(1); // build zoo + sys.checkTimeoutQueueLengthAndRun(1); // build solution + sys.checkTimeoutQueueLength(0); + }, + } + ] + }); + + verifyTscWatch({ + scenario: "demo", + subScenario: "updates with bad reference", + commandLineArgs: ["-b", "-w", "-verbose"], + sys: () => { + const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); + sys.writeFile(coreFiles[1].path, `import * as A from '../animals'; +${coreFiles[1].content}`); + return sys; + }, + changes: [ + { + caption: "Prepend a line", + change: sys => sys.writeFile(coreFiles[1].path, ` +import * as A from '../animals'; +${coreFiles[1].content}`), + // build core + timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, + } + ] + }); + + function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] { + return fileNames.map(file => projectFile(`${subProject}/${file}`)); + } + + function projectFile(fileName: string): File { + return TestFSWithWatch.getTsBuildProjectFile("demo", fileName); + } + }); +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuildWatch/moduleResolution.ts b/src/testRunner/unittests/tsbuildWatch/moduleResolution.ts new file mode 100644 index 00000000000..d68e63a5c4e --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/moduleResolution.ts @@ -0,0 +1,56 @@ +namespace ts.tscWatch { + describe("unittests:: tsbuildWatch:: watchMode:: module resolution different in referenced project", () => { + verifyTscWatch({ + scenario: "moduleResolutionCache", + subScenario: "handles the cache correctly when two projects use different module resolution settings", + sys: () => createWatchedSystem( + [ + { path: `${projectRoot}/project1/index.ts`, content: `import { foo } from "file";` }, + { path: `${projectRoot}/project1/node_modules/file/index.d.ts`, content: "export const foo = 10;" }, + { + path: `${projectRoot}/project1/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { composite: true, types: ["foo", "bar"] }, + files: ["index.ts"] + }) + }, + { path: `${projectRoot}/project2/index.ts`, content: `import { foo } from "file";` }, + { path: `${projectRoot}/project2/file.d.ts`, content: "export const foo = 10;" }, + { + path: `${projectRoot}/project2/tsconfig.json`, + content: JSON.stringify({ + compilerOptions: { composite: true, types: ["foo"], moduleResolution: "classic" }, + files: ["index.ts"] + }) + }, + { path: `${projectRoot}/node_modules/@types/foo/index.d.ts`, content: "export const foo = 10;" }, + { path: `${projectRoot}/node_modules/@types/bar/index.d.ts`, content: "export const bar = 10;" }, + { + path: `${projectRoot}/tsconfig.json`, + content: JSON.stringify({ + files: [], + references: [ + { path: "./project1" }, + { path: "./project2" } + ] + }) + }, + libFile + ], + { currentDirectory: projectRoot } + ), + commandLineArgs: ["--b", "-w", "-v"], + changes: [ + { + caption: "Append text", + change: sys => sys.appendFile(`${projectRoot}/project1/index.ts`, "const bar = 10;"), + timeouts: sys => { + sys.checkTimeoutQueueLengthAndRun(1); // build project1 + sys.checkTimeoutQueueLengthAndRun(1); // Solution + sys.checkTimeoutQueueLength(0); + } + }, + ] + }); + }); +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuildWatch/noEmitOnError.ts b/src/testRunner/unittests/tsbuildWatch/noEmitOnError.ts new file mode 100644 index 00000000000..34ae0e8bcdf --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/noEmitOnError.ts @@ -0,0 +1,46 @@ +namespace ts.tscWatch { + describe("unittests:: tsbuildWatch:: watchMode:: with noEmitOnError", () => { + function change(caption: string, content: string): TscWatchCompileChange { + return { + caption, + change: sys => sys.writeFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`, content), + // build project + timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, + }; + } + + const noChange: TscWatchCompileChange = { + caption: "No change", + change: sys => sys.writeFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`, sys.readFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`)!), + // build project + timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, + }; + verifyTscWatch({ + scenario: "noEmitOnError", + subScenario: "does not emit any files on error", + commandLineArgs: ["-b", "-w", "-verbose"], + sys: () => createWatchedSystem( + [ + ...["tsconfig.json", "shared/types/db.ts", "src/main.ts", "src/other.ts"] + .map(f => TestFSWithWatch.getTsBuildProjectFile("noEmitOnError", f)), + { path: libFile.path, content: libContent } + ], + { currentDirectory: `${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError` } + ), + changes: [ + noChange, + change("Fix Syntax error", `import { A } from "../shared/types/db"; +const a = { + lastName: 'sdsd' +};`), + change("Semantic Error", `import { A } from "../shared/types/db"; +const a: string = 10;`), + noChange, + change("Fix Semantic Error", `import { A } from "../shared/types/db"; +const a: string = "hello";`), + noChange, + ], + baselineIncremental: true + }); + }); +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuild/watchMode.ts b/src/testRunner/unittests/tsbuildWatch/programUpdates.ts similarity index 71% rename from src/testRunner/unittests/tsbuild/watchMode.ts rename to src/testRunner/unittests/tsbuildWatch/programUpdates.ts index 65880a0c69c..011bebf2e66 100644 --- a/src/testRunner/unittests/tsbuild/watchMode.ts +++ b/src/testRunner/unittests/tsbuildWatch/programUpdates.ts @@ -1,21 +1,19 @@ namespace ts.tscWatch { import projectsLocation = TestFSWithWatch.tsbuildProjectsLocation; - import getFilePathInProject = TestFSWithWatch.getTsBuildProjectFilePath; - import getFileFromProject = TestFSWithWatch.getTsBuildProjectFile; - type TsBuildWatchSystem = TestFSWithWatch.TestServerHostTrackingWrittenFiles; + describe("unittests:: tsbuildWatch:: watchMode:: program updates", () => { + type TsBuildWatchSystem = TestFSWithWatch.TestServerHostTrackingWrittenFiles; - function createTsBuildWatchSystem(fileOrFolderList: readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) { - return TestFSWithWatch.changeToHostTrackingWrittenFiles( - createWatchedSystem(fileOrFolderList, params) - ); - } + function createTsBuildWatchSystem(fileOrFolderList: readonly TestFSWithWatch.FileOrFolderOrSymLink[], params?: TestFSWithWatch.TestServerHostCreationParameters) { + return TestFSWithWatch.changeToHostTrackingWrittenFiles( + createWatchedSystem(fileOrFolderList, params) + ); + } - type OutputFileStamp = [string, Date | undefined, boolean]; - function transformOutputToOutputFileStamp(f: string, host: TsBuildWatchSystem): OutputFileStamp { - return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp; - } + type OutputFileStamp = [string, Date | undefined, boolean]; + function transformOutputToOutputFileStamp(f: string, host: TsBuildWatchSystem): OutputFileStamp { + return [f, host.getModifiedTime(f), host.writtenFiles.has(host.toFullPath(f))] as OutputFileStamp; + } - describe("unittests:: tsbuild:: watchMode:: program updates", () => { const scenario = "programUpdates"; const project = "sample1"; const enum SubProject { @@ -28,7 +26,7 @@ namespace ts.tscWatch { /** [tsconfig, index] | [tsconfig, index, anotherModule, someDecl] */ type SubProjectFiles = [ReadonlyFile, ReadonlyFile] | [ReadonlyFile, ReadonlyFile, ReadonlyFile, ReadonlyFile]; function projectPath(subProject: SubProject) { - return getFilePathInProject(project, subProject); + return TestFSWithWatch.getTsBuildProjectFilePath(project, subProject); } function projectFilePath(subProject: SubProject, baseFileName: string) { @@ -36,7 +34,7 @@ namespace ts.tscWatch { } function projectFile(subProject: SubProject, baseFileName: string): File { - return getFileFromProject(project, `${subProject}/${baseFileName}`); + return TestFSWithWatch.getTsBuildProjectFile(project, `${subProject}/${baseFileName}`); } function subProjectFiles(subProject: SubProject, anotherModuleAndSomeDecl?: true): SubProjectFiles { @@ -789,290 +787,4 @@ export function someFn() { }`), ] }); }); - - describe("unittests:: tsbuild:: watchMode:: with demo project", () => { - const projectLocation = `${projectsLocation}/demo`; - let coreFiles: File[]; - let animalFiles: File[]; - let zooFiles: File[]; - let solutionFile: File; - let baseConfig: File; - let allFiles: File[]; - before(() => { - coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]); - animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]); - zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]); - solutionFile = projectFile("tsconfig.json"); - baseConfig = projectFile("tsconfig-base.json"); - allFiles = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile, baseConfig, { path: libFile.path, content: libContent }]; - }); - - after(() => { - coreFiles = undefined!; - animalFiles = undefined!; - zooFiles = undefined!; - solutionFile = undefined!; - baseConfig = undefined!; - allFiles = undefined!; - }); - - verifyTscWatch({ - scenario: "demo", - subScenario: "updates with circular reference", - commandLineArgs: ["-b", "-w", "-verbose"], - sys: () => { - const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); - sys.writeFile(coreFiles[0].path, coreFiles[0].content.replace( - "}", - `}, - "references": [ - { - "path": "../zoo" - } - ]` - )); - return sys; - }, - changes: [ - { - caption: "Fix error", - change: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content), - timeouts: sys => { - sys.checkTimeoutQueueLengthAndRun(1); // build core - sys.checkTimeoutQueueLengthAndRun(1); // build animals - sys.checkTimeoutQueueLengthAndRun(1); // build zoo - sys.checkTimeoutQueueLengthAndRun(1); // build solution - sys.checkTimeoutQueueLength(0); - }, - } - ] - }); - - verifyTscWatch({ - scenario: "demo", - subScenario: "updates with bad reference", - commandLineArgs: ["-b", "-w", "-verbose"], - sys: () => { - const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation }); - sys.writeFile(coreFiles[1].path, `import * as A from '../animals'; -${coreFiles[1].content}`); - return sys; - }, - changes: [ - { - caption: "Prepend a line", - change: sys => sys.writeFile(coreFiles[1].path, ` -import * as A from '../animals'; -${coreFiles[1].content}`), - // build core - timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, - } - ] - }); - - function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] { - return fileNames.map(file => projectFile(`${subProject}/${file}`)); - } - - function projectFile(fileName: string): File { - return getFileFromProject("demo", fileName); - } - }); - - describe("unittests:: tsbuild:: watchMode:: with noEmitOnError", () => { - function change(caption: string, content: string): TscWatchCompileChange { - return { - caption, - change: sys => sys.writeFile(`${projectsLocation}/noEmitOnError/src/main.ts`, content), - // build project - timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, - }; - } - - const noChange: TscWatchCompileChange = { - caption: "No change", - change: sys => sys.writeFile(`${projectsLocation}/noEmitOnError/src/main.ts`, sys.readFile(`${projectsLocation}/noEmitOnError/src/main.ts`)!), - // build project - timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout, - }; - verifyTscWatch({ - scenario: "noEmitOnError", - subScenario: "does not emit any files on error", - commandLineArgs: ["-b", "-w", "-verbose"], - sys: () => createWatchedSystem( - [ - ...["tsconfig.json", "shared/types/db.ts", "src/main.ts", "src/other.ts"] - .map(f => getFileFromProject("noEmitOnError", f)), - { path: libFile.path, content: libContent } - ], - { currentDirectory: `${projectsLocation}/noEmitOnError` } - ), - changes: [ - noChange, - change("Fix Syntax error", `import { A } from "../shared/types/db"; -const a = { - lastName: 'sdsd' -};`), - change("Semantic Error", `import { A } from "../shared/types/db"; -const a: string = 10;`), - noChange, - change("Fix Semantic Error", `import { A } from "../shared/types/db"; -const a: string = "hello";`), - noChange, - ], - baselineIncremental: true - }); - }); - - describe("unittests:: tsbuild:: watchMode:: with reexport when referenced project reexports definitions from another file", () => { - function build(sys: WatchedSystem) { - sys.checkTimeoutQueueLengthAndRun(1); // build src/pure - sys.checkTimeoutQueueLengthAndRun(1); // build src/main - sys.checkTimeoutQueueLengthAndRun(1); // build src - sys.checkTimeoutQueueLength(0); - } - verifyTscWatch({ - scenario: "reexport", - subScenario: "Reports errors correctly", - commandLineArgs: ["-b", "-w", "-verbose", "src"], - sys: () => createWatchedSystem( - [ - ...[ - "src/tsconfig.json", - "src/main/tsconfig.json", "src/main/index.ts", - "src/pure/tsconfig.json", "src/pure/index.ts", "src/pure/session.ts" - ] - .map(f => getFileFromProject("reexport", f)), - { path: libFile.path, content: libContent } - ], - { currentDirectory: `${projectsLocation}/reexport` } - ), - changes: [ - { - caption: "Introduce error", - change: sys => replaceFileText(sys, `${projectsLocation}/reexport/src/pure/session.ts`, "// ", ""), - timeouts: build, - }, - { - caption: "Fix error", - change: sys => replaceFileText(sys, `${projectsLocation}/reexport/src/pure/session.ts`, "bar: ", "// bar: "), - timeouts: build - } - ] - }); - }); - - describe("unittests:: tsbuild:: watchMode:: configFileErrors:: reports syntax errors in config file", () => { - function build(sys: WatchedSystem) { - sys.checkTimeoutQueueLengthAndRun(1); // build the project - sys.checkTimeoutQueueLength(0); - } - verifyTscWatch({ - scenario: "configFileErrors", - subScenario: "reports syntax errors in config file", - sys: () => createWatchedSystem( - [ - { path: `${projectRoot}/a.ts`, content: "export function foo() { }" }, - { path: `${projectRoot}/b.ts`, content: "export function bar() { }" }, - { - path: `${projectRoot}/tsconfig.json`, - content: Utils.dedent` -{ - "compilerOptions": { - "composite": true, - }, - "files": [ - "a.ts" - "b.ts" - ] -}` - }, - libFile - ], - { currentDirectory: projectRoot } - ), - commandLineArgs: ["--b", "-w"], - changes: [ - { - caption: "reports syntax errors after change to config file", - change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, ",", `, - "declaration": true,`), - timeouts: build, - }, - { - caption: "reports syntax errors after change to ts file", - change: sys => replaceFileText(sys, `${projectRoot}/a.ts`, "foo", "fooBar"), - timeouts: build, - }, - { - caption: "reports error when there is no change to tsconfig file", - change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, "", ""), - timeouts: build, - }, - { - caption: "builds after fixing config file errors", - change: sys => sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({ - compilerOptions: { composite: true, declaration: true }, - files: ["a.ts", "b.ts"] - })), - timeouts: build, - } - ] - }); - }); - - describe("unittests:: tsbuild:: watchMode:: module resolution different in referenced project", () => { - verifyTscWatch({ - scenario: "moduleResolutionCache", - subScenario: "handles the cache correctly when two projects use different module resolution settings", - sys: () => createWatchedSystem( - [ - { path: `${projectRoot}/project1/index.ts`, content: `import { foo } from "file";` }, - { path: `${projectRoot}/project1/node_modules/file/index.d.ts`, content: "export const foo = 10;" }, - { - path: `${projectRoot}/project1/tsconfig.json`, - content: JSON.stringify({ - compilerOptions: { composite: true, types: ["foo", "bar"] }, - files: ["index.ts"] - }) - }, - { path: `${projectRoot}/project2/index.ts`, content: `import { foo } from "file";` }, - { path: `${projectRoot}/project2/file.d.ts`, content: "export const foo = 10;" }, - { - path: `${projectRoot}/project2/tsconfig.json`, - content: JSON.stringify({ - compilerOptions: { composite: true, types: ["foo"], moduleResolution: "classic" }, - files: ["index.ts"] - }) - }, - { path: `${projectRoot}/node_modules/@types/foo/index.d.ts`, content: "export const foo = 10;" }, - { path: `${projectRoot}/node_modules/@types/bar/index.d.ts`, content: "export const bar = 10;" }, - { - path: `${projectRoot}/tsconfig.json`, - content: JSON.stringify({ - files: [], - references: [ - { path: "./project1" }, - { path: "./project2" } - ] - }) - }, - libFile - ], - { currentDirectory: projectRoot } - ), - commandLineArgs: ["--b", "-w", "-v"], - changes: [ - { - caption: "Append text", - change: sys => sys.appendFile(`${projectRoot}/project1/index.ts`, "const bar = 10;"), - timeouts: sys => { - sys.checkTimeoutQueueLengthAndRun(1); // build project1 - sys.checkTimeoutQueueLengthAndRun(1); // Solution - sys.checkTimeoutQueueLength(0); - } - }, - ] - }); - }); -} +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuildWatch/reexport.ts b/src/testRunner/unittests/tsbuildWatch/reexport.ts new file mode 100644 index 00000000000..d105bd0fcf0 --- /dev/null +++ b/src/testRunner/unittests/tsbuildWatch/reexport.ts @@ -0,0 +1,39 @@ +namespace ts.tscWatch { + describe("unittests:: tsbuildWatch:: watchMode:: with reexport when referenced project reexports definitions from another file", () => { + function build(sys: WatchedSystem) { + sys.checkTimeoutQueueLengthAndRun(1); // build src/pure + sys.checkTimeoutQueueLengthAndRun(1); // build src/main + sys.checkTimeoutQueueLengthAndRun(1); // build src + sys.checkTimeoutQueueLength(0); + } + verifyTscWatch({ + scenario: "reexport", + subScenario: "Reports errors correctly", + commandLineArgs: ["-b", "-w", "-verbose", "src"], + sys: () => createWatchedSystem( + [ + ...[ + "src/tsconfig.json", + "src/main/tsconfig.json", "src/main/index.ts", + "src/pure/tsconfig.json", "src/pure/index.ts", "src/pure/session.ts" + ] + .map(f => TestFSWithWatch.getTsBuildProjectFile("reexport", f)), + { path: libFile.path, content: libContent } + ], + { currentDirectory: `${TestFSWithWatch.tsbuildProjectsLocation}/reexport` } + ), + changes: [ + { + caption: "Introduce error", + change: sys => replaceFileText(sys, `${TestFSWithWatch.tsbuildProjectsLocation}/reexport/src/pure/session.ts`, "// ", ""), + timeouts: build, + }, + { + caption: "Fix error", + change: sys => replaceFileText(sys, `${TestFSWithWatch.tsbuildProjectsLocation}/reexport/src/pure/session.ts`, "bar: ", "// bar: "), + timeouts: build + } + ] + }); + }); +} \ No newline at end of file diff --git a/src/testRunner/unittests/tsbuild/watchEnvironment.ts b/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts similarity index 96% rename from src/testRunner/unittests/tsbuild/watchEnvironment.ts rename to src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts index 4253edfe475..599b5790f85 100644 --- a/src/testRunner/unittests/tsbuild/watchEnvironment.ts +++ b/src/testRunner/unittests/tsbuildWatch/watchEnvironment.ts @@ -1,5 +1,5 @@ namespace ts.tscWatch { - describe("unittests:: tsbuild:: watchEnvironment:: tsbuild:: watchMode:: with different watch environments", () => { + describe("unittests:: tsbuildWatch:: watchEnvironment:: tsbuild:: watchMode:: with different watch environments", () => { describe("when watchFile can create multiple watchers per file", () => { verifyWatchFileOnMultipleProjects(/*singleWatchPerFile*/ false); });