@@ -93,6 +93,41 @@ describe('getCacheDirectoryPath', () => {
93
93
. then ( data => expect ( data ) . toEqual ( expectedResult ) ) ;
94
94
} ) ;
95
95
96
+ it ( 'should return path to the cache folder if one command return empty str' , async ( ) => {
97
+ //Arrange
98
+ getExecOutputSpy . mockImplementationOnce ( ( commandLine : string ) => {
99
+ return new Promise < exec . ExecOutput > ( resolve => {
100
+ resolve ( { exitCode : 0 , stdout : 'path/to/cache/folder' , stderr : '' } ) ;
101
+ } ) ;
102
+ } ) ;
103
+
104
+ getExecOutputSpy . mockImplementationOnce ( ( commandLine : string ) => {
105
+ return new Promise < exec . ExecOutput > ( resolve => {
106
+ resolve ( { exitCode : 0 , stdout : '' , stderr : '' } ) ;
107
+ } ) ;
108
+ } ) ;
109
+
110
+ const expectedResult = [ 'path/to/cache/folder' ] ;
111
+
112
+ //Act + Assert
113
+ return cacheUtils
114
+ . getCacheDirectoryPath ( validPackageManager )
115
+ . then ( data => expect ( data ) . toEqual ( expectedResult ) ) ;
116
+ } ) ;
117
+
118
+ it ( 'should throw if the both commands return empty str' , async ( ) => {
119
+ getExecOutputSpy . mockImplementation ( ( commandLine : string ) => {
120
+ return new Promise < exec . ExecOutput > ( resolve => {
121
+ resolve ( { exitCode : 10 , stdout : '' , stderr : '' } ) ;
122
+ } ) ;
123
+ } ) ;
124
+
125
+ //Act + Assert
126
+ expect ( async ( ) => {
127
+ await cacheUtils . getCacheDirectoryPath ( validPackageManager ) ;
128
+ } ) . rejects . toThrow ( ) ;
129
+ } ) ;
130
+
96
131
it ( 'should throw if the specified package name is invalid' , async ( ) => {
97
132
getExecOutputSpy . mockImplementation ( ( commandLine : string ) => {
98
133
return new Promise < exec . ExecOutput > ( resolve => {
@@ -162,18 +197,19 @@ describe('isCacheFeatureAvailable', () => {
162
197
expect ( functionResult ) . toBeFalsy ( ) ;
163
198
} ) ;
164
199
165
- it ( 'should throw when cache feature is unavailable and GHES is used' , ( ) => {
200
+ it ( 'should warn when cache feature is unavailable and GHES is used' , ( ) => {
166
201
//Arrange
167
202
isFeatureAvailableSpy . mockImplementation ( ( ) => {
168
203
return false ;
169
204
} ) ;
170
205
171
206
process . env [ 'GITHUB_SERVER_URL' ] = 'https://nongithub.com' ;
172
207
173
- let errorMessage =
208
+ let warningMessage =
174
209
'Cache action is only supported on GHES version >= 3.5. If you are on version >=3.5 Please check with GHES admin if Actions cache service is enabled or not.' ;
175
210
176
211
//Act + Assert
177
- expect ( ( ) => cacheUtils . isCacheFeatureAvailable ( ) ) . toThrow ( errorMessage ) ;
212
+ expect ( cacheUtils . isCacheFeatureAvailable ( ) ) . toBeFalsy ( ) ;
213
+ expect ( warningSpy ) . toHaveBeenCalledWith ( warningMessage ) ;
178
214
} ) ;
179
215
} ) ;
0 commit comments