Skip to content

Commit b383653

Browse files
committed
Refactor
1 parent abe3b73 commit b383653

File tree

10 files changed

+1630
-1618
lines changed

10 files changed

+1630
-1618
lines changed

src/testRunner/tsconfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@
136136
"unittests/tsbuild/resolveJsonModule.ts",
137137
"unittests/tsbuild/sample.ts",
138138
"unittests/tsbuild/transitiveReferences.ts",
139-
"unittests/tsbuild/watchEnvironment.ts",
140-
"unittests/tsbuild/watchMode.ts",
139+
"unittests/tsbuildWatch/configFileErrors.ts",
140+
"unittests/tsbuildWatch/demo.ts",
141+
"unittests/tsbuildWatch/moduleResolution.ts",
142+
"unittests/tsbuildWatch/noEmitOnError.ts",
143+
"unittests/tsbuildWatch/persistResolutions.ts",
144+
"unittests/tsbuildWatch/programUpdates.ts",
145+
"unittests/tsbuildWatch/reexport.ts",
146+
"unittests/tsbuildWatch/watchEnvironment.ts",
141147
"unittests/tsc/composite.ts",
142148
"unittests/tsc/declarationEmit.ts",
143149
"unittests/tsc/incremental.ts",

src/testRunner/unittests/tsbuild/watchMode.ts

