Skip to content

Commit 2cf6d4f

Browse files
committed
Testcase showing that renaming file with non sync directory watcher displays correct error in the end
Testcase for #38684
1 parent a37585e commit 2cf6d4f

File tree

2 files changed

+273
-0
lines changed

2 files changed

+273
-0
lines changed

src/testRunner/unittests/tscWatch/watchEnvironment.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,49 @@ namespace ts.tscWatch {
294294
noopChange,
295295
],
296296
});
297+
298+
verifyTscWatch({
299+
scenario,
300+
subScenario: "watchDirectories/with non synchronous watch directory renaming a file",
301+
commandLineArgs: ["--w", "-p", `${projectRoot}/tsconfig.json`],
302+
sys: () => {
303+
const configFile: File = {
304+
path: `${projectRoot}/tsconfig.json`,
305+
content: JSON.stringify({ compilerOptions: { outDir: "dist" } })
306+
};
307+
const file1: File = {
308+
path: `${projectRoot}/src/file1.ts`,
309+
content: `import { x } from "./file2";`
310+
};
311+
const file2: File = {
312+
path: `${projectRoot}/src/file2.ts`,
313+
content: `export const x = 10;`
314+
};
315+
const files = [libFile, file1, file2, configFile];
316+
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
317+
},
318+
changes: [
319+
noopChange,
320+
{
321+
caption: "rename the file",
322+
change: sys => sys.renameFile(`${projectRoot}/src/file2.ts`, `${projectRoot}/src/renamed.ts`),
323+
timeouts: sys => {
324+
sys.checkTimeoutQueueLength(2); // 1. For updating program and 2. for updating child watches
325+
sys.runQueuedTimeoutCallbacks(1); // Update program
326+
},
327+
},
328+
{
329+
caption: "Pending directory watchers and program update",
330+
change: noop,
331+
timeouts: sys => {
332+
sys.checkTimeoutQueueLengthAndRun(1); // To update directory watchers
333+
sys.checkTimeoutQueueLengthAndRun(2); // To Update program and failed lookup update
334+
sys.checkTimeoutQueueLengthAndRun(1); // Actual program update
335+
sys.checkTimeoutQueueLength(0);
336+
},
337+
},
338+
],
339+
});
297340
});
298341

