/
watchEnvironment.ts
723 lines (699 loc) · 37.3 KB
/
watchEnvironment.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
namespace ts.tscWatch {
import Tsc_WatchDirectory = TestFSWithWatch.Tsc_WatchDirectory;
describe("unittests:: tsc-watch:: watchEnvironment:: tsc-watch with different polling/non polling options", () => {
const scenario = "watchEnvironment";
verifyTscWatch({
scenario,
subScenario: "watchFile/using dynamic priority polling",
commandLineArgs: ["--w", `/a/username/project/typescript.ts`],
sys: () => {
const projectFolder = "/a/username/project";
const file1: File = {
path: `${projectFolder}/typescript.ts`,
content: "var z = 10;"
};
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHFILE", TestFSWithWatch.Tsc_WatchFile.DynamicPolling);
return createWatchedSystem([file1, libFile], { environmentVariables });
},
changes: [
{
caption: "Time spent to Transition libFile and file1 to low priority queue",
change: noop,
timeouts: (sys, programs) => {
const initialProgram = programs[0][0];
const mediumPollingIntervalThreshold = unchangedPollThresholds[PollingInterval.Medium];
for (let index = 0; index < mediumPollingIntervalThreshold; index++) {
// Transition libFile and file1 to low priority queue
sys.checkTimeoutQueueLengthAndRun(1);
assert.deepEqual(programs[0][0], initialProgram);
}
return;
},
},
{
caption: "Make change to file",
// Make a change to file
change: sys => sys.writeFile("/a/username/project/typescript.ts", "var zz30 = 100;"),
// During this timeout the file would be detected as unchanged
timeouts: checkSingleTimeoutQueueLengthAndRun,
},
{
caption: "Callbacks: medium priority + high priority queue and scheduled program update",
change: noop,
// Callbacks: medium priority + high priority queue and scheduled program update
// This should detect change in the file
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(3),
},
{
caption: "Polling queues polled and everything is in the high polling queue",
change: noop,
timeouts: (sys, programs) => {
const initialProgram = programs[0][0];
const mediumPollingIntervalThreshold = unchangedPollThresholds[PollingInterval.Medium];
const newThreshold = unchangedPollThresholds[PollingInterval.Low] + mediumPollingIntervalThreshold;
for (let fileUnchangeDetected = 1; fileUnchangeDetected < newThreshold; fileUnchangeDetected++) {
// For high + Medium/low polling interval
sys.checkTimeoutQueueLengthAndRun(2);
assert.deepEqual(programs[0][0], initialProgram);
}
// Everything goes in high polling interval queue
sys.checkTimeoutQueueLengthAndRun(1);
return;
},
}
]
});
verifyTscWatch({
scenario,
subScenario: "watchFile/using fixed chunk size polling",
commandLineArgs: ["-w", "-p", "/a/b/tsconfig.json"],
sys: () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({
watchOptions: {
watchFile: "FixedChunkSizePolling"
}
})
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files);
},
changes: [
{
caption: "The timeout is to check the status of all files",
change: noop,
timeouts: (sys, programs) => {
// On each timeout file does not change
const initialProgram = programs[0][0];
for (let index = 0; index < 4; index++) {
sys.checkTimeoutQueueLengthAndRun(1);
assert.deepEqual(programs[0][0], initialProgram);
}
},
},
{
caption: "Make change to file but should detect as changed and schedule program update",
// Make a change to file
change: sys => sys.writeFile(commonFile1.path, "var zz30 = 100;"),
timeouts: checkSingleTimeoutQueueLengthAndRun,
},
{
caption: "Callbacks: queue and scheduled program update",
change: noop,
// Callbacks: scheduled program update and queue for the polling
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
},
{
caption: "The timeout is to check the status of all files",
change: noop,
timeouts: (sys, programs) => {
// On each timeout file does not change
const initialProgram = programs[0][0];
sys.checkTimeoutQueueLengthAndRun(1);
assert.deepEqual(programs[0][0], initialProgram);
},
},
]
});
describe("tsc-watch when watchDirectories implementation", () => {
function verifyRenamingFileInSubFolder(subScenario: string, tscWatchDirectory: Tsc_WatchDirectory) {
const projectFolder = "/a/username/project";
const projectSrcFolder = `${projectFolder}/src`;
const configFile: File = {
path: `${projectFolder}/tsconfig.json`,
content: JSON.stringify({
watchOptions: {
synchronousWatchDirectory: true
}
})
};
const file: File = {
path: `${projectSrcFolder}/file1.ts`,
content: ""
};
verifyTscWatch({
scenario,
subScenario: `watchDirectories/${subScenario}`,
commandLineArgs: ["--w", "-p", configFile.path],
sys: () => {
const files = [file, configFile, libFile];
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", tscWatchDirectory);
return createWatchedSystem(files, { environmentVariables });
},
changes: [
{
caption: "Rename file1 to file2",
// Rename the file:
change: sys => sys.renameFile(file.path, file.path.replace("file1.ts", "file2.ts")),
timeouts: sys => {
if (tscWatchDirectory === Tsc_WatchDirectory.DynamicPolling) {
// With dynamic polling the fs change would be detected only by running timeouts
sys.runQueuedTimeoutCallbacks();
}
// Delayed update program
sys.runQueuedTimeoutCallbacks();
return;
},
},
],
});
}
verifyRenamingFileInSubFolder("uses watchFile when renaming file in subfolder", Tsc_WatchDirectory.WatchFile);
verifyRenamingFileInSubFolder("uses non recursive watchDirectory when renaming file in subfolder", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
verifyRenamingFileInSubFolder("uses non recursive dynamic polling when renaming file in subfolder", Tsc_WatchDirectory.DynamicPolling);
verifyTscWatch({
scenario,
subScenario: "watchDirectories/when there are symlinks to folders in recursive folders",
commandLineArgs: ["--w"],
sys: () => {
const cwd = "/home/user/projects/myproject";
const file1: File = {
path: `${cwd}/src/file.ts`,
content: `import * as a from "a"`
};
const tsconfig: File = {
path: `${cwd}/tsconfig.json`,
content: `{ "compilerOptions": { "extendedDiagnostics": true, "traceResolution": true }}`
};
const realA: File = {
path: `${cwd}/node_modules/reala/index.d.ts`,
content: `export {}`
};
const realB: File = {
path: `${cwd}/node_modules/realb/index.d.ts`,
content: `export {}`
};
const symLinkA: SymLink = {
path: `${cwd}/node_modules/a`,
symLink: `${cwd}/node_modules/reala`
};
const symLinkB: SymLink = {
path: `${cwd}/node_modules/b`,
symLink: `${cwd}/node_modules/realb`
};
const symLinkBInA: SymLink = {
path: `${cwd}/node_modules/reala/node_modules/b`,
symLink: `${cwd}/node_modules/b`
};
const symLinkAInB: SymLink = {
path: `${cwd}/node_modules/realb/node_modules/a`,
symLink: `${cwd}/node_modules/a`
};
const files = [libFile, file1, tsconfig, realA, realB, symLinkA, symLinkB, symLinkBInA, symLinkAInB];
const environmentVariables = new Map<string, string>();
environmentVariables.set("TSC_WATCHDIRECTORY", Tsc_WatchDirectory.NonRecursiveWatchDirectory);
return createWatchedSystem(files, { environmentVariables, currentDirectory: cwd });
},
changes: emptyArray
});
verifyTscWatch({
scenario,
subScenario: "watchDirectories/with non synchronous watch directory",
commandLineArgs: ["--w", "-p", `${projectRoot}/tsconfig.json`],
sys: () => {
const configFile: File = {
path: `${projectRoot}/tsconfig.json`,
content: "{}"
};
const file1: File = {
path: `${projectRoot}/src/file1.ts`,
content: `import { x } from "file2";`
};
const file2: File = {
path: `${projectRoot}/node_modules/file2/index.d.ts`,
content: `export const x = 10;`
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
},
changes: [
{
caption: "Directory watch updates because of file1.js creation",
change: noop,
timeouts: sys => {
sys.checkTimeoutQueueLengthAndRun(1); // To update directory callbacks for file1.js output
sys.checkTimeoutQueueLength(0);
},
},
{
caption: "Remove directory node_modules",
// Remove directory node_modules
change: sys => sys.deleteFolder(`${projectRoot}/node_modules`, /*recursive*/ true),
timeouts: sys => {
sys.checkTimeoutQueueLength(3); // 1. Failed lookup invalidation 2. For updating program and 3. for updating child watches
sys.runQueuedTimeoutCallbacks(sys.getNextTimeoutId() - 2); // Update program
},
},
{
caption: "Pending directory watchers and program update",
change: noop,
timeouts: sys => {
sys.checkTimeoutQueueLengthAndRun(1); // To update directory watchers
sys.checkTimeoutQueueLengthAndRun(2); // To Update program and failed lookup update
sys.checkTimeoutQueueLengthAndRun(1); // Actual program update
sys.checkTimeoutQueueLength(0);
},
},
{
caption: "Start npm install",
// npm install
change: sys => sys.createDirectory(`${projectRoot}/node_modules`),
timeouts: sys => sys.checkTimeoutQueueLength(1), // To update folder structure
},
{
caption: "npm install folder creation of file2",
change: sys => sys.createDirectory(`${projectRoot}/node_modules/file2`),
timeouts: sys => sys.checkTimeoutQueueLength(1), // To update folder structure
},
{
caption: "npm install index file in file2",
change: sys => sys.writeFile(`${projectRoot}/node_modules/file2/index.d.ts`, `export const x = 10;`),
timeouts: sys => sys.checkTimeoutQueueLength(1), // To update folder structure
},
{
caption: "Updates the program",
change: noop,
timeouts: sys => {
sys.runQueuedTimeoutCallbacks();
sys.checkTimeoutQueueLength(2); // To Update program and failed lookup update
},
},
{
caption: "Invalidates module resolution cache",
change: noop,
timeouts: sys => {
sys.runQueuedTimeoutCallbacks();
sys.checkTimeoutQueueLength(1); // To Update program
},
},
{
caption: "Pending updates",
change: noop,
timeouts: sys => {
sys.runQueuedTimeoutCallbacks();
sys.checkTimeoutQueueLength(0);
},
},
],
});
verifyTscWatch({
scenario,
subScenario: "watchDirectories/with non synchronous watch directory with outDir and declaration enabled",
commandLineArgs: ["--w", "-p", `${projectRoot}/tsconfig.json`],
sys: () => {
const configFile: File = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ compilerOptions: { outDir: "dist", declaration: true } })
};
const file1: File = {
path: `${projectRoot}/src/file1.ts`,
content: `import { x } from "file2";`
};
const file2: File = {
path: `${projectRoot}/node_modules/file2/index.d.ts`,
content: `export const x = 10;`
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
},
changes: [
noopChange,
{
caption: "Add new file, should schedule and run timeout to update directory watcher",
change: sys => sys.writeFile(`${projectRoot}/src/file3.ts`, `export const y = 10;`),
timeouts: checkSingleTimeoutQueueLengthAndRun, // Update the child watch
},
{
caption: "Actual program update to include new file",
change: noop,
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2), // Scheduling failed lookup update and program update
},
{
caption: "After program emit with new file, should schedule and run timeout to update directory watcher",
change: noop,
timeouts: checkSingleTimeoutQueueLengthAndRun, // Update the child watch
},
noopChange,
],
});
verifyTscWatch({
scenario,
subScenario: "watchDirectories/with non synchronous watch directory renaming a file",
commandLineArgs: ["--w", "-p", `${projectRoot}/tsconfig.json`],
sys: () => {
const configFile: File = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ compilerOptions: { outDir: "dist" } })
};
const file1: File = {
path: `${projectRoot}/src/file1.ts`,
content: `import { x } from "./file2";`
};
const file2: File = {
path: `${projectRoot}/src/file2.ts`,
content: `export const x = 10;`
};
const files = [libFile, file1, file2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
},
changes: [
noopChange,
{
caption: "rename the file",
change: sys => sys.renameFile(`${projectRoot}/src/file2.ts`, `${projectRoot}/src/renamed.ts`),
timeouts: sys => {
sys.checkTimeoutQueueLength(2); // 1. For updating program and 2. for updating child watches
sys.runQueuedTimeoutCallbacks(1); // Update program
},
},
{
caption: "Pending directory watchers and program update",
change: noop,
timeouts: sys => {
sys.checkTimeoutQueueLengthAndRun(1); // To update directory watchers
sys.checkTimeoutQueueLengthAndRun(2); // To Update program and failed lookup update
sys.checkTimeoutQueueLengthAndRun(1); // Actual program update
sys.checkTimeoutQueueLength(0);
},
},
],
});
});
describe("handles watch compiler options", () => {
verifyTscWatch({
scenario,
subScenario: "watchOptions/with watchFile option",
commandLineArgs: ["-w", "-p", "/a/b/tsconfig.json"],
sys: () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({
watchOptions: {
watchFile: "UseFsEvents"
}
})
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files);
},
changes: emptyArray
});
verifyTscWatch({
scenario,
subScenario: "watchOptions/with watchDirectory option",
commandLineArgs: ["-w", "-p", "/a/b/tsconfig.json"],
sys: () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({
watchOptions: {
watchDirectory: "UseFsEvents"
}
})
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true });
},
changes: emptyArray
});
verifyTscWatch({
scenario,
subScenario: "watchOptions/with fallbackPolling option",
commandLineArgs: ["-w", "-p", "/a/b/tsconfig.json"],
sys: () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: JSON.stringify({
watchOptions: {
fallbackPolling: "PriorityInterval"
}
})
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files, { runWithoutRecursiveWatches: true, runWithFallbackPolling: true });
},
changes: emptyArray
});
verifyTscWatch({
scenario,
subScenario: "watchOptions/with watchFile as watch options to extend",
commandLineArgs: ["-w", "-p", "/a/b/tsconfig.json", "--watchFile", "UseFsEvents"],
sys: () => {
const configFile: File = {
path: "/a/b/tsconfig.json",
content: "{}"
};
const files = [libFile, commonFile1, commonFile2, configFile];
return createWatchedSystem(files);
},
changes: emptyArray
});
describe("exclude options", () => {
function sys(watchOptions: WatchOptions, runWithoutRecursiveWatches?: boolean): WatchedSystem {
const configFile: File = {
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({ exclude: ["node_modules"], watchOptions })
};
const main: File = {
path: `${projectRoot}/src/main.ts`,
content: `import { foo } from "bar"; foo();`
};
const bar: File = {
path: `${projectRoot}/node_modules/bar/index.d.ts`,
content: `export { foo } from "./foo";`
};
const foo: File = {
path: `${projectRoot}/node_modules/bar/foo.d.ts`,
content: `export function foo(): string;`
};
const fooBar: File = {
path: `${projectRoot}/node_modules/bar/fooBar.d.ts`,
content: `export function fooBar(): string;`
};
const temp: File = {
path: `${projectRoot}/node_modules/bar/temp/index.d.ts`,
content: "export function temp(): string;"
};
const files = [libFile, main, bar, foo, fooBar, temp, configFile];
return createWatchedSystem(files, { currentDirectory: projectRoot, runWithoutRecursiveWatches });
}
function verifyWorker(...additionalFlags: string[]) {
verifyTscWatch({
scenario,
subScenario: `watchOptions/with excludeFiles option${additionalFlags.join("")}`,
commandLineArgs: ["-w", ...additionalFlags],
sys: () => sys({ excludeFiles: ["node_modules/*"] }),
changes: [
{
caption: "Change foo",
change: sys => replaceFileText(sys, `${projectRoot}/node_modules/bar/foo.d.ts`, "foo", "fooBar"),
timeouts: sys => sys.checkTimeoutQueueLength(0),
}
]
});
verifyTscWatch({
scenario,
subScenario: `watchOptions/with excludeDirectories option${additionalFlags.join("")}`,
commandLineArgs: ["-w", ...additionalFlags],
sys: () => sys({ excludeDirectories: ["node_modules"] }),
changes: [
{
caption: "delete fooBar",
change: sys => sys.deleteFile(`${projectRoot}/node_modules/bar/fooBar.d.ts`),
timeouts: sys => sys.checkTimeoutQueueLength(0), }
]
});
verifyTscWatch({
scenario,
subScenario: `watchOptions/with excludeDirectories option with recursive directory watching${additionalFlags.join("")}`,
commandLineArgs: ["-w", ...additionalFlags],
sys: () => sys({ excludeDirectories: ["**/temp"] }, /*runWithoutRecursiveWatches*/ true),
changes: [
{
caption: "Directory watch updates because of main.js creation",
change: noop,
timeouts: sys => {
sys.checkTimeoutQueueLengthAndRun(1); // To update directory callbacks for main.js output
sys.checkTimeoutQueueLength(0);
},
},
{
caption: "add new folder to temp",
change: sys => sys.ensureFileOrFolder({ path: `${projectRoot}/node_modules/bar/temp/fooBar/index.d.ts`, content: "export function temp(): string;" }),
timeouts: sys => sys.checkTimeoutQueueLength(0),
}
]
});
}
verifyWorker();
verifyWorker("-extendedDiagnostics");
});
});
verifyTscWatch({
scenario,
subScenario: `fsWatch/when using file watching thats when rename occurs when file is still on the disk`,
commandLineArgs: ["-w", "--extendedDiagnostics"],
sys: () => createWatchedSystem(
{
[libFile.path]: libFile.content,
[`${projectRoot}/main.ts`]: `import { foo } from "./foo"; foo();`,
[`${projectRoot}/foo.ts`]: `export declare function foo(): string;`,
[`${projectRoot}/tsconfig.json`]: JSON.stringify({
watchOptions: { watchFile: "useFsEvents" },
files: ["foo.ts", "main.ts"]
}),
},
{ currentDirectory: projectRoot, }
),
changes: [
{
caption: "Introduce error such that when callback happens file is already appeared",
// vm's wq generates this kind of event
// Skip delete event so inode changes but when the create's rename occurs file is on disk
change: sys => sys.modifyFile(`${projectRoot}/foo.ts`, `export declare function foo2(): string;`, {
invokeFileDeleteCreateAsPartInsteadOfChange: true,
ignoreDelete: true,
}),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
},
{
caption: "Replace file with rename event that fixes error",
change: sys => sys.modifyFile(`${projectRoot}/foo.ts`, `export declare function foo(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
},
]
});
describe("with fsWatch on inodes", () => {
verifyTscWatch({
scenario,
subScenario: `fsWatch/when using file watching thats on inode`,
commandLineArgs: ["-w", "--extendedDiagnostics"],
sys: () => createWatchedSystem(
{
[libFile.path]: libFile.content,
[`${projectRoot}/main.ts`]: `import { foo } from "./foo"; foo();`,
[`${projectRoot}/foo.d.ts`]: `export function foo(): string;`,
[`${projectRoot}/tsconfig.json`]: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
},
{
currentDirectory: projectRoot,
inodeWatching: true
}
),
changes: [
{
caption: "Replace file with rename event that introduces error",
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo2(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
},
{
caption: "Replace file with rename event that fixes error",
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
},
]
});
verifyTscWatch({
scenario,
subScenario: `fsWatch/when using file watching thats on inode when rename event ends with tilde`,
commandLineArgs: ["-w", "--extendedDiagnostics"],
sys: () => createWatchedSystem(
{
[libFile.path]: libFile.content,
[`${projectRoot}/main.ts`]: `import { foo } from "./foo"; foo();`,
[`${projectRoot}/foo.d.ts`]: `export function foo(): string;`,
[`${projectRoot}/tsconfig.json`]: JSON.stringify({ watchOptions: { watchFile: "useFsEvents" }, files: ["foo.d.ts", "main.ts"] }),
},
{
currentDirectory: projectRoot,
inodeWatching: true
}
),
changes: [
{
caption: "Replace file with rename event that introduces error",
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo2(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, useTildeAsSuffixInRenameEventFileName: true }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
},
{
caption: "Replace file with rename event that fixes error",
change: sys => sys.modifyFile(`${projectRoot}/foo.d.ts`, `export function foo(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, useTildeAsSuffixInRenameEventFileName: true }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(2),
},
]
});
verifyTscWatch({
scenario,
subScenario: `fsWatch/when using file watching thats on inode when rename occurs when file is still on the disk`,
commandLineArgs: ["-w", "--extendedDiagnostics"],
sys: () => createWatchedSystem(
{
[libFile.path]: libFile.content,
[`${projectRoot}/main.ts`]: `import { foo } from "./foo"; foo();`,
[`${projectRoot}/foo.ts`]: `export declare function foo(): string;`,
[`${projectRoot}/tsconfig.json`]: JSON.stringify({
watchOptions: { watchFile: "useFsEvents" },
files: ["foo.ts", "main.ts"]
}),
},
{
currentDirectory: projectRoot,
inodeWatching: true,
}
),
changes: [
{
caption: "Introduce error such that when callback happens file is already appeared",
// vm's wq generates this kind of event
// Skip delete event so inode changes but when the create's rename occurs file is on disk
change: sys => sys.modifyFile(`${projectRoot}/foo.ts`, `export declare function foo2(): string;`, {
invokeFileDeleteCreateAsPartInsteadOfChange: true,
ignoreDelete: true,
skipInodeCheckOnCreate: true
}),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
},
{
caption: "Replace file with rename event that fixes error",
change: sys => sys.modifyFile(`${projectRoot}/foo.ts`, `export declare function foo(): string;`, { invokeFileDeleteCreateAsPartInsteadOfChange: true, }),
timeouts: sys => sys.checkTimeoutQueueLengthAndRun(1),
},
]
});
});
verifyTscWatch({
scenario,
subScenario: "fsEvent for change is repeated",
commandLineArgs: ["-w", "main.ts", "--extendedDiagnostics"],
sys: () => createWatchedSystem({
"/user/username/projects/project/main.ts": `let a: string = "Hello"`,
[libFile.path]: libFile.content,
}, { currentDirectory: "/user/username/projects/project" }),
changes: [
{
caption: "change main.ts",
change: sys => replaceFileText(sys, "/user/username/projects/project/main.ts", "Hello", "Hello World"),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "receive another change event without modifying the file",
change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "change main.ts to empty text",
change: sys => sys.writeFile("/user/username/projects/project/main.ts", ""),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
},
{
caption: "receive another change event without modifying the file",
change: sys => sys.invokeFsWatches("/user/username/projects/project/main.ts", "change", /*modifiedTime*/ undefined, /*useTildeSuffix*/ undefined),
timeouts: sys => sys.runQueuedTimeoutCallbacks(),
}
]
});
});
}