Skip to content

Commit 9d4c544

Browse files
committed
Fix tests after main merge
1 parent 151d26b commit 9d4c544

File tree

12 files changed

+198
-143
lines changed

12 files changed

+198
-143
lines changed

internal/modulespecifiers/specifiers_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/microsoft/typescript-go/internal/core"
88
"github.com/microsoft/typescript-go/internal/module"
99
"github.com/microsoft/typescript-go/internal/packagejson"
10+
"github.com/microsoft/typescript-go/internal/pnp"
1011
"github.com/microsoft/typescript-go/internal/symlinks"
1112
"github.com/microsoft/typescript-go/internal/tsoptions"
1213
"github.com/microsoft/typescript-go/internal/tspath"
@@ -23,6 +24,10 @@ func (h *mockModuleSpecifierGenerationHost) GetCurrentDirectory() string {
2324
return h.currentDir
2425
}
2526

27+
func (h *mockModuleSpecifierGenerationHost) PnpApi() *pnp.PnpApi {
28+
return nil
29+
}
30+
2631
func (h *mockModuleSpecifierGenerationHost) UseCaseSensitiveFileNames() bool {
2732
return h.useCaseSensitiveFileNames
2833
}

testdata/baselines/reference/compiler/pnpSimpleTest.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ module.exports = {};
5959
"types": "index.d.ts"
6060
}
6161

62-
//// [index.js]
63-
exports.helperA = function(value) {
64-
return "Helper A: " + value;
65-
};
66-
6762
//// [index.d.ts]
6863
export declare function helperA(value: string): string;
6964

@@ -77,11 +72,6 @@ export declare function helperA(value: string): string;
7772
"types": "index.d.ts"
7873
}
7974

80-
//// [index.js]
81-
exports.helperB = function(value) {
82-
return "Helper B: " + value;
83-
};
84-
8575
//// [index.d.ts]
8676
export declare function helperB(value: number): string;
8777

@@ -108,3 +98,7 @@ function processData(text, num) {
10898
const resultB = (0, package_b_1.helperB)(num);
10999
return `${resultA} | ${resultB}`;
110100
}
101+
102+
103+
//// [index.d.ts]
104+
export declare function processData(text: string, num: number): string;

testdata/baselines/reference/compiler/pnpSimpleTest.symbols

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//// [tests/cases/compiler/pnpSimpleTest.ts] ////
22

3-
=== /.yarn/cache/package-a-npm-1.0.0-abcd1234/node_modules/package-a/index.d.ts ===
4-
export declare function helperA(value: string): string;
5-
>helperA : Symbol(helperA, Decl(index.d.ts, 0, 0))
6-
>value : Symbol(value, Decl(index.d.ts, 0, 32))
7-
8-
=== /.yarn/cache/package-b-npm-2.0.0-efgh5678/node_modules/package-b/index.d.ts ===
9-
export declare function helperB(value: number): string;
10-
>helperB : Symbol(helperB, Decl(index.d.ts, 0, 0))
11-
>value : Symbol(value, Decl(index.d.ts, 0, 32))
12-
133
=== /src/index.ts ===
144
// Workspace package that imports both third-party dependencies
155
import { helperA } from 'package-a';
@@ -37,3 +27,13 @@ export function processData(text: string, num: number): string {
3727
>resultA : Symbol(resultA, Decl(index.ts, 5, 7))
3828
>resultB : Symbol(resultB, Decl(index.ts, 6, 7))
3929
}
30+
=== /.yarn/cache/package-a-npm-1.0.0-abcd1234/node_modules/package-a/index.d.ts ===
31+
export declare function helperA(value: string): string;
32+
>helperA : Symbol(helperA, Decl(index.d.ts, 0, 0))
33+
>value : Symbol(value, Decl(index.d.ts, 0, 32))
34+
35+
=== /.yarn/cache/package-b-npm-2.0.0-efgh5678/node_modules/package-b/index.d.ts ===
36+
export declare function helperB(value: number): string;
37+
>helperB : Symbol(helperB, Decl(index.d.ts, 0, 0))
38+
>value : Symbol(value, Decl(index.d.ts, 0, 32))
39+

