Skip to content

Commit a80cdfb

Browse files
committed
Fix APISample tests to not depend on the existence of the ts namespace
The way we pull in the types for typescript in these tests only works when we include typescriptServices.d.ts into the project, which declares a global namespace, which then is reexported as the typescript package. This reexport is already what the current typescript.d.ts does, but now that we don't have the namespace at all, we can't do this. Instead, simulate the typescript package directly and point it at the correct d.ts file. This is a good chagne regardless of the module transform, and could be cherry-picked back to main early.
1 parent 4953316 commit a80cdfb

18 files changed

+81
-69
lines changed

tests/baselines/reference/APISample_Watch.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_Watch.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_Watch.ts]

tests/baselines/reference/APISample_WatchWithDefaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_WatchWithDefaults.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_WatchWithDefaults.ts]

tests/baselines/reference/APISample_WatchWithOwnWatchHost.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_WatchWithOwnWatchHost.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_WatchWithOwnWatchHost.ts]

tests/baselines/reference/APISample_compile.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_compile.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_compile.ts]

tests/baselines/reference/APISample_jsdoc.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_jsdoc.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_jsdoc.ts]

tests/baselines/reference/APISample_linter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_linter.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_linter.ts]
@@ -68,7 +69,8 @@ fileNames.forEach(fileName => {
6869

6970
// delint it
7071
delint(sourceFile);
71-
});
72+
});
73+
7274

7375
//// [APISample_linter.js]
7476
"use strict";

tests/baselines/reference/APISample_parseConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_parseConfig.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_parseConfig.ts]
@@ -40,7 +41,8 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
4041
return undefined;
4142
}
4243
return ts.createProgram(rootFiles, settings.options);
43-
}
44+
}
45+
4446

4547
//// [APISample_parseConfig.js]
4648
"use strict";

tests/baselines/reference/APISample_transform.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_transform.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_transform.ts]
@@ -20,7 +21,8 @@ const source = "let x: string = 'string'";
2021

2122
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
2223

23-
console.log(JSON.stringify(result));
24+
console.log(JSON.stringify(result));
25+
2426

2527
//// [APISample_transform.js]
2628
"use strict";

tests/baselines/reference/APISample_watcher.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//// [tests/cases/compiler/APISample_watcher.ts] ////
22

3-
//// [index.d.ts]
4-
declare module "typescript" {
5-
export = ts;
3+
//// [package.json]
4+
{
5+
"name": "typescript",
6+
"types": "/.ts/typescript.d.ts"
67
}
78

89
//// [APISample_watcher.ts]

tests/cases/compiler/APISample_Watch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_Watch.ts

tests/cases/compiler/APISample_WatchWithDefaults.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_WatchWithDefaults.ts

tests/cases/compiler/APISample_WatchWithOwnWatchHost.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_WatchWithOwnWatchHost.ts

tests/cases/compiler/APISample_compile.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_compile.ts

tests/cases/compiler/APISample_jsdoc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_jsdoc.ts

tests/cases/compiler/APISample_linter.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_linter.ts
@@ -72,4 +72,4 @@ fileNames.forEach(fileName => {
7272

7373
// delint it
7474
delint(sourceFile);
75-
});
75+
});

tests/cases/compiler/APISample_parseConfig.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_parseConfig.ts
@@ -44,4 +44,4 @@ export function createProgram(rootFiles: string[], compilerOptionsJson: string):
4444
return undefined;
4545
}
4646
return ts.createProgram(rootFiles, settings.options);
47-
}
47+
}

tests/cases/compiler/APISample_transform.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_transform.ts
@@ -24,4 +24,4 @@ const source = "let x: string = 'string'";
2424

2525
let result = ts.transpile(source, { module: ts.ModuleKind.CommonJS });
2626

27-
console.log(JSON.stringify(result));
27+
console.log(JSON.stringify(result));

tests/cases/compiler/APISample_watcher.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// @module: commonjs
22
// @skipLibCheck: true
3-
// @includebuiltfile: typescriptServices.d.ts
43
// @noImplicitAny:true
54
// @strictNullChecks:true
65

7-
// @filename: node_modules/typescript/index.d.ts
8-
declare module "typescript" {
9-
export = ts;
6+
// @filename: node_modules/typescript/package.json
7+
{
8+
"name": "typescript",
9+
"types": "/.ts/typescript.d.ts"
1010
}
1111

1212
// @filename: APISample_watcher.ts

0 commit comments

Comments
 (0)