Skip to content

Commit 43720b9

Browse files
committed
Some tests where file is added later to the project
1 parent 098e3ef commit 43720b9

File tree

5 files changed

+354
-4
lines changed

5 files changed

+354
-4
lines changed

src/testRunner/unittests/tsserver/auxiliaryProject.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import * as ts from "../../_namespaces/ts";
2+
import {
3+
dedent,
4+
} from "../../_namespaces/Utils";
25
import {
36
baselineTsserverLogs,
47
createLoggerWithInMemoryLogs,
58
createSession,
69
openFilesForSession,
10+
protocolFileLocationFromSubstring,
711
} from "../helpers/tsserver";
812
import {
913
createServerHost,
1014
File,
15+
libFile,
1116
} from "../helpers/virtualFileSystemWithWatch";
1217

13-
describe("unittests:: tsserver:: auxiliaryProject", () => {
18+
describe("unittests:: tsserver:: auxiliaryProject::", () => {
1419
it("AuxiliaryProject does not remove scrips from InferredProject", () => {
1520
const aTs: File = {
1621
path: "/a.ts",
@@ -33,8 +38,11 @@ describe("unittests:: tsserver:: auxiliaryProject", () => {
3338
const inferredProject = projectService.inferredProjects[0];
3439

3540
// getNoDtsResolutionProject will create an AuxiliaryProject with a.ts and b.js
41+
session.executeCommandSeq<ts.server.protocol.FindSourceDefinitionRequest>({
42+
command: ts.server.protocol.CommandTypes.FindSourceDefinition,
43+
arguments: protocolFileLocationFromSubstring(aTs, "B"),
44+
});
3645
const auxProject = inferredProject.getNoDtsResolutionProject([aTs.path]);
37-
auxProject.updateGraph();
3846

3947
// b.js ScriptInfo is now available because it's contained by the AuxiliaryProject.
4048
// The AuxiliaryProject should never be the default project for anything, so
@@ -54,4 +62,59 @@ describe("unittests:: tsserver:: auxiliaryProject", () => {
5462
assert.equal(bJsScriptInfo.getDefaultProject().projectKind, ts.server.ProjectKind.Inferred);
5563
baselineTsserverLogs("auxiliaryProject", "does not remove scrips from InferredProject", session);
5664
});
65+
66+
it("file is added later through finding definition", () => {
67+
const indexFile: File = {
68+
path: "/user/users/projects/myproject/index.ts",
69+
content: dedent`
70+
import { command } from "yargs";
71+
command("foo", yargs => {
72+
yargs.positional();
73+
});
74+
`,
75+
};
76+
const host = createServerHost({
77+
"/user/users/projects/myproject/node_modules/@types/yargs/package.json": JSON.stringify(
78+
{
79+
name: "@types/yargs",
80+
version: "1.0.0",
81+
types: "./index.d.ts",
82+
},
83+
undefined,
84+
" ",
85+
),
86+
"/user/users/projects/myproject/node_modules/@types/yargs/callback.d.ts": dedent`
87+
export declare class Yargs { positional(): Yargs; }
88+
`,
89+
"/user/users/projects/myproject/node_modules/@types/yargs/index.d.ts": dedent`
90+
import { Yargs } from "./callback";
91+
export declare function command(command: string, cb: (yargs: Yargs) => void): void;
92+
`,
93+
"/user/users/projects/myproject/node_modules/yargs/package.json": JSON.stringify(
94+
{
95+
name: "yargs",
96+
version: "1.0.0",
97+
main: "index.js",
98+
},
99+
undefined,
100+
" ",
101+
),
102+
"/user/users/projects/myproject/node_modules/yargs/callback.js": dedent`
103+
export class Yargs { positional() { } }
104+
`,
105+
"/user/users/projects/myproject/node_modules/yargs/index.js": dedent`
106+
// Specifically didnt have ./callback import to ensure that resolving module sepcifier adds the file to project at later stage
107+
export function command(cmd, cb) { cb(Yargs) }
108+
`,
109+
[indexFile.path]: indexFile.content,
110+
[libFile.path]: libFile.content,
111+
});
112+
const session = createSession(host, { logger: createLoggerWithInMemoryLogs(host) });
113+
openFilesForSession([indexFile], session);
114+
session.executeCommandSeq<ts.server.protocol.FindSourceDefinitionRequest>({
115+
command: ts.server.protocol.CommandTypes.FindSourceDefinition,
116+
arguments: protocolFileLocationFromSubstring(indexFile, "positional"),
117+
});
118+
baselineTsserverLogs("auxiliaryProject", "file is added later through finding definition", session);
119+
});
57120
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// === goToSourceDefinition ===
2+
// === /index.ts ===
3+
// import { command } from "yargs";
4+
// command("foo", yargs => {
5+
// yargs./*GOTO SOURCE DEF*/positional();
6+
// });

tests/baselines/reference/tsserver/auxiliaryProject/does-not-remove-scrips-from-InferredProject.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,19 @@ FsWatches::
5959
/b.d.ts: *new*
6060
{}
6161

62+
Before request
63+
64+
Info seq [hh:mm:ss:mss] request:
65+
{
66+
"command": "findSourceDefinition",
67+
"arguments": {
68+
"file": "/a.ts",
69+
"line": 1,
70+
"offset": 10
71+
},
72+
"seq": 2,
73+
"type": "request"
74+
}
6275
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/auxiliaryProject1*
6376
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /b.js 500 undefined WatchType: Closed Script info
6477
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/auxiliaryProject1* Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
@@ -74,7 +87,32 @@ Info seq [hh:mm:ss:mss] Files (2)
7487
Root file specified for compilation
7588

7689
Info seq [hh:mm:ss:mss] -----------------------------------------------
77-
Before request
90+
Info seq [hh:mm:ss:mss] response:
91+
{
92+
"response": [
93+
{
94+
"file": "/b.js",
95+
"start": {
96+
"line": 1,
97+
"offset": 14
98+
},
99+
"end": {
100+
"line": 1,
101+
"offset": 15
102+
},
103+
"contextStart": {
104+
"line": 1,
105+
"offset": 1
106+
},
107+
"contextEnd": {
108+
"line": 1,
109+
"offset": 18
110+
}
111+
}
112+
],
113+
"responseRequired": true
114+
}
115+
After request
78116

79117
PolledWatches::
80118
/a/lib/lib.d.ts:
@@ -86,13 +124,15 @@ FsWatches::
86124
/b.js: *new*
87125
{}
88126

127+
Before request
128+
89129
Info seq [hh:mm:ss:mss] request:
90130
{
91131
"command": "open",
92132
"arguments": {
93133
"file": "/b.js"
94134
},
95-
"seq": 2,
135+
"seq": 3,
96136
"type": "request"
97137
}
98138
Info seq [hh:mm:ss:mss] FileWatcher:: Close:: WatchInfo: /b.js 500 undefined WatchType: Closed Script info
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
currentDirectory:: / useCaseSensitiveFileNames: false
2+
Info seq [hh:mm:ss:mss] Provided types map file "/a/lib/typesMap.json" doesn't exist
3+
Before request
4+
//// [/user/users/projects/myproject/node_modules/@types/yargs/package.json]
5+
{
6+
"name": "@types/yargs",
7+
"version": "1.0.0",
8+
"types": "./index.d.ts"
9+
}
10+
11+
//// [/user/users/projects/myproject/node_modules/@types/yargs/callback.d.ts]
12+
export declare class Yargs { positional(): Yargs; }
13+
14+
15+
//// [/user/users/projects/myproject/node_modules/@types/yargs/index.d.ts]
16+
17+
import { Yargs } from "./callback";
18+
export declare function command(command: string, cb: (yargs: Yargs) => void): void;
19+
20+
21+
//// [/user/users/projects/myproject/node_modules/yargs/package.json]
22+
{
23+
"name": "yargs",
24+
"version": "1.0.0",
25+
"main": "index.js"
26+
}
27+
28+
//// [/user/users/projects/myproject/node_modules/yargs/callback.js]
29+
export class Yargs { positional() { } }
30+
31+
32+
//// [/user/users/projects/myproject/node_modules/yargs/index.js]
33+
// Specifically didnt have ./callback import to ensure that resolving module sepcifier adds the file to project at later stage
34+
export function command(cmd, cb) { cb(Yargs) }
35+
36+
37+
//// [/user/users/projects/myproject/index.ts]
38+
import { command } from "yargs";
39+
command("foo", yargs => {
40+
yargs.positional();
41+
});
42+
43+
44+
//// [/a/lib/lib.d.ts]
45+
/// <reference no-default-lib="true"/>
46+
interface Boolean {}
47+
interface Function {}
48+
interface CallableFunction {}
49+
interface NewableFunction {}
50+
interface IArguments {}
51+
interface Number { toExponential: any; }
52+
interface Object {}
53+
interface RegExp {}
54+
interface String { charAt: any; }
55+
interface Array<T> { length: number; [n: number]: T; }
56+
57+
58+
Info seq [hh:mm:ss:mss] request:
59+
{
60+
"command": "open",
61+
"arguments": {
62+
"file": "/user/users/projects/myproject/index.ts"
63+
},
64+
"seq": 1,
65+
"type": "request"
66+
}
67+
Info seq [hh:mm:ss:mss] Search path: /user/users/projects/myproject
68+
Info seq [hh:mm:ss:mss] For info: /user/users/projects/myproject/index.ts :: No config files found.
69+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/users/projects/myproject/tsconfig.json 2000 undefined WatchType: Config file for the inferred project root
70+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/users/projects/myproject/jsconfig.json 2000 undefined WatchType: Config file for the inferred project root
71+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/inferredProject1*
72+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
73+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined WatchType: node_modules for closed script infos and package.jsons affecting module specifier cache
74+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
75+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined Project: /dev/null/inferredProject1* WatchType: Failed Lookup Locations
76+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules/@types/yargs/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
77+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 500 undefined WatchType: Closed Script info
78+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules/yargs/package.json 2000 undefined Project: /dev/null/inferredProject1* WatchType: File location affecting resolution
79+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
80+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
81+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
82+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/node_modules/@types 1 undefined Project: /dev/null/inferredProject1* WatchType: Type roots
83+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/inferredProject1* Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
84+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
85+
Info seq [hh:mm:ss:mss] Files (4)
86+
/a/lib/lib.d.ts Text-1 "/// <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; }"
87+
/user/users/projects/myproject/node_modules/@types/yargs/callback.d.ts Text-1 "export declare class Yargs { positional(): Yargs; }\n"
88+
/user/users/projects/myproject/node_modules/@types/yargs/index.d.ts Text-1 "\nimport { Yargs } from \"./callback\";\nexport declare function command(command: string, cb: (yargs: Yargs) => void): void;\n"
89+
/user/users/projects/myproject/index.ts SVC-1-0 "import { command } from \"yargs\";\ncommand(\"foo\", yargs => {\n yargs.positional();\n});\n"
90+
91+
92+
../../../../a/lib/lib.d.ts
93+
Default library for target 'es5'
94+
node_modules/@types/yargs/callback.d.ts
95+
Imported via "./callback" from file 'node_modules/@types/yargs/index.d.ts' with packageId '@types/yargs/[email protected]'
96+
node_modules/@types/yargs/index.d.ts
97+
Imported via "yargs" from file 'index.ts' with packageId '@types/yargs/[email protected]'
98+
Entry point for implicit type library 'yargs' with packageId '@types/yargs/[email protected]'
99+
index.ts
100+
Root file specified for compilation
101+
102+
Info seq [hh:mm:ss:mss] -----------------------------------------------
103+
Info seq [hh:mm:ss:mss] Project '/dev/null/inferredProject1*' (Inferred)
104+
Info seq [hh:mm:ss:mss] Files (4)
105+
106+
Info seq [hh:mm:ss:mss] -----------------------------------------------
107+
Info seq [hh:mm:ss:mss] Open files:
108+
Info seq [hh:mm:ss:mss] FileName: /user/users/projects/myproject/index.ts ProjectRootPath: undefined
109+
Info seq [hh:mm:ss:mss] Projects: /dev/null/inferredProject1*
110+
Info seq [hh:mm:ss:mss] response:
111+
{
112+
"responseRequired": false
113+
}
114+
After request
115+
116+
PolledWatches::
117+
/user/users/projects/myproject/jsconfig.json: *new*
118+
{"pollingInterval":2000}
119+
/user/users/projects/myproject/tsconfig.json: *new*
120+
{"pollingInterval":2000}
121+
/user/users/projects/node_modules/@types: *new*
122+
{"pollingInterval":500}
123+
124+
FsWatches::
125+
/a/lib/lib.d.ts: *new*
126+
{}
127+
/user/users/projects/myproject/node_modules/@types/yargs/package.json: *new*
128+
{}
129+
/user/users/projects/myproject/node_modules/yargs/package.json: *new*
130+
{}
131+
132+
FsWatchesRecursive::
133+
/user/users/projects/myproject/node_modules: *new*
134+
{}
135+
/user/users/projects/myproject/node_modules/@types: *new*
136+
{}
137+
138+
Before request
139+
140+
Info seq [hh:mm:ss:mss] request:
141+
{
142+
"command": "findSourceDefinition",
143+
"arguments": {
144+
"file": "/user/users/projects/myproject/index.ts",
145+
"line": 3,
146+
"offset": 11
147+
},
148+
"seq": 2,
149+
"type": "request"
150+
}
151+
Info seq [hh:mm:ss:mss] Starting updateGraphWorker: Project: /dev/null/auxiliaryProject1*
152+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined Project: /dev/null/auxiliaryProject1* WatchType: Failed Lookup Locations
153+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules 1 undefined Project: /dev/null/auxiliaryProject1* WatchType: Failed Lookup Locations
154+
Info seq [hh:mm:ss:mss] DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/node_modules 1 undefined Project: /dev/null/auxiliaryProject1* WatchType: Failed Lookup Locations
155+
Info seq [hh:mm:ss:mss] Elapsed:: *ms DirectoryWatcher:: Added:: WatchInfo: /user/users/projects/node_modules 1 undefined Project: /dev/null/auxiliaryProject1* WatchType: Failed Lookup Locations
156+
Info seq [hh:mm:ss:mss] FileWatcher:: Added:: WatchInfo: /user/users/projects/myproject/node_modules/yargs/package.json 2000 undefined Project: /dev/null/auxiliaryProject1* WatchType: File location affecting resolution
157+
Info seq [hh:mm:ss:mss] Finishing updateGraphWorker: Project: /dev/null/auxiliaryProject1* Version: 1 structureChanged: true structureIsReused:: Not Elapsed:: *ms
158+
Info seq [hh:mm:ss:mss] Project '/dev/null/auxiliaryProject1*' (Auxiliary)
159+
Info seq [hh:mm:ss:mss] Files (2)
160+
/user/users/projects/myproject/node_modules/yargs/index.js Text-1 "// Specifically didnt have ./callback import to ensure that resolving module sepcifier adds the file to project at later stage\nexport function command(cmd, cb) { cb(Yargs) }\n"
161+
/user/users/projects/myproject/index.ts SVC-1-0 "import { command } from \"yargs\";\ncommand(\"foo\", yargs => {\n yargs.positional();\n});\n"
162+
163+
164+
node_modules/yargs/index.js
165+
Imported via "yargs" from file 'index.ts' with packageId 'yargs/index.js@1.0.0'
166+
index.ts
167+
Root file specified for compilation
168+
169+
Info seq [hh:mm:ss:mss] -----------------------------------------------
170+
Info seq [hh:mm:ss:mss] response:
171+
{
172+
"response": [],
173+
"responseRequired": true
174+
}
175+
After request
176+
177+
PolledWatches::
178+
/user/users/projects/myproject/jsconfig.json:
179+
{"pollingInterval":2000}
180+
/user/users/projects/myproject/tsconfig.json:
181+
{"pollingInterval":2000}
182+
/user/users/projects/node_modules: *new*
183+
{"pollingInterval":500}
184+
/user/users/projects/node_modules/@types:
185+
{"pollingInterval":500}
186+
187+
FsWatches::
188+
/a/lib/lib.d.ts:
189+
{}
190+
/user/users/projects/myproject/node_modules/@types/yargs/package.json:
191+
{}
192+
/user/users/projects/myproject/node_modules/yargs/package.json:
193+
{}
194+
195+
FsWatchesRecursive::
196+
/user/users/projects/myproject/node_modules:
197+
{}
198+
/user/users/projects/myproject/node_modules/@types:
199+
{}

0 commit comments

Comments
 (0)