testdata/baselines/reference/compiler/pnpSimpleTest.types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
//// [tests/cases/compiler/pnpSimpleTest.ts] ////
22

3-
=== /.yarn/cache/package-a-npm-1.0.0-abcd1234/node_modules/package-a/index.d.ts ===
4-
export declare function helperA(value: string): string;
5-
>helperA : (value: string) => string
6-
>value : string
7-
8-
=== /.yarn/cache/package-b-npm-2.0.0-efgh5678/node_modules/package-b/index.d.ts ===
9-
export declare function helperB(value: number): string;
10-
>helperB : (value: number) => string
11-
>value : number
12-
133
=== /src/index.ts ===
144
// Workspace package that imports both third-party dependencies
155
import { helperA } from 'package-a';
@@ -40,3 +30,13 @@ export function processData(text: string, num: number): string {
4030
>resultA : string
4131
>resultB : string
4232
}
33+
=== /.yarn/cache/package-a-npm-1.0.0-abcd1234/node_modules/package-a/index.d.ts ===
34+
export declare function helperA(value: string): string;
35+
>helperA : (value: string) => string
36+
>value : string
37+
38+
=== /.yarn/cache/package-b-npm-2.0.0-efgh5678/node_modules/package-b/index.d.ts ===
39+
export declare function helperB(value: number): string;
40+
>helperB : (value: number) => string
41+
>value : number
42+

testdata/baselines/reference/compiler/pnpTransitiveDependencies.errors.txt

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,61 @@
11
/src/index.ts(5,36): error TS2307: Cannot find module 'package-b' or its corresponding type declarations.
22

33

4+
==== /tsconfig.json (0 errors) ====
5+
{
6+
"compilerOptions": {
7+
"exclude": [".pnp.cjs"],
8+
"rootDir": ".",
9+
"declaration": true,
10+
"outDir": "./dist"
11+
}
12+
}
13+
14+
==== /packages/package-a/index.ts (0 errors) ====
15+
import type { ConfigOptions } from 'package-b';
16+
17+
export interface HelperResult {
18+
message: string;
19+
config: ConfigOptions;
20+
}
21+
22+
export function helperA(value: string, config: ConfigOptions): HelperResult {
23+
return {
24+
message: "Helper A: " + value,
25+
config: config
26+
};
27+
}
28+
29+
==== /packages/package-b/index.ts (0 errors) ====
30+
export interface ConfigOptions {
31+
enabled: boolean;
32+
timeout: number;
33+
}
34+
35+
export function helperB(value: number): string {
36+
return "Helper B: " + value;
37+
}
38+
39+
==== /src/index.ts (1 errors) ====
40+
// Test that the project can import package-a directly
41+
// package-a's types depend on package-b's types (ConfigOptions)
42+
import { helperA } from 'package-a';
43+
import type { HelperResult } from 'package-a';
44+
import type { ConfigOptions } from 'package-b'; // This should error - package-b is not a direct dependency
45+
~~~~~~~~~~~
46+
!!! error TS2307: Cannot find module 'package-b' or its corresponding type declarations.
47+
48+
export function useDirectDependency(text: string): HelperResult {
49+
const config: ConfigOptions = { enabled: true, timeout: 5000 };
50+
return helperA(text, config);
51+
}
52+
53+
// Test that the project CANNOT import package-b directly even though package-a uses it
54+
// This should cause an error since package-b is not in project's dependencies
55+
export function attemptDirectImport(): ConfigOptions {
56+
return { enabled: false, timeout: 1000 };
57+
}
58+
459
==== /.pnp.cjs (0 errors) ====
560
module.exports = {};
661

