@@ -103,4 +103,46 @@ suite("Swiftly Unit Tests", () => {
103
103
expect ( mockUtilities . execFile ) . not . have . been . called ;
104
104
} ) ;
105
105
} ) ;
106
+
107
+ suite ( "isInstalled" , ( ) => {
108
+ test ( "should return false when platform is not supported" , async ( ) => {
109
+ mockedPlatform . setValue ( "win32" ) ;
110
+
111
+ const result = await Swiftly . isInstalled ( ) ;
112
+
113
+ expect ( result ) . to . be . false ;
114
+ expect ( mockUtilities . execFile ) . not . have . been . called ;
115
+ } ) ;
116
+
117
+ test ( "should return true when swiftly is installed" , async ( ) => {
118
+ mockedPlatform . setValue ( "darwin" ) ;
119
+
120
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . resolves ( {
121
+ stdout : "1.1.0\n" ,
122
+ stderr : "" ,
123
+ } ) ;
124
+
125
+ const result = await Swiftly . isInstalled ( ) ;
126
+
127
+ expect ( result ) . to . be . true ;
128
+ expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [ "--version" ] ) ;
129
+ } ) ;
130
+
131
+ test ( "should throw error when swiftly command fails with non-ENOENT error" , async ( ) => {
132
+ mockedPlatform . setValue ( "darwin" ) ;
133
+
134
+ const otherError = new Error ( "Other error" ) ;
135
+
136
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "--version" ] ) . rejects ( otherError ) ;
137
+
138
+ try {
139
+ await Swiftly . isInstalled ( ) ;
140
+ expect . fail ( "Should have thrown an error" ) ;
141
+ } catch ( error ) {
142
+ expect ( error ) . to . equal ( otherError ) ;
143
+ }
144
+
145
+ expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [ "--version" ] ) ;
146
+ } ) ;
147
+ } ) ;
106
148
} ) ;
0 commit comments