@@ -3445,6 +3445,117 @@ namespace ts.projectSystem {
3445
3445
diags = session . executeCommand ( getErrRequest ) . response as server . protocol . Diagnostic [ ] ;
3446
3446
verifyNoDiagnostics ( diags ) ;
3447
3447
} ) ;
3448
+
3449
+ function assertEvent ( actualOutput : string , expectedEvent : protocol . Event , host : TestServerHost ) {
3450
+ assert . equal ( actualOutput , server . formatMessage ( expectedEvent , nullLogger , Utils . byteLength , host . newLine ) ) ;
3451
+ }
3452
+
3453
+ function checkErrorMessage ( host : TestServerHost , eventName : "syntaxDiag" | "semanticDiag" , diagnostics : protocol . DiagnosticEventBody ) {
3454
+ const outputs = host . getOutput ( ) ;
3455
+ assert . isTrue ( outputs . length >= 1 , outputs . toString ( ) ) ;
3456
+ const event : protocol . Event = {
3457
+ seq : 0 ,
3458
+ type : "event" ,
3459
+ event : eventName ,
3460
+ body : diagnostics
3461
+ } ;
3462
+ assertEvent ( outputs [ 0 ] , event , host ) ;
3463
+ }
3464
+
3465
+ function checkCompleteEvent ( host : TestServerHost , numberOfCurrentEvents : number , expectedSequenceId : number ) {
3466
+ const outputs = host . getOutput ( ) ;
3467
+ assert . equal ( outputs . length , numberOfCurrentEvents , outputs . toString ( ) ) ;
3468
+ const event : protocol . RequestCompletedEvent = {
3469
+ seq : 0 ,
3470
+ type : "event" ,
3471
+ event : "requestCompleted" ,
3472
+ body : {
3473
+ request_seq : expectedSequenceId
3474
+ }
3475
+ } ;
3476
+ assertEvent ( outputs [ numberOfCurrentEvents - 1 ] , event , host ) ;
3477
+ }
3478
+
3479
+ function checkProjectUpdatedInBackgroundEvent ( host : TestServerHost , openFiles : string [ ] ) {
3480
+ const outputs = host . getOutput ( ) ;
3481
+ assert . equal ( outputs . length , 1 , outputs . toString ( ) ) ;
3482
+ const event : protocol . ProjectsUpdatedInBackgroundEvent = {
3483
+ seq : 0 ,
3484
+ type : "event" ,
3485
+ event : "projectsUpdatedInBackground" ,
3486
+ body : {
3487
+ openFiles
3488
+ }
3489
+ } ;
3490
+ assertEvent ( outputs [ 0 ] , event , host ) ;
3491
+ }
3492
+
3493
+ it ( "npm install @types works" , ( ) => {
3494
+ const folderPath = "/a/b/projects/temp" ;
3495
+ const file1 : FileOrFolder = {
3496
+ path : `${ folderPath } /a.ts` ,
3497
+ content : 'import f = require("pad")'
3498
+ } ;
3499
+ const files = [ file1 , libFile ] ;
3500
+ const host = createServerHost ( files ) ;
3501
+ const session = createSession ( host , { canUseEvents : true } ) ;
3502
+ const service = session . getProjectService ( ) ;
3503
+ session . executeCommandSeq < protocol . OpenRequest > ( {
3504
+ command : server . CommandNames . Open ,
3505
+ arguments : {
3506
+ file : file1 . path ,
3507
+ fileContent : file1 . content ,
3508
+ scriptKindName : "TS" ,
3509
+ projectRootPath : folderPath
3510
+ }
3511
+ } ) ;
3512
+ checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
3513
+ host . clearOutput ( ) ;
3514
+ const expectedSequenceId = session . getNextSeq ( ) ;
3515
+ session . executeCommandSeq < protocol . GeterrRequest > ( {
3516
+ command : server . CommandNames . Geterr ,
3517
+ arguments : {
3518
+ delay : 0 ,
3519
+ files : [ file1 . path ]
3520
+ }
3521
+ } ) ;
3522
+
3523
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ;
3524
+ checkErrorMessage ( host , "syntaxDiag" , { file : file1 . path , diagnostics : [ ] } ) ;
3525
+ host . clearOutput ( ) ;
3526
+
3527
+ host . runQueuedImmediateCallbacks ( ) ;
3528
+ const moduleNotFound = Diagnostics . Cannot_find_module_0 ;
3529
+ const startOffset = file1 . content . indexOf ( '"' ) + 1 ;
3530
+ checkErrorMessage ( host , "semanticDiag" , {
3531
+ file : file1 . path , diagnostics : [ {
3532
+ start : { line : 1 , offset : startOffset } ,
3533
+ end : { line : 1 , offset : startOffset + '"pad"' . length } ,
3534
+ text : formatStringFromArgs ( moduleNotFound . message , [ "pad" ] ) ,
3535
+ code : moduleNotFound . code ,
3536
+ category : DiagnosticCategory [ moduleNotFound . category ] . toLowerCase ( )
3537
+ } ]
3538
+ } ) ;
3539
+ checkCompleteEvent ( host , 2 , expectedSequenceId ) ;
3540
+ host . clearOutput ( ) ;
3541
+
3542
+ const padIndex : FileOrFolder = {
3543
+ path : `${ folderPath } /node_modules/@types/pad/index.d.ts` ,
3544
+ content : "export = pad;declare function pad(length: number, text: string, char ?: string): string;"
3545
+ } ;
3546
+ files . push ( padIndex ) ;
3547
+ host . reloadFS ( files , { ignoreWatchInvokedWithTriggerAsFileCreate : true } ) ;
3548
+ host . runQueuedTimeoutCallbacks ( ) ;
3549
+ checkProjectUpdatedInBackgroundEvent ( host , [ file1 . path ] ) ;
3550
+ host . clearOutput ( ) ;
3551
+
3552
+ host . runQueuedTimeoutCallbacks ( ) ;
3553
+ checkErrorMessage ( host , "syntaxDiag" , { file : file1 . path , diagnostics : [ ] } ) ;
3554
+ host . clearOutput ( ) ;
3555
+
3556
+ host . runQueuedImmediateCallbacks ( ) ;
3557
+ checkErrorMessage ( host , "semanticDiag" , { file : file1 . path , diagnostics : [ ] } ) ;
3558
+ } ) ;
3448
3559
} ) ;
3449
3560
3450
3561
describe ( "Configure file diagnostics events" , ( ) => {
0 commit comments