Skip to content

Commit 688b635

Browse files
committed
Some more tests
1 parent 841b9ae commit 688b635

File tree

24 files changed

+75980
-5117
lines changed

24 files changed

+75980
-5117
lines changed

src/testRunner/unittests/tsbuild/persistResolutions.ts

Lines changed: 29 additions & 4 deletions
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/tsbuildWatch/persistResolutions.ts

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ namespace ts.tscWatch {
77
content: Utils.dedent`
88
import { something } from "./filePresent";
99
import { something as something1 } from "./filePresent";
10-
import { something2 } from "./fileNotFound";`,
10+
import { something2 } from "./fileNotFound";
11+
import { externalThing1 } from "externalThing";
12+
import { externalThing2 } from "externalThingNotPresent";`,
1113
},
1214
{
1315
path: `${projectRoot}/src/anotherFileReusingResolution.ts`,
1416
content: Utils.dedent`
1517
import { something } from "./filePresent";
16-
import { something2 } from "./fileNotFound";`,
18+
import { something2 } from "./fileNotFound";
19+
import { externalThing1 } from "externalThing";
20+
import { externalThing2 } from "externalThingNotPresent";`,
1721
},
1822
{
1923
path: `${projectRoot}/src/filePresent.ts`,
@@ -47,6 +51,10 @@ namespace ts.tscWatch {
4751
path: `${projectRoot}/src/globalFilePresent.ts`,
4852
content: `function globalSomething() { return 10; }`,
4953
},
54+
{
55+
path: `${projectRoot}/src/externalThing.d.ts`,
56+
content: `export function externalThing1(): number;`,
57+
},
5058
{
5159
path: `${projectRoot}/tsconfig.json`,
5260
content: JSON.stringify({
@@ -142,6 +150,22 @@ namespace ts.tscWatch {
142150
sys.runQueuedTimeoutCallbacks(); // Actual update
143151
}
144152
},
153+
{
154+
caption: "Create external module file that could not be resolved",
155+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
156+
timeouts: sys => {
157+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
158+
sys.runQueuedTimeoutCallbacks(); // Actual update
159+
}
160+
},
161+
{
162+
caption: "Write .ts file that takes preference over resolved .d.ts file",
163+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
164+
timeouts: sys => {
165+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
166+
sys.runQueuedTimeoutCallbacks(); // Actual update
167+
}
168+
},
145169
]
146170
});
147171
verifyTscWatch({
@@ -199,6 +223,22 @@ namespace ts.tscWatch {
199223
sys.runQueuedTimeoutCallbacks(); // Actual update
200224
}
201225
},
226+
{
227+
caption: "Create external module file that could not be resolved",
228+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
229+
timeouts: sys => {
230+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
231+
sys.runQueuedTimeoutCallbacks(); // Actual update
232+
}
233+
},
234+
{
235+
caption: "Write .ts file that takes preference over resolved .d.ts file",
236+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
237+
timeouts: sys => {
238+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
239+
sys.runQueuedTimeoutCallbacks(); // Actual update
240+
}
241+
},
202242
]
203243
});
204244
verifyTscWatch({
@@ -256,6 +296,22 @@ namespace ts.tscWatch {
256296
sys.runQueuedTimeoutCallbacks(); // Actual update
257297
}
258298
},
299+
{
300+
caption: "Create external module file that could not be resolved",
301+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
302+
timeouts: sys => {
303+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
304+
sys.runQueuedTimeoutCallbacks(); // Actual update
305+
}
306+
},
307+
{
308+
caption: "Write .ts file that takes preference over resolved .d.ts file",
309+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
310+
timeouts: sys => {
311+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
312+
sys.runQueuedTimeoutCallbacks(); // Actual update
313+
}
314+
},
259315
]
260316
});
261317

@@ -314,6 +370,22 @@ namespace ts.tscWatch {
314370
sys.runQueuedTimeoutCallbacks(); // Actual update
315371
}
316372
},
373+
{
374+
caption: "Create external module file that could not be resolved",
375+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
376+
timeouts: sys => {
377+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
378+
sys.runQueuedTimeoutCallbacks(); // Actual update
379+
}
380+
},
381+
{
382+
caption: "Write .ts file that takes preference over resolved .d.ts file",
383+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
384+
timeouts: sys => {
385+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
386+
sys.runQueuedTimeoutCallbacks(); // Actual update
387+
}
388+
},
317389
]
318390
});
319391
verifyTscWatch({
@@ -371,6 +443,22 @@ namespace ts.tscWatch {
371443
sys.runQueuedTimeoutCallbacks(); // Actual update
372444
}
373445
},
446+
{
447+
caption: "Create external module file that could not be resolved",
448+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
449+
timeouts: sys => {
450+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
451+
sys.runQueuedTimeoutCallbacks(); // Actual update
452+
}
453+
},
454+
{
455+
caption: "Write .ts file that takes preference over resolved .d.ts file",
456+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
457+
timeouts: sys => {
458+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
459+
sys.runQueuedTimeoutCallbacks(); // Actual update
460+
}
461+
},
374462
]
375463
});
376464
verifyTscWatch({
@@ -428,6 +516,22 @@ namespace ts.tscWatch {
428516
sys.runQueuedTimeoutCallbacks(); // Actual update
429517
}
430518
},
519+
{
520+
caption: "Create external module file that could not be resolved",
521+
change: sys => sys.writeFile(`${projectRoot}/src/externalThingNotPresent.ts`, "export function externalThing2() { return 20; }"),
522+
timeouts: sys => {
523+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
524+
sys.runQueuedTimeoutCallbacks(); // Actual update
525+
}
526+
},
527+
{
528+
caption: "Write .ts file that takes preference over resolved .d.ts file",
529+
change: sys => sys.writeFile(`${projectRoot}/src/externalThing.ts`, "export function externalThing1() { return 10; }"),
530+
timeouts: sys => {
531+
sys.runQueuedTimeoutCallbacks(); // Invalidate resolutions
532+
sys.runQueuedTimeoutCallbacks(); // Actual update
533+
}
534+
},
431535
]
432536
});
433537
});

src/testRunner/unittests/tsc/persistResolutions.ts

Lines changed: 38 additions & 4 deletions
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)