@@ -65,21 +120,6 @@
65120
}
66121
}
67122

68-
==== /packages/package-a/index.ts (0 errors) ====
69-
import type { ConfigOptions } from 'package-b';
70-
71-
export interface HelperResult {
72-
message: string;
73-
config: ConfigOptions;
74-
}
75-
76-
export function helperA(value: string, config: ConfigOptions): HelperResult {
77-
return {
78-
message: "Helper A: " + value,
79-
config: config
80-
};
81-
}
82-
83123
==== /packages/package-b/package.json (0 errors) ====
84124
{
85125
"name": "package-b",
@@ -88,34 +128,4 @@
88128
".": "./index.ts"
89129
}
90130
}
91-
92-
==== /packages/package-b/index.ts (0 errors) ====
93-
export interface ConfigOptions {
94-
enabled: boolean;
95-
timeout: number;
96-
}
97-
98-
export function helperB(value: number): string {
99-
return "Helper B: " + value;
100-
}
101-
102-
==== /src/index.ts (1 errors) ====
103-
// Test that the project can import package-a directly
104-
// package-a's types depend on package-b's types (ConfigOptions)
105-
import { helperA } from 'package-a';
106-
import type { HelperResult } from 'package-a';
107-
import type { ConfigOptions } from 'package-b'; // This should error - package-b is not a direct dependency
108-
~~~~~~~~~~~
109-
!!! error TS2307: Cannot find module 'package-b' or its corresponding type declarations.
110-
111-
export function useDirectDependency(text: string): HelperResult {
112-
const config: ConfigOptions = { enabled: true, timeout: 5000 };
113-
return helperA(text, config);
114-
}
115-
116-
// Test that the project CANNOT import package-b directly even though package-a uses it
117-
// This should cause an error since package-b is not in project's dependencies
118-
export function attemptDirectImport(): ConfigOptions {
119-
return { enabled: false, timeout: 1000 };
120-
}
121131

testdata/baselines/reference/compiler/pnpTransitiveDependencies.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ module.exports = {};
6464
}
6565
}
6666

67+
//// [package.json]
68+
{
69+
"name": "package-b",
70+
"version": "2.0.0",
71+
"exports": {
72+
".": "./index.ts"
73+
}
74+
}
75+
6776
//// [index.ts]
6877
import type { ConfigOptions } from 'package-b';
6978

@@ -79,15 +88,6 @@ export function helperA(value: string, config: ConfigOptions): HelperResult {
7988
};
8089
}
8190

