Skip to content

Commit 787f9b6

Browse files
committed
Fix misc unit tests
1 parent 2312bd9 commit 787f9b6

10 files changed

Lines changed: 398 additions & 283 deletions

src/testRunner/unittests/tsbuild/moduleResolution.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
7878
TestServerHost.createWatchedSystem({
7979
"/home/src/workspaces/project/packages/pkg1_index.ts": `export const theNum: TheNum = "type1";`,
8080
"/home/src/workspaces/project/packages/pkg1.tsconfig.json": jsonToReadableText({
81-
compilerOptions: { composite: true, typeRoots: ["./typeroot1"] },
81+
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], types: ["*"] },
8282
files: ["./pkg1_index.ts"],
8383
}),
8484
"/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts": dedent`declare type TheNum = "type1";`,
8585
"/home/src/workspaces/project/packages/pkg2_index.ts": `export const theNum: TheNum2 = "type2";`,
8686
"/home/src/workspaces/project/packages/pkg2.tsconfig.json": jsonToReadableText({
87-
compilerOptions: { composite: true, typeRoots: ["./typeroot2"] },
87+
compilerOptions: { composite: true, typeRoots: ["./typeroot2"], types: ["*"] },
8888
files: ["./pkg2_index.ts"],
8989
}),
9090
"/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts": dedent`declare type TheNum2 = "type2";`,
@@ -164,6 +164,7 @@ describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs bet
164164
"/home/src/workspaces/project/a/src/index.ts": "",
165165
"/home/src/workspaces/project/a/tsconfig.json": jsonToReadableText({
166166
compilerOptions: { strict: true },
167+
types: ["*"]
167168
}),
168169
"/home/src/workspaces/project/b/src/index.ts": dedent`
169170
import pg from "pg";

src/testRunner/unittests/tsc/incremental.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ declare global {
188188
"/home/src/workspaces/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
189189
"/home/src/workspaces/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
190190
"/home/src/workspaces/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
191-
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
191+
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react", types: ["react"] } }),
192192
}),
193193
commandLineArgs: ts.emptyArray,
194194
});
@@ -201,7 +201,7 @@ declare global {
201201
"/home/src/workspaces/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
202202
"/home/src/workspaces/project/node_modules/@types/react/index.d.ts": getJsxLibraryContent(), // doesn't contain a jsx-runtime definition
203203
"/home/src/workspaces/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
204-
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } }),
204+
"/home/src/workspaces/project/tsconfig.json": jsonToReadableText({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react", types: ["react"] } }),
205205
}),
206206
commandLineArgs: ["--strict"],
207207
});

src/testRunner/unittests/tscWatch/resolutionCache.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ describe("unittests:: tscWatch:: resolutionCache:: tsc-watch module resolution c
236236
verifyTscWatch({
237237
scenario,
238238
subScenario: "works when module resolution changes to ambient module",
239-
commandLineArgs: ["-w", "/users/username/projects/project/foo.ts"],
239+
commandLineArgs: ["-w", "/users/username/projects/project/foo.ts", "-types", "node"],
240240
sys: () =>
241241
TestServerHost.createWatchedSystem([{
242242
path: "/users/username/projects/project/foo.ts",
@@ -272,7 +272,7 @@ declare module "fs" {
272272
verifyTscWatch({
273273
scenario,
274274
subScenario: "works when included file with ambient module changes",
275-
commandLineArgs: ["--w", "/users/username/projects/project/foo.ts", "/users/username/projects/project/bar.d.ts"],
275+
commandLineArgs: ["--w", "/users/username/projects/project/foo.ts", "/users/username/projects/project/bar.d.ts", "-types", "node"],
276276
sys: () => {
277277
const root = {
278278
path: "/users/username/projects/project/foo.ts",
@@ -565,7 +565,7 @@ declare namespace NodeJS {
565565
};
566566
const tsconfig: File = {
567567
path: `/user/username/projects/myproject/tsconfig.json`,
568-
content: "{}",
568+
content: "{ \"compilerOptions\": { \"types\": [\"node\"] } }",
569569
};
570570
const { nodeAtTypesIndex, nodeAtTypesBase, nodeAtTypes36Base, nodeAtTypesGlobals } = getNodeAtTypes();
571571
return TestServerHost.createWatchedSystem(

tests/baselines/reference/tsbuild/moduleResolution/impliedNodeFormat-differs-between-projects-for-shared-file.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ Input::
77
{
88
"compilerOptions": {
99
"strict": true
10-
}
10+
},
11+
"types": [
12+
"*"
13+
]
1114
}
1215

1316
//// [/home/src/workspaces/project/b/src/index.ts]

tests/baselines/reference/tsbuild/moduleResolution/type-reference-resolution-uses-correct-options-for-different-resolution-options-referenced-project.js

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export const theNum: TheNum = "type1";
99
"composite": true,
1010
"typeRoots": [
1111
"./typeroot1"
12+
],
13+
"types": [
14+
"*"
1215
]
1316
},
1417
"files": [
@@ -28,6 +31,9 @@ export const theNum: TheNum2 = "type2";
2831
"composite": true,
2932
"typeRoots": [
3033
"./typeroot2"
34+
],
35+
"types": [
36+
"*"
3137
]
3238
},
3339
"files": [
@@ -63,23 +69,24 @@ Output::
6369

6470
[HH:MM:SS AM] Building project '/home/src/workspaces/project/packages/pkg1.tsconfig.json'...
6571

66-
packages/pkg1_index.ts:1:22 - error TS2304: Cannot find name 'TheNum'.
67-
68-
1 export const theNum: TheNum = "type1";
69-
   ~~~~~~
70-
72+
======== Resolving type reference directive 'sometype', containing file '/home/src/workspaces/project/packages/__inferred type names__.ts', root directory '/home/src/workspaces/project/packages/typeroot1'. ========
73+
Resolving with primary search path '/home/src/workspaces/project/packages/typeroot1'.
74+
File '/home/src/workspaces/project/packages/typeroot1/sometype.d.ts' does not exist.
75+
File '/home/src/workspaces/project/packages/typeroot1/sometype/package.json' does not exist.
76+
File '/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts' exists - use it as a name resolution result.
77+
Resolving real path for '/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts', result '/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts'.
78+
======== Type reference directive 'sometype' was successfully resolved to '/home/src/workspaces/project/packages/typeroot1/sometype/index.d.ts', primary: true. ========
7179
[HH:MM:SS AM] Project 'packages/pkg2.tsconfig.json' is out of date because output file 'packages/pkg2.tsconfig.tsbuildinfo' does not exist
7280

7381
[HH:MM:SS AM] Building project '/home/src/workspaces/project/packages/pkg2.tsconfig.json'...
7482

75-
packages/pkg2_index.ts:1:22 - error TS2304: Cannot find name 'TheNum2'.
76-
77-
1 export const theNum: TheNum2 = "type2";
78-
   ~~~~~~~
79-
80-
81-
Found 2 errors.
82-
83+
======== Resolving type reference directive 'sometype', containing file '/home/src/workspaces/project/packages/__inferred type names__.ts', root directory '/home/src/workspaces/project/packages/typeroot2'. ========
84+
Resolving with primary search path '/home/src/workspaces/project/packages/typeroot2'.
85+
File '/home/src/workspaces/project/packages/typeroot2/sometype.d.ts' does not exist.
86+
File '/home/src/workspaces/project/packages/typeroot2/sometype/package.json' does not exist.
87+
File '/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts' exists - use it as a name resolution result.
88+
Resolving real path for '/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts', result '/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts'.
89+
======== Type reference directive 'sometype' was successfully resolved to '/home/src/workspaces/project/packages/typeroot2/sometype/index.d.ts', primary: true. ========
8390

8491

8592
//// [/home/src/workspaces/project/packages/pkg1_index.js]
@@ -94,13 +101,14 @@ export declare const theNum: TheNum;
94101

95102

96103
//// [/home/src/workspaces/project/packages/pkg1.tsconfig.tsbuildinfo]
97-
{"fileNames":["../../../tslibs/ts/lib/lib.d.ts","./pkg1_index.ts"],"fileInfos":[{"version":"-25093698414-interface 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; };","affectsGlobalScope":true},{"version":"-9601687719-export const theNum: TheNum = \"type1\";","signature":"-11475605505-export declare const theNum: TheNum;\n"}],"root":[2],"options":{"composite":true},"semanticDiagnosticsPerFile":[[2,[{"start":21,"length":6,"messageText":"Cannot find name 'TheNum'.","category":1,"code":2304}]]],"latestChangedDtsFile":"./pkg1_index.d.ts","version":"FakeTSVersion"}
104+
{"fileNames":["../../../tslibs/ts/lib/lib.d.ts","./pkg1_index.ts","./typeroot1/sometype/index.d.ts"],"fileInfos":[{"version":"-25093698414-interface 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; };","affectsGlobalScope":true},{"version":"-9601687719-export const theNum: TheNum = \"type1\";","signature":"-11475605505-export declare const theNum: TheNum;\n"},{"version":"-4557394441-declare type TheNum = \"type1\";","affectsGlobalScope":true}],"root":[2],"options":{"composite":true},"latestChangedDtsFile":"./pkg1_index.d.ts","version":"FakeTSVersion"}
98105

99106
//// [/home/src/workspaces/project/packages/pkg1.tsconfig.tsbuildinfo.readable.baseline.txt]
100107
{
101108
"fileNames": [
102109
"../../../tslibs/ts/lib/lib.d.ts",
103-
"./pkg1_index.ts"
110+
"./pkg1_index.ts",
111+
"./typeroot1/sometype/index.d.ts"
104112
],
105113
"fileInfos": {
106114
"../../../tslibs/ts/lib/lib.d.ts": {
@@ -119,6 +127,15 @@ export declare const theNum: TheNum;
119127
},
120128
"version": "-9601687719-export const theNum: TheNum = \"type1\";",
121129
"signature": "-11475605505-export declare const theNum: TheNum;\n"
130+
},
131+
"./typeroot1/sometype/index.d.ts": {
132+
"original": {
133+
"version": "-4557394441-declare type TheNum = \"type1\";",
134+
"affectsGlobalScope": true
135+
},
136+
"version": "-4557394441-declare type TheNum = \"type1\";",
137+
"signature": "-4557394441-declare type TheNum = \"type1\";",
138+
"affectsGlobalScope": true
122139
}
123140
},
124141
"root": [
@@ -130,23 +147,9 @@ export declare const theNum: TheNum;
130147
"options": {
131148
"composite": true
132149
},
133-
"semanticDiagnosticsPerFile": [
134-
[
135-
"./pkg1_index.ts",
136-
[
137-
{
138-
"start": 21,
139-
"length": 6,
140-
"messageText": "Cannot find name 'TheNum'.",
141-
"category": 1,
142-
"code": 2304
143-
}
144-
]
145-
]
146-
],
147150
"latestChangedDtsFile": "./pkg1_index.d.ts",
148151
"version": "FakeTSVersion",
149-
"size": 891
152+
"size": 881
150153
}
151154

152155
//// [/home/src/workspaces/project/packages/pkg2_index.js]
@@ -161,13 +164,14 @@ export declare const theNum: TheNum2;
161164

162165

163166
//// [/home/src/workspaces/project/packages/pkg2.tsconfig.tsbuildinfo]
164-
{"fileNames":["../../../tslibs/ts/lib/lib.d.ts","./pkg2_index.ts"],"fileInfos":[{"version":"-25093698414-interface 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; };","affectsGlobalScope":true},{"version":"-12823281204-export const theNum: TheNum2 = \"type2\";","signature":"-13622769679-export declare const theNum: TheNum2;\n"}],"root":[2],"options":{"composite":true},"semanticDiagnosticsPerFile":[[2,[{"start":21,"length":7,"messageText":"Cannot find name 'TheNum2'.","category":1,"code":2304}]]],"latestChangedDtsFile":"./pkg2_index.d.ts","version":"FakeTSVersion"}
167+
{"fileNames":["../../../tslibs/ts/lib/lib.d.ts","./pkg2_index.ts","./typeroot2/sometype/index.d.ts"],"fileInfos":[{"version":"-25093698414-interface 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; };","affectsGlobalScope":true},{"version":"-12823281204-export const theNum: TheNum2 = \"type2\";","signature":"-13622769679-export declare const theNum: TheNum2;\n"},{"version":"-980425686-declare type TheNum2 = \"type2\";","affectsGlobalScope":true}],"root":[2],"options":{"composite":true},"latestChangedDtsFile":"./pkg2_index.d.ts","version":"FakeTSVersion"}
165168

166169
//// [/home/src/workspaces/project/packages/pkg2.tsconfig.tsbuildinfo.readable.baseline.txt]
167170
{
168171
"fileNames": [
169172
"../../../tslibs/ts/lib/lib.d.ts",
170-
"./pkg2_index.ts"
173+
"./pkg2_index.ts",
174+
"./typeroot2/sometype/index.d.ts"
171175
],
172176
"fileInfos": {
173177
"../../../tslibs/ts/lib/lib.d.ts": {
@@ -186,6 +190,15 @@ export declare const theNum: TheNum2;
186190
},
187191
"version": "-12823281204-export const theNum: TheNum2 = \"type2\";",
188192
"signature": "-13622769679-export declare const theNum: TheNum2;\n"
193+
},
194+
"./typeroot2/sometype/index.d.ts": {
195+
"original": {
196+
"version": "-980425686-declare type TheNum2 = \"type2\";",
197+
"affectsGlobalScope": true
198+
},
199+
"version": "-980425686-declare type TheNum2 = \"type2\";",
200+
"signature": "-980425686-declare type TheNum2 = \"type2\";",
201+
"affectsGlobalScope": true
189202
}
190203
},
191204
"root": [
@@ -197,24 +210,10 @@ export declare const theNum: TheNum2;
197210
"options": {
198211
"composite": true
199212
},
200-
"semanticDiagnosticsPerFile": [
201-
[
202-
"./pkg2_index.ts",
203-
[
204-
{
205-
"start": 21,
206-
"length": 7,
207-
"messageText": "Cannot find name 'TheNum2'.",
208-
"category": 1,
209-
"code": 2304
210-
}
211-
]
212-
]
213-
],
214213
"latestChangedDtsFile": "./pkg2_index.d.ts",
215214
"version": "FakeTSVersion",
216-
"size": 895
215+
"size": 884
217216
}
218217

219218

220-
exitCode:: ExitStatus.DiagnosticsPresent_OutputsSkipped
219+
exitCode:: ExitStatus.Success

0 commit comments

Comments
 (0)