299342
describe("handles watch compiler options", () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
Input::
2+
//// [/a/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+
15+
//// [/user/username/projects/myproject/src/file1.ts]
16+
import { x } from "./file2";
17+
18+
//// [/user/username/projects/myproject/src/file2.ts]
19+
export const x = 10;
20+
21+
//// [/user/username/projects/myproject/tsconfig.json]
22+
{"compilerOptions":{"outDir":"dist"}}
23+
24+
25+
/a/lib/tsc.js --w -p /user/username/projects/myproject/tsconfig.json
26+
Output::
27+
>> Screen clear
28+
[12:00:25 AM] Starting compilation in watch mode...
29+
30+
31+
[12:00:33 AM] Found 0 errors. Watching for file changes.
32+
33+
34+
35+
Program root files: ["/user/username/projects/myproject/src/file1.ts","/user/username/projects/myproject/src/file2.ts"]
36+
Program options: {"outDir":"/user/username/projects/myproject/dist","watch":true,"project":"/user/username/projects/myproject/tsconfig.json","configFilePath":"/user/username/projects/myproject/tsconfig.json"}
37+
Program files::
38+
/a/lib/lib.d.ts
39+
/user/username/projects/myproject/src/file2.ts
40+
/user/username/projects/myproject/src/file1.ts
41+
42+
Semantic diagnostics in builder refreshed for::
43+
/a/lib/lib.d.ts
44+
/user/username/projects/myproject/src/file2.ts
45+
/user/username/projects/myproject/src/file1.ts
46+
47+
WatchedFiles::
48+
/user/username/projects/myproject/tsconfig.json:
49+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
50+
/user/username/projects/myproject/src/file1.ts:
51+
{"fileName":"/user/username/projects/myproject/src/file1.ts","pollingInterval":250}
52+
/user/username/projects/myproject/src/file2.ts:
53+
{"fileName":"/user/username/projects/myproject/src/file2.ts","pollingInterval":250}
54+
/a/lib/lib.d.ts:
55+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
56+
57+
FsWatches::
58+
/user/username/projects/myproject/node_modules/@types:
59+
{"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
60+
/user/username/projects/myproject:
61+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
62+
/user/username/projects/myproject/dist:
63+
{"directoryName":"/user/username/projects/myproject/dist","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
64+
/user/username/projects/myproject/src:
65+
{"directoryName":"/user/username/projects/myproject/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
66+
67+
FsWatchesRecursive::
68+
69+
exitCode:: ExitStatus.undefined
70+
71+
//// [/user/username/projects/myproject/dist/file2.js]
72+
"use strict";
73+
exports.__esModule = true;
74+
exports.x = void 0;
75+
exports.x = 10;
76+
77+
78+
//// [/user/username/projects/myproject/dist/file1.js]
79+
"use strict";
80+
exports.__esModule = true;
81+
82+
83+
84+
Change:: No change
85+
86+
Input::
87+
88+
Output::
89+
90+
WatchedFiles::
91+
/user/username/projects/myproject/tsconfig.json:
92+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
93+
/user/username/projects/myproject/src/file1.ts:
94+
{"fileName":"/user/username/projects/myproject/src/file1.ts","pollingInterval":250}
95+
/user/username/projects/myproject/src/file2.ts:
96+
{"fileName":"/user/username/projects/myproject/src/file2.ts","pollingInterval":250}
97+
/a/lib/lib.d.ts:
98+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
99+
100+
FsWatches::
101+
/user/username/projects/myproject/node_modules/@types:
102+
{"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
103+
/user/username/projects/myproject:
104+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
105+
/user/username/projects/myproject/dist:
106+
{"directoryName":"/user/username/projects/myproject/dist","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
107+
/user/username/projects/myproject/src:
108+
{"directoryName":"/user/username/projects/myproject/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
109+
110+
FsWatchesRecursive::
111+
112+
exitCode:: ExitStatus.undefined
113+
114+
115+
Change:: rename the file
116+
117+
Input::
118+
//// [/user/username/projects/myproject/src/renamed.ts]
119+
export const x = 10;
120+
121+
//// [/user/username/projects/myproject/src/file2.ts] deleted
122+
123+
Output::
124+
>> Screen clear
125+
[12:00:37 AM] File change detected. Starting incremental compilation...
126+
127+
128+
error TS6053: File '/user/username/projects/myproject/src/file2.ts' not found.
129+
130+
131+
[12:00:41 AM] Found 1 error. Watching for file changes.
132+
133+
134+
135+
Program root files: ["/user/username/projects/myproject/src/file1.ts","/user/username/projects/myproject/src/file2.ts"]
136+
Program options: {"outDir":"/user/username/projects/myproject/dist","watch":true,"project":"/user/username/projects/myproject/tsconfig.json","configFilePath":"/user/username/projects/myproject/tsconfig.json"}
137+
Program files::
138+
/a/lib/lib.d.ts
139+
/user/username/projects/myproject/src/file1.ts
140+
141+
Semantic diagnostics in builder refreshed for::
142+
/user/username/projects/myproject/src/file1.ts
143+
144+
WatchedFiles::
145+
/user/username/projects/myproject/tsconfig.json:
146+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
147+
/user/username/projects/myproject/src/file1.ts:
148+
{"fileName":"/user/username/projects/myproject/src/file1.ts","pollingInterval":250}
149+
/a/lib/lib.d.ts:
150+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
151+
/user/username/projects/myproject/src/file2.ts:
152+
{"fileName":"/user/username/projects/myproject/src/file2.ts","pollingInterval":250}
153+
154+
FsWatches::
155+
/user/username/projects/myproject/node_modules/@types:
156+
{"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
157+
/user/username/projects/myproject:
158+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
159+
/user/username/projects/myproject/dist:
160+
{"directoryName":"/user/username/projects/myproject/dist","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
161+
/user/username/projects/myproject/src:
162+
{"directoryName":"/user/username/projects/myproject/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
163+
164+
FsWatchesRecursive::
165+
166+
exitCode:: ExitStatus.undefined
167+
168+
//// [/user/username/projects/myproject/dist/file1.js] file written with same contents
169+
170+
Change:: Pending directory watchers and program update
171+
172+
Input::
173+
174+
Output::
175+
>> Screen clear
176+
[12:00:42 AM] File change detected. Starting incremental compilation...
177+
178+
179+
user/username/projects/myproject/src/file1.ts:1:19 - error TS2307: Cannot find module './file2' or its corresponding type declarations.
180+
181+
1 import { x } from "./file2";
182+
   ~~~~~~~~~
183+
184+
185+
[12:00:45 AM] Found 1 error. Watching for file changes.
186+
187+
188+
189+
Program root files: ["/user/username/projects/myproject/src/file1.ts","/user/username/projects/myproject/src/renamed.ts"]
190+
Program options: {"outDir":"/user/username/projects/myproject/dist","watch":true,"project":"/user/username/projects/myproject/tsconfig.json","configFilePath":"/user/username/projects/myproject/tsconfig.json"}
191+
Program files::
192+
/a/lib/lib.d.ts
193+
/user/username/projects/myproject/src/file1.ts
194+
/user/username/projects/myproject/src/renamed.ts
195+
196+
Semantic diagnostics in builder refreshed for::
197+
/user/username/projects/myproject/src/file1.ts
198+
/user/username/projects/myproject/src/renamed.ts
199+
200+
WatchedFiles::
201+
/user/username/projects/myproject/tsconfig.json:
202+
{"fileName":"/user/username/projects/myproject/tsconfig.json","pollingInterval":250}
203+
/user/username/projects/myproject/src/file1.ts:
204+
{"fileName":"/user/username/projects/myproject/src/file1.ts","pollingInterval":250}
205+
/a/lib/lib.d.ts:
206+
{"fileName":"/a/lib/lib.d.ts","pollingInterval":250}
207+
/user/username/projects/myproject/src/renamed.ts:
208+
{"fileName":"/user/username/projects/myproject/src/renamed.ts","pollingInterval":250}
209+
210+
FsWatches::
211+
/user/username/projects/myproject/node_modules/@types:
212+
{"directoryName":"/user/username/projects/myproject/node_modules/@types","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
213+
/user/username/projects/myproject:
214+
{"directoryName":"/user/username/projects/myproject","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
215+
/user/username/projects/myproject/dist:
216+
{"directoryName":"/user/username/projects/myproject/dist","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
217+
/user/username/projects/myproject/src:
218+
{"directoryName":"/user/username/projects/myproject/src","fallbackPollingInterval":500,"fallbackOptions":{"watchFile":"PriorityPollingInterval"}}
219+
220+
FsWatchesRecursive::
221+
222+
exitCode:: ExitStatus.undefined
223+
224+
//// [/user/username/projects/myproject/dist/renamed.js]
225+
"use strict";
226+
exports.__esModule = true;
227+
exports.x = void 0;
228+
exports.x = 10;
229+
230+

0 commit comments

Comments
 (0)