Skip to content

Commit 933df64

Browse files
committed
Some more tests
1 parent 9580bcf commit 933df64

24 files changed

+75980
-5117
lines changed

src/testRunner/unittests/tsbuild/persistResolutions.ts

+29-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ namespace ts {
55
"/src/project/src/main.ts": Utils.dedent`
66
import { something } from "./filePresent";
77
import { something as something1 } from "./filePresent";
8-
import { something2 } from "./fileNotFound";`,
8+
import { something2 } from "./fileNotFound";
9+
import { externalThing1 } from "externalThing";
10+
import { externalThing2 } from "externalThingNotPresent";`,
911
"/src/project/src/anotherFileReusingResolution.ts": Utils.dedent`
1012
import { something } from "./filePresent";
11-
import { something2 } from "./fileNotFound";`,
13+
import { something2 } from "./fileNotFound";
14+
import { externalThing1 } from "externalThing";
15+
import { externalThing2 } from "externalThingNotPresent";`,
1216
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
1317
"/src/project/src/fileWithRef.ts": `/// <reference path="./types.ts"/>`,
1418
"/src/project/src/types.ts": `interface SomeType {}`,
@@ -23,6 +27,7 @@ namespace ts {
2327
function globalAnotherFileWithSameReferenes() { }
2428
`,
2529
"/src/project/src/globalFilePresent.ts": `function globalSomething() { return 10; }`,
30+
"/src/project/src/externalThing.d.ts": `export function externalThing1(): number;`,
2631
"/src/project/tsconfig.json": JSON.stringify({
2732
compilerOptions: {
2833
module: "amd",
@@ -119,7 +124,17 @@ namespace ts {
119124
{
120125
subScenario: "Delete file that could not be resolved",
121126
buildKind: BuildKind.IncrementalDtsChange,
122-
modifyFs: sys => sys.unlinkSync(`/src/project/src/fileNotFound.ts`),
127+
modifyFs: fs => fs.unlinkSync(`/src/project/src/fileNotFound.ts`),
128+
},
129+
{
130+
subScenario: "Create external module file that could not be resolved",
131+
buildKind: BuildKind.IncrementalDtsChange,
132+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
133+
},
134+
{
135+
subScenario: "Write .ts file that takes preference over resolved .d.ts file",
136+
buildKind: BuildKind.IncrementalDtsChange,
137+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
123138
},
124139
],
125140
baselinePrograms: true,
@@ -209,7 +224,17 @@ namespace ts {
209224
{
210225
subScenario: "Delete file that could not be resolved",
211226
buildKind: BuildKind.IncrementalDtsChange,
212-
modifyFs: sys => sys.unlinkSync(`/src/project/src/fileNotFound.ts`),
227+
modifyFs: fs => fs.unlinkSync(`/src/project/src/fileNotFound.ts`),
228+
},
229+
{
230+
subScenario: "Create external module file that could not be resolved",
231+
buildKind: BuildKind.IncrementalDtsChange,
232+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
233+
},
234+
{
235+
subScenario: "Write .ts file that takes preference over resolved .d.ts file",
236+
buildKind: BuildKind.IncrementalDtsChange,
237+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
213238
},
214239
],
215240
baselinePrograms: true,

src/testRunner/unittests/tsbuild/watchMode.ts

+106-2
Original file line numberDiff line numberDiff line change
@@ -1084,13 +1084,17 @@ const a: string = "hello";`),
10841084
content: Utils.dedent`
10851085
import { something } from "./filePresent";
10861086
import { something as something1 } from "./filePresent";
1087-
import { something2 } from "./fileNotFound";`,
1087+
import { something2 } from "./fileNotFound";
1088+
import { externalThing1 } from "externalThing";
1089+
import { externalThing2 } from "externalThingNotPresent";`,
10881090
},
10891091
{
10901092
path: `${projectRoot}/src/anotherFileReusingResolution.ts`,
10911093
content: Utils.dedent`
10921094
import { something } from "./filePresent";
1093-
import { something2 } from "./fileNotFound";`,
1095+
import { something2 } from "./fileNotFound";
1096+
import { externalThing1 } from "externalThing";
1097+
import { externalThing2 } from "externalThingNotPresent";`,
10941098
},
10951099
{
10961100
path: `${projectRoot}/src/filePresent.ts`,
@@ -1124,6 +1128,10 @@ const a: string = "hello";`),
11241128
path: `${projectRoot}/src/globalFilePresent.ts`,
11251129
content: `function globalSomething() { return 10; }`,
11261130
},
1131+
{
1132+
path: `${projectRoot}/src/externalThing.d.ts`,
1133+
content: `export function externalThing1(): number;`,
1134+
},
11271135
{
11281136
path: `${projectRoot}/tsconfig.json`,
11291137
content: JSON.stringify({
@@ -1219,6 +1227,22 @@ const a: string = "hello";`),
12191227
sys.runQueuedTimeoutCallbacks(); // Actual update
12201228
}
12211229
},
1230+
{
1231+
caption: "Create external module file that could not be resolved",
1232+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1233+
timeouts: sys => {
1234+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1235+
sys.runQueuedTimeoutCallbacks(); // Actual update
1236+
}
1237+
},
1238+
{
1239+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1240+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1241+
timeouts: sys => {
1242+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1243+
sys.runQueuedTimeoutCallbacks(); // Actual update
1244+
}
1245+
},
12221246
]
12231247
});
12241248
verifyTscWatch({
@@ -1276,6 +1300,22 @@ const a: string = "hello";`),
12761300
sys.runQueuedTimeoutCallbacks(); // Actual update
12771301
}
12781302
},
1303+
{
1304+
caption: "Create external module file that could not be resolved",
1305+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1306+
timeouts: sys => {
1307+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1308+
sys.runQueuedTimeoutCallbacks(); // Actual update
1309+
}
1310+
},
1311+
{
1312+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1313+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1314+
timeouts: sys => {
1315+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1316+
sys.runQueuedTimeoutCallbacks(); // Actual update
1317+
}
1318+
},
12791319
]
12801320
});
12811321
verifyTscWatch({
@@ -1333,6 +1373,22 @@ const a: string = "hello";`),
13331373
sys.runQueuedTimeoutCallbacks(); // Actual update
13341374
}
13351375
},
1376+
{
1377+
caption: "Create external module file that could not be resolved",
1378+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1379+
timeouts: sys => {
1380+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1381+
sys.runQueuedTimeoutCallbacks(); // Actual update
1382+
}
1383+
},
1384+
{
1385+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1386+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1387+
timeouts: sys => {
1388+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1389+
sys.runQueuedTimeoutCallbacks(); // Actual update
1390+
}
1391+
},
13361392
]
13371393
});
13381394

