1
1
/// <reference path="../harness.ts" />
2
2
/// <reference path="./tsserverProjectSystem.ts" />
3
3
/// <reference path="../../server/typingsInstaller/typingsInstaller.ts" />
4
+ /// <reference path="../mocks.ts" />
4
5
5
6
namespace ts . projectSystem {
6
7
import CommandNames = server . CommandNames ;
@@ -58,6 +59,24 @@ namespace ts.projectSystem {
58
59
// A compile on save affected file request using file1
59
60
let moduleFile1FileListRequest : server . protocol . Request ;
60
61
62
+ let sharedFs : vfs . VirtualFileSystem ;
63
+ before ( ( ) => {
64
+ const fs = new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ;
65
+ fs . addFile ( "/a/b/moduleFile1.ts" , `export function Foo() { };` ) ;
66
+ fs . addFile ( "/a/b/file1Consumer1.ts" , `import {Foo} from "./moduleFile1"; export var y = 10;` ) ;
67
+ fs . addFile ( "/a/b/file1Consumer2.ts" , `import {Foo} from "./moduleFile1"; let z = 10;` ) ;
68
+ fs . addFile ( "/a/b/globalFile3.ts" , `interface GlobalFoo { age: number }` ) ;
69
+ fs . addFile ( "/a/b/moduleFile2.ts" , `export var Foo4 = 10;` ) ;
70
+ fs . addFile ( "/a/b/tsconfig.json" , `{ compileOnSave": true }` ) ;
71
+ fs . addFile ( libFile . path , libFile . content ) ;
72
+ fs . makeReadOnly ( ) ;
73
+ sharedFs = fs ;
74
+ } ) ;
75
+
76
+ after ( ( ) => {
77
+ sharedFs = undefined ;
78
+ } ) ;
79
+
61
80
beforeEach ( ( ) => {
62
81
moduleFile1 = {
63
82
path : "/a/b/moduleFile1.ts" ,
@@ -115,7 +134,7 @@ namespace ts.projectSystem {
115
134
} ) ;
116
135
117
136
it ( "should contains only itself if a module file's shape didn't change, and all files referencing it if its shape changed" , ( ) => {
118
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
137
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
119
138
const typingsInstaller = createTestTypingsInstaller ( host ) ;
120
139
const session = createSession ( host , typingsInstaller ) ;
121
140
@@ -140,7 +159,7 @@ namespace ts.projectSystem {
140
159
} ) ;
141
160
142
161
it ( "should be up-to-date with the reference map changes" , ( ) => {
143
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
162
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
144
163
const typingsInstaller = createTestTypingsInstaller ( host ) ;
145
164
const session = createSession ( host , typingsInstaller ) ;
146
165
@@ -187,7 +206,7 @@ namespace ts.projectSystem {
187
206
} ) ;
188
207
189
208
it ( "should be up-to-date with changes made in non-open files" , ( ) => {
190
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
209
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
191
210
const typingsInstaller = createTestTypingsInstaller ( host ) ;
192
211
const session = createSession ( host , typingsInstaller ) ;
193
212
@@ -196,29 +215,28 @@ namespace ts.projectSystem {
196
215
// Send an initial compileOnSave request
197
216
sendAffectedFileRequestAndCheckResult ( session , moduleFile1FileListRequest , [ { projectFileName : configFile . path , files : [ moduleFile1 , file1Consumer1 , file1Consumer2 ] } ] ) ;
198
217
199
- file1Consumer1 . content = `let y = 10;` ;
200
- host . reloadFS ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , configFile , libFile ] ) ;
201
-
218
+ host . vfs . writeFile ( file1Consumer1 . path , `let y = 10;` ) ;
202
219
session . executeCommand ( changeModuleFile1ShapeRequest1 ) ;
203
220
sendAffectedFileRequestAndCheckResult ( session , moduleFile1FileListRequest , [ { projectFileName : configFile . path , files : [ moduleFile1 , file1Consumer2 ] } ] ) ;
204
221
} ) ;
205
222
206
223
it ( "should be up-to-date with deleted files" , ( ) => {
207
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
224
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
208
225
const typingsInstaller = createTestTypingsInstaller ( host ) ;
209
226
const session = createSession ( host , typingsInstaller ) ;
210
227
211
228
openFilesForSession ( [ moduleFile1 ] , session ) ;
212
229
sendAffectedFileRequestAndCheckResult ( session , moduleFile1FileListRequest , [ { projectFileName : configFile . path , files : [ moduleFile1 , file1Consumer1 , file1Consumer2 ] } ] ) ;
213
230
214
231
session . executeCommand ( changeModuleFile1ShapeRequest1 ) ;
215
- // Delete file1Consumer2
216
- host . reloadFS ( [ moduleFile1 , file1Consumer1 , configFile , libFile ] ) ;
232
+
233
+ host . vfs . removeFile ( file1Consumer2 . path ) ;
234
+
217
235
sendAffectedFileRequestAndCheckResult ( session , moduleFile1FileListRequest , [ { projectFileName : configFile . path , files : [ moduleFile1 , file1Consumer1 ] } ] ) ;
218
236
} ) ;
219
237
220
238
it ( "should be up-to-date with newly created files" , ( ) => {
221
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
239
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
222
240
const typingsInstaller = createTestTypingsInstaller ( host ) ;
223
241
const session = createSession ( host , typingsInstaller ) ;
224
242
@@ -229,8 +247,7 @@ namespace ts.projectSystem {
229
247
path : "/a/b/file1Consumer3.ts" ,
230
248
content : `import {Foo} from "./moduleFile1"; let y = Foo();`
231
249
} ;
232
- host . reloadFS ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , file1Consumer3 , globalFile3 , configFile , libFile ] ) ;
233
- host . runQueuedTimeoutCallbacks ( ) ;
250
+ host . vfs . writeFile ( file1Consumer3 . path , file1Consumer3 . content ) ;
234
251
session . executeCommand ( changeModuleFile1ShapeRequest1 ) ;
235
252
sendAffectedFileRequestAndCheckResult ( session , moduleFile1FileListRequest , [ { projectFileName : configFile . path , files : [ moduleFile1 , file1Consumer1 , file1Consumer2 , file1Consumer3 ] } ] ) ;
236
253
} ) ;
@@ -254,7 +271,12 @@ namespace ts.projectSystem {
254
271
}`
255
272
} ;
256
273
257
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , configFile , libFile ] ) ;
274
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
275
+ host . vfs . addFile ( moduleFile1 . path , moduleFile1 . content ) ;
276
+ host . vfs . addFile ( file1Consumer1 . path , file1Consumer1 . content ) ;
277
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
278
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
279
+
258
280
const typingsInstaller = createTestTypingsInstaller ( host ) ;
259
281
const session = createSession ( host , typingsInstaller ) ;
260
282
@@ -271,7 +293,7 @@ namespace ts.projectSystem {
271
293
} ) ;
272
294
273
295
it ( "should return all files if a global file changed shape" , ( ) => {
274
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , globalFile3 , moduleFile2 , configFile , libFile ] ) ;
296
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
275
297
const typingsInstaller = createTestTypingsInstaller ( host ) ;
276
298
const session = createSession ( host , typingsInstaller ) ;
277
299
@@ -297,7 +319,8 @@ namespace ts.projectSystem {
297
319
content : `{}`
298
320
} ;
299
321
300
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , configFile , libFile ] ) ;
322
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
323
+ host . vfs . writeFile ( configFile . path , configFile . content ) ;
301
324
const typingsInstaller = createTestTypingsInstaller ( host ) ;
302
325
const session = createSession ( host , typingsInstaller ) ;
303
326
openFilesForSession ( [ moduleFile1 ] , session ) ;
@@ -319,7 +342,10 @@ namespace ts.projectSystem {
319
342
}`
320
343
} ;
321
344
322
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer2 , configFile2 , configFile , libFile ] ) ;
345
+ const host = new mocks . MockServerHost ( sharedFs . shadow ( ) ) ;
346
+ host . vfs . writeFile ( configFile . path , configFile . content ) ;
347
+ host . vfs . addFile ( configFile2 . path , configFile2 . content ) ;
348
+
323
349
const typingsInstaller = createTestTypingsInstaller ( host ) ;
324
350
const session = createSession ( host , typingsInstaller ) ;
325
351
@@ -338,7 +364,12 @@ namespace ts.projectSystem {
338
364
}`
339
365
} ;
340
366
341
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , configFile , libFile ] ) ;
367
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
368
+ host . vfs . addFile ( moduleFile1 . path , moduleFile1 . content ) ;
369
+ host . vfs . addFile ( file1Consumer1 . path , file1Consumer1 . content ) ;
370
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
371
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
372
+
342
373
const typingsInstaller = createTestTypingsInstaller ( host ) ;
343
374
const session = createSession ( host , typingsInstaller ) ;
344
375
openFilesForSession ( [ moduleFile1 ] , session ) ;
@@ -367,7 +398,12 @@ namespace ts.projectSystem {
367
398
}`
368
399
} ;
369
400
370
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , configFile , libFile ] ) ;
401
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
402
+ host . vfs . addFile ( moduleFile1 . path , moduleFile1 . content ) ;
403
+ host . vfs . addFile ( file1Consumer1 . path , file1Consumer1 . content ) ;
404
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
405
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
406
+
371
407
const typingsInstaller = createTestTypingsInstaller ( host ) ;
372
408
const session = createSession ( host , typingsInstaller ) ;
373
409
openFilesForSession ( [ moduleFile1 ] , session ) ;
@@ -389,7 +425,16 @@ namespace ts.projectSystem {
389
425
path : "/a/b/file1Consumer1Consumer1.ts" ,
390
426
content : `import {y} from "./file1Consumer1";`
391
427
} ;
392
- const host = createServerHost ( [ moduleFile1 , file1Consumer1 , file1Consumer1Consumer1 , globalFile3 , configFile , libFile ] ) ;
428
+
429
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
430
+ host . vfs . addFile ( moduleFile1 . path , moduleFile1 . content ) ;
431
+ host . vfs . addFile ( file1Consumer1 . path , file1Consumer1 . content ) ;
432
+ host . vfs . addFile ( file1Consumer1Consumer1 . path , file1Consumer1Consumer1 . content ) ;
433
+ host . vfs . addFile ( globalFile3 . path , globalFile3 . content ) ;
434
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
435
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
436
+ host . vfs . addFile ( file1Consumer1Consumer1 . path , file1Consumer1Consumer1 . content ) ;
437
+
393
438
const typingsInstaller = createTestTypingsInstaller ( host ) ;
394
439
const session = createSession ( host , typingsInstaller ) ;
395
440
@@ -422,7 +467,12 @@ namespace ts.projectSystem {
422
467
/// <reference path="./file1.ts" />
423
468
export var t2 = 10;`
424
469
} ;
425
- const host = createServerHost ( [ file1 , file2 , configFile ] ) ;
470
+
471
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
472
+ host . vfs . addFile ( file1 . path , file1 . content ) ;
473
+ host . vfs . addFile ( file2 . path , file2 . content ) ;
474
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
475
+
426
476
const typingsInstaller = createTestTypingsInstaller ( host ) ;
427
477
const session = createSession ( host , typingsInstaller ) ;
428
478
@@ -438,7 +488,13 @@ namespace ts.projectSystem {
438
488
const configFile1 : FileOrFolder = { path : "/a/b/tsconfig.json" , content : `{ "compileOnSave": true }` } ;
439
489
const configFile2 : FileOrFolder = { path : "/a/c/tsconfig.json" , content : `{ "compileOnSave": true }` } ;
440
490
441
- const host = createServerHost ( [ file1 , file2 , file3 , configFile1 , configFile2 ] ) ;
491
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
492
+ host . vfs . addFile ( file1 . path , file1 . content ) ;
493
+ host . vfs . addFile ( file2 . path , file2 . content ) ;
494
+ host . vfs . addFile ( file3 . path , file3 . content ) ;
495
+ host . vfs . addFile ( configFile1 . path , configFile1 . content ) ;
496
+ host . vfs . addFile ( configFile2 . path , configFile2 . content ) ;
497
+
442
498
const session = createSession ( host ) ;
443
499
444
500
openFilesForSession ( [ file1 , file2 , file3 ] , session ) ;
@@ -457,16 +513,23 @@ namespace ts.projectSystem {
457
513
/// <reference path="./moduleFile1.ts" />
458
514
export var x = Foo();`
459
515
} ;
460
- const host = createServerHost ( [ moduleFile1 , referenceFile1 , configFile ] ) ;
516
+
517
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
518
+ host . vfs . addFile ( moduleFile1 . path , moduleFile1 . content ) ;
519
+ host . vfs . addFile ( referenceFile1 . path , referenceFile1 . content ) ;
520
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
521
+
461
522
const session = createSession ( host ) ;
462
523
463
524
openFilesForSession ( [ referenceFile1 ] , session ) ;
464
- host . reloadFS ( [ referenceFile1 , configFile ] ) ;
525
+
526
+ host . vfs . removeFile ( moduleFile1 . path ) ;
465
527
466
528
const request = makeSessionRequest < server . protocol . FileRequestArgs > ( CommandNames . CompileOnSaveAffectedFileList , { file : referenceFile1 . path } ) ;
467
529
sendAffectedFileRequestAndCheckResult ( session , request , [
468
530
{ projectFileName : configFile . path , files : [ referenceFile1 ] }
469
531
] ) ;
532
+
470
533
const requestForMissingFile = makeSessionRequest < server . protocol . FileRequestArgs > ( CommandNames . CompileOnSaveAffectedFileList , { file : moduleFile1 . path } ) ;
471
534
sendAffectedFileRequestAndCheckResult ( session , requestForMissingFile , [ ] ) ;
472
535
} ) ;
@@ -478,10 +541,15 @@ namespace ts.projectSystem {
478
541
/// <reference path="./moduleFile2.ts" />
479
542
export var x = Foo();`
480
543
} ;
481
- const host = createServerHost ( [ referenceFile1 , configFile ] ) ;
544
+
545
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
546
+ host . vfs . addFile ( referenceFile1 . path , referenceFile1 . content ) ;
547
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
548
+
482
549
const session = createSession ( host ) ;
483
550
484
551
openFilesForSession ( [ referenceFile1 ] , session ) ;
552
+
485
553
const request = makeSessionRequest < server . protocol . FileRequestArgs > ( CommandNames . CompileOnSaveAffectedFileList , { file : referenceFile1 . path } ) ;
486
554
sendAffectedFileRequestAndCheckResult ( session , request , [
487
555
{ projectFileName : configFile . path , files : [ referenceFile1 ] }
@@ -502,7 +570,10 @@ namespace ts.projectSystem {
502
570
path : path + ts . Extension . Ts ,
503
571
content : lines . join ( newLine )
504
572
} ;
505
- const host = createServerHost ( [ f ] , { newLine } ) ;
573
+
574
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) , /*executingFilePath*/ undefined , newLine ) ;
575
+ host . vfs . addFile ( f . path , f . content ) ;
576
+
506
577
const session = createSession ( host ) ;
507
578
const openRequest : server . protocol . OpenRequest = {
508
579
seq : 1 ,
@@ -536,7 +607,13 @@ namespace ts.projectSystem {
536
607
path : "/a/b/tsconfig.json" ,
537
608
content : `{}`
538
609
} ;
539
- const host = createServerHost ( [ file1 , file2 , configFile , libFile ] , { newLine : "\r\n" } ) ;
610
+
611
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) , /*executingFilePath*/ undefined , "\r\n" ) ;
612
+ host . vfs . addFile ( file1 . path , file1 . content ) ;
613
+ host . vfs . addFile ( file2 . path , file2 . content ) ;
614
+ host . vfs . addFile ( configFile . path , configFile . content ) ;
615
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
616
+
540
617
const typingsInstaller = createTestTypingsInstaller ( host ) ;
541
618
const session = createSession ( host , { typingsInstaller } ) ;
542
619
@@ -564,7 +641,13 @@ namespace ts.projectSystem {
564
641
content : "console.log('file3');"
565
642
} ;
566
643
const externalProjectName = "/a/b/externalproject" ;
567
- const host = createServerHost ( [ file1 , file2 , file3 , libFile ] ) ;
644
+
645
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
646
+ host . vfs . addFile ( file1 . path , file1 . content ) ;
647
+ host . vfs . addFile ( file2 . path , file2 . content ) ;
648
+ host . vfs . addFile ( file3 . path , file3 . content ) ;
649
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
650
+
568
651
const session = createSession ( host ) ;
569
652
const projectService = session . getProjectService ( ) ;
570
653
@@ -596,7 +679,11 @@ namespace ts.projectSystem {
596
679
content : "consonle.log('file1');"
597
680
} ;
598
681
const externalProjectName = "/root/TypeScriptProject3/TypeScriptProject3/TypeScriptProject3.csproj" ;
599
- const host = createServerHost ( [ file1 , libFile ] ) ;
682
+
683
+ const host = new mocks . MockServerHost ( new vfs . VirtualFileSystem ( "/" , /*useCaseSensitiveFileNames*/ true ) ) ;
684
+ host . vfs . addFile ( file1 . path , file1 . content ) ;
685
+ host . vfs . addFile ( libFile . path , libFile . content ) ;
686
+
600
687
const session = createSession ( host ) ;
601
688
const projectService = session . getProjectService ( ) ;
602
689
0 commit comments