Skip to content

Commit 5c12067

Browse files
committed
Add test that shows input file is not present
1 parent 59f2b5c commit 5c12067

File tree

3 files changed

+402
-0
lines changed

3 files changed

+402
-0
lines changed

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,34 @@ class someClass2 { }`),
509509
modifyFs: fs => replaceText(fs, "/src/tests/tsconfig.json", `"esModuleInterop": false`, `"esModuleInterop": true`),
510510
}],
511511
});
512+
513+
verifyTsc({
514+
scenario: "sample1",
515+
subScenario: "reports error if input file is missing",
516+
fs: () => projFs,
517+
commandLineArgs: ["--b", "/src/tests", "--v"],
518+
modifyFs: fs => {
519+
fs.writeFileSync("/src/core/tsconfig.json", JSON.stringify({
520+
compilerOptions: { composite: true },
521+
files: ["anotherModule.ts", "index.ts", "some_decl.d.ts"]
522+
}));
523+
fs.unlinkSync("/src/core/anotherModule.ts");
524+
}
525+
});
526+
527+
verifyTsc({
528+
scenario: "sample1",
529+
subScenario: "reports error if input file is missing with force",
530+
fs: () => projFs,
531+
commandLineArgs: ["--b", "/src/tests", "--v", "--f"],
532+
modifyFs: fs => {
533+
fs.writeFileSync("/src/core/tsconfig.json", JSON.stringify({
534+
compilerOptions: { composite: true },
535+
files: ["anotherModule.ts", "index.ts", "some_decl.d.ts"]
536+
}));
537+
fs.unlinkSync("/src/core/anotherModule.ts");
538+
}
539+
});
512540
});
513541
});
514542
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/core/index.ts]
18+
export const someString: string = "HELLO WORLD";
19+
export function leftPad(s: string, n: number) { return s + n; }
20+
export function multiply(a: number, b: number) { return a * b; }
21+
22+
23+
//// [/src/core/some_decl.d.ts]
24+
declare const dts: any;
25+
26+
27+
//// [/src/core/tsconfig.json]
28+
{"compilerOptions":{"composite":true},"files":["anotherModule.ts","index.ts","some_decl.d.ts"]}
29+
30+
//// [/src/logic/index.ts]
31+
import * as c from '../core/index';
32+
export function getSecondsInDay() {
33+
return c.multiply(10, 15);
34+
}
35+
import * as mod from '../core/anotherModule';
36+
export const m = mod;
37+
38+
39+
//// [/src/logic/tsconfig.json]
40+
{
41+
"compilerOptions": {
42+
"composite": true,
43+
"declaration": true,
44+
"sourceMap": true,
45+
"forceConsistentCasingInFileNames": true,
46+
"skipDefaultLibCheck": true
47+
},
48+
"references": [
49+
{ "path": "../core" }
50+
]
51+
}
52+
53+
54+
//// [/src/tests/index.ts]
55+
import * as c from '../core/index';
56+
import * as logic from '../logic/index';
57+
58+
c.leftPad("", 10);
59+
logic.getSecondsInDay();
60+
61+
import * as mod from '../core/anotherModule';
62+
export const m = mod;
63+
64+
65+
//// [/src/tests/tsconfig.json]
66+
{
67+
"references": [
68+
{ "path": "../core" },
69+
{ "path": "../logic" }
70+
],
71+
"files": ["index.ts"],
72+
"compilerOptions": {
73+
"composite": true,
74+
"declaration": true,
75+
"forceConsistentCasingInFileNames": true,
76+
"skipDefaultLibCheck": true
77+
}
78+
}
79+
80+
//// [/src/ui/index.ts]
81+
import * as logic from '../logic';
82+
83+
export function run() {
84+
console.log(logic.getSecondsInDay());
85+
}
86+
87+
88+
//// [/src/ui/tsconfig.json]
89+
{
90+
"compilerOptions": {
91+
"skipDefaultLibCheck": true
92+
},
93+
"references": [
94+
{ "path": "../logic/index" }
95+
]
96+
}
97+
98+
99+
100+
101+
Output::
102+
/lib/tsc --b /src/tests --v --f
103+
[12:00:08 AM] Projects in this build:
104+
* src/core/tsconfig.json
105+
* src/logic/tsconfig.json
106+
* src/tests/tsconfig.json
107+
108+
[12:00:09 AM] Failed to parse file 'src/core/tsconfig.json': /src/core/anotherModule.ts does not exist.
109+
110+
[12:00:10 AM] Building project '/src/core/tsconfig.json'...
111+
112+
error TS6053: File '/src/core/anotherModule.ts' not found.
113+
The file is in the program because:
114+
Part of 'files' list in tsconfig.json
115+
116+
src/core/tsconfig.json:1:48
117+
1 {"compilerOptions":{"composite":true},"files":["anotherModule.ts","index.ts","some_decl.d.ts"]}
118+
   ~~~~~~~~~~~~~~~~~~
119+
File is matched by 'files' list specified here.
120+
121+
[12:00:13 AM] Project 'src/logic/tsconfig.json' can't be built because its dependency 'src/core' has errors
122+
123+
[12:00:14 AM] Skipping build of project '/src/logic/tsconfig.json' because its dependency '/src/core' has errors
124+
125+
[12:00:15 AM] Project 'src/tests/tsconfig.json' can't be built because its dependency 'src/core' has errors
126+
127+
[12:00:16 AM] Skipping build of project '/src/tests/tsconfig.json' because its dependency '/src/core' has errors
128+
129+
130+
Found 1 error.
131+
132+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
133+
134+
getModifiedTime:: {
135+
"/src/core/anotherModule.ts": 1
136+
}
137+
138+
setModifiedTime:: {}
139+
140+
fileExists:: {}
141+
142+
directoryExists:: {
143+
"/src/core/node_modules/@types": 1,
144+
"/src/node_modules/@types": 1,
145+
"/node_modules/@types": 1
146+
}
147+
148+
149+
//// [/src/core/tsconfig.tsbuildinfo]
150+
{"program":{"fileNames":["../../lib/lib.d.ts","./index.ts","./some_decl.d.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","signature":false,"affectsGlobalScope":true},{"version":"-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n","signature":false},{"version":"-9253692965-declare const dts: any;\r\n","signature":false,"affectsGlobalScope":true}],"options":{"composite":true},"referencedMap":[],"exportedModulesMap":[],"changeFileSet":[1,2,3]},"version":"FakeTSVersion"}
151+
152+
//// [/src/core/tsconfig.tsbuildinfo.readable.baseline.txt]
153+
{
154+
"program": {
155+
"fileNames": [
156+
"../../lib/lib.d.ts",
157+
"./index.ts",
158+
"./some_decl.d.ts"
159+
],
160+
"fileInfos": {
161+
"../../lib/lib.d.ts": {
162+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
163+
"affectsGlobalScope": true
164+
},
165+
"./index.ts": {
166+
"version": "-18749805970-export const someString: string = \"HELLO WORLD\";\r\nexport function leftPad(s: string, n: number) { return s + n; }\r\nexport function multiply(a: number, b: number) { return a * b; }\r\n"
167+
},
168+
"./some_decl.d.ts": {
169+
"version": "-9253692965-declare const dts: any;\r\n",
170+
"affectsGlobalScope": true
171+
}
172+
},
173+
"options": {
174+
"composite": true
175+
},
176+
"referencedMap": {},
177+
"exportedModulesMap": {},
178+
"changeFileSet": [
179+
"../../lib/lib.d.ts",
180+
"./index.ts",
181+
"./some_decl.d.ts"
182+
]
183+
},
184+
"version": "FakeTSVersion",
185+
"size": 1046
186+
}
187+

0 commit comments

Comments
 (0)