@@ -20,13 +20,12 @@ namespace ts.projectSystem {
2020 }
2121
2222 class Installer extends TestTypingsInstaller {
23- constructor ( host : server . ServerHost , p ?: InstallerParams , telemetryEnabled ?: boolean , log ?: TI . Log ) {
23+ constructor ( host : server . ServerHost , p ?: InstallerParams , log ?: TI . Log ) {
2424 super (
2525 ( p && p . globalTypingsCacheLocation ) || "/a/data" ,
2626 ( p && p . throttleLimit ) || 5 ,
2727 host ,
2828 ( p && p . typesRegistry ) ,
29- telemetryEnabled ,
3029 log ) ;
3130 }
3231
@@ -36,7 +35,7 @@ namespace ts.projectSystem {
3635 }
3736 }
3837
39- function executeCommand ( self : Installer , host : TestServerHost , installedTypings : string [ ] , typingFiles : FileOrFolder [ ] , cb : TI . RequestCompletedAction ) : void {
38+ function executeCommand ( self : Installer , host : TestServerHost , installedTypings : string [ ] | string , typingFiles : FileOrFolder [ ] , cb : TI . RequestCompletedAction ) : void {
4039 self . addPostExecAction ( installedTypings , success => {
4140 for ( const file of typingFiles ) {
4241 host . createFileOrFolder ( file , /*createParentDirectory*/ true ) ;
@@ -907,7 +906,7 @@ namespace ts.projectSystem {
907906 const host = createServerHost ( [ f1 , packageJson ] ) ;
908907 const installer = new ( class extends Installer {
909908 constructor ( ) {
910- super ( host , { globalTypingsCacheLocation : "/tmp" } , /*telemetryEnabled*/ false , { isEnabled : ( ) => true , writeLine : msg => messages . push ( msg ) } ) ;
909+ super ( host , { globalTypingsCacheLocation : "/tmp" } , { isEnabled : ( ) => true , writeLine : msg => messages . push ( msg ) } ) ;
911910 }
912911 installWorker ( _requestId : number , _args : string [ ] , _cwd : string , _cb : server . typingsInstaller . RequestCompletedAction ) {
913912 assert ( false , "runCommand should not be invoked" ) ;
@@ -971,15 +970,18 @@ namespace ts.projectSystem {
971970 let seenTelemetryEvent = false ;
972971 const installer = new ( class extends Installer {
973972 constructor ( ) {
974- super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } , /*telemetryEnabled*/ true ) ;
973+ super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } ) ;
975974 }
976975 installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : server . typingsInstaller . RequestCompletedAction ) {
977976 const installedTypings = [ "@types/commander" ] ;
978977 const typingFiles = [ commander ] ;
979978 executeCommand ( this , host , installedTypings , typingFiles , cb ) ;
980979 }
981- sendResponse ( response : server . SetTypings | server . InvalidateCachedTypings | server . TypingsInstallEvent ) {
982- if ( response . kind === server . EventInstall ) {
980+ sendResponse ( response : server . SetTypings | server . InvalidateCachedTypings | server . BeginInstallTypes | server . EndInstallTypes ) {
981+ if ( response . kind === server . EventBeginInstallTypes ) {
982+ return ;
983+ }
984+ if ( response . kind === server . EventEndInstallTypes ) {
983985 assert . deepEqual ( response . packagesToInstall , [ "@types/commander" ] ) ;
984986 seenTelemetryEvent = true ;
985987 return ;
@@ -997,4 +999,102 @@ namespace ts.projectSystem {
997999 checkProjectActualFiles ( projectService . inferredProjects [ 0 ] , [ f1 . path , commander . path ] ) ;
9981000 } ) ;
9991001 } ) ;
1002+
1003+ describe ( "progress notifications" , ( ) => {
1004+ it ( "should be sent for success" , ( ) => {
1005+ const f1 = {
1006+ path : "/a/app.js" ,
1007+ content : ""
1008+ } ;
1009+ const package = {
1010+ path : "/a/package.json" ,
1011+ content : JSON . stringify ( { dependencies : { "commander" : "1.0.0" } } )
1012+ } ;
1013+ const cachePath = "/a/cache/" ;
1014+ const commander = {
1015+ path : cachePath + "node_modules/@types/commander/index.d.ts" ,
1016+ content : "export let x: number"
1017+ } ;
1018+ const host = createServerHost ( [ f1 , package ] ) ;
1019+ let beginEvent : server . BeginInstallTypes ;
1020+ let endEvent : server . EndInstallTypes ;
1021+ const installer = new ( class extends Installer {
1022+ constructor ( ) {
1023+ super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } ) ;
1024+ }
1025+ installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : server . typingsInstaller . RequestCompletedAction ) {
1026+ const installedTypings = [ "@types/commander" ] ;
1027+ const typingFiles = [ commander ] ;
1028+ executeCommand ( this , host , installedTypings , typingFiles , cb ) ;
1029+ }
1030+ sendResponse ( response : server . SetTypings | server . InvalidateCachedTypings | server . BeginInstallTypes | server . EndInstallTypes ) {
1031+ if ( response . kind === server . EventBeginInstallTypes ) {
1032+ beginEvent = response ;
1033+ return ;
1034+ }
1035+ if ( response . kind === server . EventEndInstallTypes ) {
1036+ endEvent = response ;
1037+ return ;
1038+ }
1039+ super . sendResponse ( response ) ;
1040+ }
1041+ } ) ( ) ;
1042+ const projectService = createProjectService ( host , { typingsInstaller : installer } ) ;
1043+ projectService . openClientFile ( f1 . path ) ;
1044+
1045+ installer . installAll ( /*expectedCount*/ 1 ) ;
1046+
1047+ assert . isTrue ( ! ! beginEvent ) ;
1048+ assert . isTrue ( ! ! endEvent ) ;
1049+ assert . isTrue ( beginEvent . eventId === endEvent . eventId ) ;
1050+ assert . isTrue ( endEvent . installSuccess ) ;
1051+ checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
1052+ checkProjectActualFiles ( projectService . inferredProjects [ 0 ] , [ f1 . path , commander . path ] ) ;
1053+ } ) ;
1054+
1055+ it ( "should be sent for error" , ( ) => {
1056+ const f1 = {
1057+ path : "/a/app.js" ,
1058+ content : ""
1059+ } ;
1060+ const package = {
1061+ path : "/a/package.json" ,
1062+ content : JSON . stringify ( { dependencies : { "commander" : "1.0.0" } } )
1063+ } ;
1064+ const cachePath = "/a/cache/" ;
1065+ const host = createServerHost ( [ f1 , package ] ) ;
1066+ let beginEvent : server . BeginInstallTypes ;
1067+ let endEvent : server . EndInstallTypes ;
1068+ const installer = new ( class extends Installer {
1069+ constructor ( ) {
1070+ super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } ) ;
1071+ }
1072+ installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : server . typingsInstaller . RequestCompletedAction ) {
1073+ executeCommand ( this , host , "" , [ ] , cb ) ;
1074+ }
1075+ sendResponse ( response : server . SetTypings | server . InvalidateCachedTypings | server . BeginInstallTypes | server . EndInstallTypes ) {
1076+ if ( response . kind === server . EventBeginInstallTypes ) {
1077+ beginEvent = response ;
1078+ return ;
1079+ }
1080+ if ( response . kind === server . EventEndInstallTypes ) {
1081+ endEvent = response ;
1082+ return ;
1083+ }
1084+ super . sendResponse ( response ) ;
1085+ }
1086+ } ) ( ) ;
1087+ const projectService = createProjectService ( host , { typingsInstaller : installer } ) ;
1088+ projectService . openClientFile ( f1 . path ) ;
1089+
1090+ installer . installAll ( /*expectedCount*/ 1 ) ;
1091+
1092+ assert . isTrue ( ! ! beginEvent ) ;
1093+ assert . isTrue ( ! ! endEvent ) ;
1094+ assert . isTrue ( beginEvent . eventId === endEvent . eventId ) ;
1095+ assert . isFalse ( endEvent . installSuccess ) ;
1096+ checkNumberOfProjects ( projectService , { inferredProjects : 1 } ) ;
1097+ checkProjectActualFiles ( projectService . inferredProjects [ 0 ] , [ f1 . path ] ) ;
1098+ } ) ;
1099+ } ) ;
10001100}
0 commit comments