@@ -20,13 +20,12 @@ namespace ts.projectSystem {
20
20
}
21
21
22
22
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 ) {
24
24
super (
25
25
( p && p . globalTypingsCacheLocation ) || "/a/data" ,
26
26
( p && p . throttleLimit ) || 5 ,
27
27
host ,
28
28
( p && p . typesRegistry ) ,
29
- telemetryEnabled ,
30
29
log ) ;
31
30
}
32
31
@@ -36,7 +35,7 @@ namespace ts.projectSystem {
36
35
}
37
36
}
38
37
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 {
40
39
self . addPostExecAction ( installedTypings , success => {
41
40
for ( const file of typingFiles ) {
42
41
host . createFileOrFolder ( file , /*createParentDirectory*/ true ) ;
@@ -907,7 +906,7 @@ namespace ts.projectSystem {
907
906
const host = createServerHost ( [ f1 , packageJson ] ) ;
908
907
const installer = new ( class extends Installer {
909
908
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 ) } ) ;
911
910
}
912
911
installWorker ( _requestId : number , _args : string [ ] , _cwd : string , _cb : server . typingsInstaller . RequestCompletedAction ) {
913
912
assert ( false , "runCommand should not be invoked" ) ;
@@ -971,15 +970,18 @@ namespace ts.projectSystem {
971
970
let seenTelemetryEvent = false ;
972
971
const installer = new ( class extends Installer {
973
972
constructor ( ) {
974
- super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } , /*telemetryEnabled*/ true ) ;
973
+ super ( host , { globalTypingsCacheLocation : cachePath , typesRegistry : createTypesRegistry ( "commander" ) } ) ;
975
974
}
976
975
installWorker ( _requestId : number , _args : string [ ] , _cwd : string , cb : server . typingsInstaller . RequestCompletedAction ) {
977
976
const installedTypings = [ "@types/commander" ] ;
978
977
const typingFiles = [ commander ] ;
979
978
executeCommand ( this , host , installedTypings , typingFiles , cb ) ;
980
979
}
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 ) {
983
985
assert . deepEqual ( response . packagesToInstall , [ "@types/commander" ] ) ;
984
986
seenTelemetryEvent = true ;
985
987
return ;
@@ -997,4 +999,102 @@ namespace ts.projectSystem {
997
999
checkProjectActualFiles ( projectService . inferredProjects [ 0 ] , [ f1 . path , commander . path ] ) ;
998
1000
} ) ;
999
1001
} ) ;
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
+ } ) ;
1000
1100
}
0 commit comments