82-
//// [package.json]
83-
{
84-
"name": "package-b",
85-
"version": "2.0.0",
86-
"exports": {
87-
".": "./index.ts"
88-
}
89-
}
90-
9191
//// [index.ts]
9292
export interface ConfigOptions {
9393
enabled: boolean;
@@ -151,3 +151,23 @@ function useDirectDependency(text) {
151151
function attemptDirectImport() {
152152
return { enabled: false, timeout: 1000 };
153153
}
154+
155+
156+
//// [index.d.ts]
157+
export interface ConfigOptions {
158+
enabled: boolean;
159+
timeout: number;
160+
}
161+
export declare function helperB(value: number): string;
162+
//// [index.d.ts]
163+
import type { ConfigOptions } from 'package-b';
164+
export interface HelperResult {
165+
message: string;
166+
config: ConfigOptions;
167+
}
168+
export declare function helperA(value: string, config: ConfigOptions): HelperResult;
169+
//// [index.d.ts]
170+
import type { HelperResult } from 'package-a';
171+
import type { ConfigOptions } from 'package-b';
172+
export declare function useDirectDependency(text: string): HelperResult;
173+
export declare function attemptDirectImport(): ConfigOptions;

testdata/baselines/reference/compiler/pnpTypeRootsResolution.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ function handleRequest(req, res) {
101101
res.json({ data: 'Hello, world!' });
102102
}
103103
exports.server = (0, server_lib_1.createServer)();
104+
105+
106+
//// [index.d.ts]
107+
import type { Request, Response } from 'server-lib';
108+
export declare function handleRequest(req: Request, res: Response): void;
109+
export declare const server: Record<string, unknown>;
Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,32 @@
11
//// [tests/cases/compiler/pnpTypeRootsResolution.ts] ////
22

3+
=== /src/index.ts ===
4+
// Test that TypeScript can resolve @types packages through PnP
5+
import type { Request, Response } from 'server-lib';
6+
>Request : Symbol(Request, Decl(index.ts, 1, 13))
7+
>Response : Symbol(Response, Decl(index.ts, 1, 22))
8+
9+
import { createServer } from 'server-lib';
10+
>createServer : Symbol(createServer, Decl(index.ts, 2, 8))
11+
12+
export function handleRequest(req: Request, res: Response): void {
13+
>handleRequest : Symbol(handleRequest, Decl(index.ts, 2, 42))
14+
>req : Symbol(req, Decl(index.ts, 4, 30))
15+
>Request : Symbol(Request, Decl(index.ts, 1, 13))
16+
>res : Symbol(res, Decl(index.ts, 4, 43))
17+
>Response : Symbol(Response, Decl(index.ts, 1, 22))
18+
19+
res.json({ data: 'Hello, world!' });
20+
>res.json : Symbol(Response.json, Decl(index.d.ts, 6, 44))
21+
>res : Symbol(res, Decl(index.ts, 4, 43))
22+
>json : Symbol(Response.json, Decl(index.d.ts, 6, 44))
23+
>data : Symbol(data, Decl(index.ts, 5, 12))
24+
}
25+
26+
export const server = createServer();
27+
>server : Symbol(server, Decl(index.ts, 8, 12))
28+
>createServer : Symbol(createServer, Decl(index.ts, 2, 8))
29+
330
=== /.yarn/cache/@types-server-lib-npm-2.0.0-mnop3456/node_modules/@types/server-lib/index.d.ts ===
431
export interface Request {
532
>Request : Symbol(Request, Decl(index.d.ts, 0, 0))
@@ -31,30 +58,3 @@ export declare function createServer(): Record<string, unknown>;
3158
>createServer : Symbol(createServer, Decl(index.d.ts, 8, 1))
3259
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
3360

34-
=== /src/index.ts ===
35-
// Test that TypeScript can resolve @types packages through PnP
36-
import type { Request, Response } from 'server-lib';
37-
>Request : Symbol(Request, Decl(index.ts, 1, 13))
38-
>Response : Symbol(Response, Decl(index.ts, 1, 22))
39-
40-
import { createServer } from 'server-lib';
41-
>createServer : Symbol(createServer, Decl(index.ts, 2, 8))
42-
43-
export function handleRequest(req: Request, res: Response): void {
44-
>handleRequest : Symbol(handleRequest, Decl(index.ts, 2, 42))
45-
>req : Symbol(req, Decl(index.ts, 4, 30))
46-
>Request : Symbol(Request, Decl(index.ts, 1, 13))
47-
>res : Symbol(res, Decl(index.ts, 4, 43))
48-
>Response : Symbol(Response, Decl(index.ts, 1, 22))
49-
50-
res.json({ data: 'Hello, world!' });
51-
>res.json : Symbol(Response.json, Decl(index.d.ts, 6, 44))
52-
>res : Symbol(res, Decl(index.ts, 4, 43))
53-
>json : Symbol(Response.json, Decl(index.d.ts, 6, 44))
54-
>data : Symbol(data, Decl(index.ts, 5, 12))
55-
}
56-
57-
export const server = createServer();
58-
>server : Symbol(server, Decl(index.ts, 8, 12))
59-
>createServer : Symbol(createServer, Decl(index.ts, 2, 8))
60-

0 commit comments

Comments
 (0)