@@ -1391,6 +1447,22 @@ const a: string = "hello";`),
13911447
sys.runQueuedTimeoutCallbacks(); // Actual update
13921448
}
13931449
},
1450+
{
1451+
caption: "Create external module file that could not be resolved",
1452+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1453+
timeouts: sys => {
1454+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1455+
sys.runQueuedTimeoutCallbacks(); // Actual update
1456+
}
1457+
},
1458+
{
1459+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1460+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1461+
timeouts: sys => {
1462+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1463+
sys.runQueuedTimeoutCallbacks(); // Actual update
1464+
}
1465+
},
13941466
]
13951467
});
13961468
verifyTscWatch({
@@ -1448,6 +1520,22 @@ const a: string = "hello";`),
14481520
sys.runQueuedTimeoutCallbacks(); // Actual update
14491521
}
14501522
},
1523+
{
1524+
caption: "Create external module file that could not be resolved",
1525+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1526+
timeouts: sys => {
1527+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1528+
sys.runQueuedTimeoutCallbacks(); // Actual update
1529+
}
1530+
},
1531+
{
1532+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1533+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1534+
timeouts: sys => {
1535+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1536+
sys.runQueuedTimeoutCallbacks(); // Actual update
1537+
}
1538+
},
14511539
]
14521540
});
14531541
verifyTscWatch({
@@ -1505,6 +1593,22 @@ const a: string = "hello";`),
15051593
sys.runQueuedTimeoutCallbacks(); // Actual update
15061594
}
15071595
},
1596+
{
1597+
caption: "Create external module file that could not be resolved",
1598+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
1599+
timeouts: sys => {
1600+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1601+
sys.runQueuedTimeoutCallbacks(); // Actual update
1602+
}
1603+
},
1604+
{
1605+
caption: "Write .ts file that takes preference over resolved .d.ts file",
1606+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
1607+
timeouts: sys => {
1608+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
1609+
sys.runQueuedTimeoutCallbacks(); // Actual update
1610+
}
1611+
},
15081612
]
15091613
});
15101614
});

src/testRunner/unittests/tsc/persistResolutions.ts

+38-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ namespace ts {
55
"/src/project/src/main.ts": Utils.dedent`
66
import { something } from "./filePresent";
77
import { something as something1 } from "./filePresent";
8-
import { something2 } from "./fileNotFound";`,
8+
import { something2 } from "./fileNotFound";
9+
import { externalThing1 } from "externalThing";
10+
import { externalThing2 } from "externalThingNotPresent";`,
911
"/src/project/src/anotherFileReusingResolution.ts": Utils.dedent`
1012
import { something } from "./filePresent";
11-
import { something2 } from "./fileNotFound";`,
13+
import { something2 } from "./fileNotFound";
14+
import { externalThing1 } from "externalThing";
15+
import { externalThing2 } from "externalThingNotPresent";`,
1216
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
1317
"/src/project/src/fileWithRef.ts": `/// <reference path="./types.ts"/>`,
1418
"/src/project/src/types.ts": `interface SomeType {}`,
@@ -23,6 +27,7 @@ namespace ts {
2327
function globalAnotherFileWithSameReferenes() { }
2428
`,
2529
"/src/project/src/globalFilePresent.ts": `function globalSomething() { return 10; }`,
30+
"/src/project/src/externalThing.d.ts": `export function externalThing1(): number;`,
2631
"/src/project/tsconfig.json": JSON.stringify({
2732
compilerOptions: {
2833
module: "amd",
@@ -119,7 +124,21 @@ namespace ts {
119124
{
120125
subScenario: "Delete file that could not be resolved",
121126
buildKind: BuildKind.IncrementalDtsChange,
122-
modifyFs: sys => sys.unlinkSync(`/src/project/src/fileNotFound.ts`),
127+
modifyFs: fs => fs.unlinkSync(`/src/project/src/fileNotFound.ts`),
128+
},
129+
{
130+
subScenario: "Create external module file that could not be resolved",
131+
buildKind: BuildKind.IncrementalDtsChange,
132+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
133+
},
134+
{
135+
subScenario: "Write .ts file that takes preference over resolved .d.ts file",
136+
buildKind: BuildKind.IncrementalDtsChange,
137+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
138+
cleanBuildDiscrepancies: () => new Map([
139+
// In the clean build since .d.ts is not picked up, it can be overwritten with d.ts output from .ts file
140+
["/src/project/src/externalthing.d.ts", CleanBuildDescrepancy.CleanFileTextDifferent],
141+
])
123142
},
124143
],
125144
baselinePrograms: true,
@@ -209,7 +228,22 @@ namespace ts {
209228
{
210229
subScenario: "Delete file that could not be resolved",
211230
buildKind: BuildKind.IncrementalDtsChange,
212-
modifyFs: sys => sys.unlinkSync(`/src/project/src/fileNotFound.ts`),
231+
modifyFs: fs => fs.unlinkSync(`/src/project/src/fileNotFound.ts`),
232+
},
233+
{
234+
subScenario: "Create external module file that could not be resolved",
235+
buildKind: BuildKind.IncrementalDtsChange,
236+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
237+
},
238+
{
239+
subScenario: "Write .ts file that takes preference over resolved .d.ts file",
240+
buildKind: BuildKind.IncrementalDtsChange,
241+
modifyFs: fs => fs.writeFileSync(`/src/project/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
242+
cleanBuildDiscrepancies: () => new Map([
243+
// In the clean build since .d.ts is not picked up, the output of externalThing.ts would be before the main file because of import
244+
["/src/project/outfile.js", CleanBuildDescrepancy.CleanFileTextDifferent],
245+
["/src/project/outfile.d.ts", CleanBuildDescrepancy.CleanFileTextDifferent],
246+
])
213247
},
214248
],
215249
baselinePrograms: true,

0 commit comments

Comments
 (0)