Lines changed: 0 additions & 1615 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsbuildWatch:: watchMode:: configFileErrors:: reports syntax errors in config file", () => {
3+
function build(sys: WatchedSystem) {
4+
sys.checkTimeoutQueueLengthAndRun(1); // build the project
5+
sys.checkTimeoutQueueLength(0);
6+
}
7+
verifyTscWatch({
8+
scenario: "configFileErrors",
9+
subScenario: "reports syntax errors in config file",
10+
sys: () => createWatchedSystem(
11+
[
12+
{ path: `${projectRoot}/a.ts`, content: "export function foo() { }" },
13+
{ path: `${projectRoot}/b.ts`, content: "export function bar() { }" },
14+
{
15+
path: `${projectRoot}/tsconfig.json`,
16+
content: Utils.dedent`
17+
{
18+
"compilerOptions": {
19+
"composite": true,
20+
},
21+
"files": [
22+
"a.ts"
23+
"b.ts"
24+
]
25+
}`
26+
},
27+
libFile
28+
],
29+
{ currentDirectory: projectRoot }
30+
),
31+
commandLineArgs: ["--b", "-w"],
32+
changes: [
33+
{
34+
caption: "reports syntax errors after change to config file",
35+
change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, ",", `,
36+
"declaration": true,`),
37+
timeouts: build,
38+
},
39+
{
40+
caption: "reports syntax errors after change to ts file",
41+
change: sys => replaceFileText(sys, `${projectRoot}/a.ts`, "foo", "fooBar"),
42+
timeouts: build,
43+
},
44+
{
45+
caption: "reports error when there is no change to tsconfig file",
46+
change: sys => replaceFileText(sys, `${projectRoot}/tsconfig.json`, "", ""),
47+
timeouts: build,
48+
},
49+
{
50+
caption: "builds after fixing config file errors",
51+
change: sys => sys.writeFile(`${projectRoot}/tsconfig.json`, JSON.stringify({
52+
compilerOptions: { composite: true, declaration: true },
53+
files: ["a.ts", "b.ts"]
54+
})),
55+
timeouts: build,
56+
}
57+
]
58+
});
59+
});
60+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsbuildWatch:: watchMode:: with demo project", () => {
3+
const projectLocation = `${TestFSWithWatch.tsbuildProjectsLocation}/demo`;
4+
let coreFiles: File[];
5+
let animalFiles: File[];
6+
let zooFiles: File[];
7+
let solutionFile: File;
8+
let baseConfig: File;
9+
let allFiles: File[];
10+
before(() => {
11+
coreFiles = subProjectFiles("core", ["tsconfig.json", "utilities.ts"]);
12+
animalFiles = subProjectFiles("animals", ["tsconfig.json", "animal.ts", "dog.ts", "index.ts"]);
13+
zooFiles = subProjectFiles("zoo", ["tsconfig.json", "zoo.ts"]);
14+
solutionFile = projectFile("tsconfig.json");
15+
baseConfig = projectFile("tsconfig-base.json");
16+
allFiles = [...coreFiles, ...animalFiles, ...zooFiles, solutionFile, baseConfig, { path: libFile.path, content: libContent }];
17+
});
18+
19+
after(() => {
20+
coreFiles = undefined!;
21+
animalFiles = undefined!;
22+
zooFiles = undefined!;
23+
solutionFile = undefined!;
24+
baseConfig = undefined!;
25+
allFiles = undefined!;
26+
});
27+
28+
verifyTscWatch({
29+
scenario: "demo",
30+
subScenario: "updates with circular reference",
31+
commandLineArgs: ["-b", "-w", "-verbose"],
32+
sys: () => {
33+
const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation });
34+
sys.writeFile(coreFiles[0].path, coreFiles[0].content.replace(
35+
"}",
36+
`},
37+
"references": [
38+
{
39+
"path": "../zoo"
40+
}
41+
]`
42+
));
43+
return sys;
44+
},
45+
changes: [
46+
{
47+
caption: "Fix error",
48+
change: sys => sys.writeFile(coreFiles[0].path, coreFiles[0].content),
49+
timeouts: sys => {
50+
sys.checkTimeoutQueueLengthAndRun(1); // build core
51+
sys.checkTimeoutQueueLengthAndRun(1); // build animals
52+
sys.checkTimeoutQueueLengthAndRun(1); // build zoo
53+
sys.checkTimeoutQueueLengthAndRun(1); // build solution
54+
sys.checkTimeoutQueueLength(0);
55+
},
56+
}
57+
]
58+
});
59+
60+
verifyTscWatch({
61+
scenario: "demo",
62+
subScenario: "updates with bad reference",
63+
commandLineArgs: ["-b", "-w", "-verbose"],
64+
sys: () => {
65+
const sys = createWatchedSystem(allFiles, { currentDirectory: projectLocation });
66+
sys.writeFile(coreFiles[1].path, `import * as A from '../animals';
67+
${coreFiles[1].content}`);
68+
return sys;
69+
},
70+
changes: [
71+
{
72+
caption: "Prepend a line",
73+
change: sys => sys.writeFile(coreFiles[1].path, `
74+
import * as A from '../animals';
75+
${coreFiles[1].content}`),
76+
// build core
77+
timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout,
78+
}
79+
]
80+
});
81+
82+
function subProjectFiles(subProject: string, fileNames: readonly string[]): File[] {
83+
return fileNames.map(file => projectFile(`${subProject}/${file}`));
84+
}
85+
86+
function projectFile(fileName: string): File {
87+
return TestFSWithWatch.getTsBuildProjectFile("demo", fileName);
88+
}
89+
});
90+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsbuildWatch:: watchMode:: module resolution different in referenced project", () => {
3+
verifyTscWatch({
4+
scenario: "moduleResolutionCache",
5+
subScenario: "handles the cache correctly when two projects use different module resolution settings",
6+
sys: () => createWatchedSystem(
7+
[
8+
{ path: `${projectRoot}/project1/index.ts`, content: `import { foo } from "file";` },
9+
{ path: `${projectRoot}/project1/node_modules/file/index.d.ts`, content: "export const foo = 10;" },
10+
{
11+
path: `${projectRoot}/project1/tsconfig.json`,
12+
content: JSON.stringify({
13+
compilerOptions: { composite: true, types: ["foo", "bar"] },
14+
files: ["index.ts"]
15+
})
16+
},
17+
{ path: `${projectRoot}/project2/index.ts`, content: `import { foo } from "file";` },
18+
{ path: `${projectRoot}/project2/file.d.ts`, content: "export const foo = 10;" },
19+
{
20+
path: `${projectRoot}/project2/tsconfig.json`,
21+
content: JSON.stringify({
22+
compilerOptions: { composite: true, types: ["foo"], moduleResolution: "classic" },
23+
files: ["index.ts"]
24+
})
25+
},
26+
{ path: `${projectRoot}/node_modules/@types/foo/index.d.ts`, content: "export const foo = 10;" },
27+
{ path: `${projectRoot}/node_modules/@types/bar/index.d.ts`, content: "export const bar = 10;" },
28+
{
29+
path: `${projectRoot}/tsconfig.json`,
30+
content: JSON.stringify({
31+
files: [],
32+
references: [
33+
{ path: "./project1" },
34+
{ path: "./project2" }
35+
]
36+
})
37+
},
38+
libFile
39+
],
40+
{ currentDirectory: projectRoot }
41+
),
42+
commandLineArgs: ["--b", "-w", "-v"],
43+
changes: [
44+
{
45+
caption: "Append text",
46+
change: sys => sys.appendFile(`${projectRoot}/project1/index.ts`, "const bar = 10;"),
47+
timeouts: sys => {
48+
sys.checkTimeoutQueueLengthAndRun(1); // build project1
49+
sys.checkTimeoutQueueLengthAndRun(1); // Solution
50+
sys.checkTimeoutQueueLength(0);
51+
}
52+
},
53+
]
54+
});
55+
});
56+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
namespace ts.tscWatch {
2+
describe("unittests:: tsbuildWatch:: watchMode:: with noEmitOnError", () => {
3+
function change(caption: string, content: string): TscWatchCompileChange {
4+
return {
5+
caption,
6+
change: sys => sys.writeFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`, content),
7+
// build project
8+
timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout,
9+
};
10+
}
11+
12+
const noChange: TscWatchCompileChange = {
13+
caption: "No change",
14+
change: sys => sys.writeFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`, sys.readFile(`${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError/src/main.ts`)!),
15+
// build project
16+
timeouts: checkSingleTimeoutQueueLengthAndRunAndVerifyNoTimeout,
17+
};
18+
verifyTscWatch({
19+
scenario: "noEmitOnError",
20+
subScenario: "does not emit any files on error",
21+
commandLineArgs: ["-b", "-w", "-verbose"],
22+
sys: () => createWatchedSystem(
23+
[
24+
...["tsconfig.json", "shared/types/db.ts", "src/main.ts", "src/other.ts"]
25+
.map(f => TestFSWithWatch.getTsBuildProjectFile("noEmitOnError", f)),
26+
{ path: libFile.path, content: libContent }
27+
],
28+
{ currentDirectory: `${TestFSWithWatch.tsbuildProjectsLocation}/noEmitOnError` }
29+
),
30+
changes: [
31+
noChange,
32+
change("Fix Syntax error", `import { A } from "../shared/types/db";
33+
const a = {
34+
lastName: 'sdsd'
35+
};`),
36+
change("Semantic Error", `import { A } from "../shared/types/db";
37+
const a: string = 10;`),
38+
noChange,
39+
change("Fix Semantic Error", `import { A } from "../shared/types/db";
40+
const a: string = "hello";`),
41+
noChange,
42+
],
43+
baselineIncremental: true
44+
});
45+
});
46+
}

0 commit comments

Comments
 (0)