@@ -92,6 +92,9 @@ describe('run', () => {
92
92
93
93
it ( 'Package manager is not valid, skip caching' , async ( ) => {
94
94
inputs [ 'cache' ] = 'yarn3' ;
95
+ getStateSpy . mockImplementation ( key =>
96
+ key === State . CachePackageManager ? inputs [ 'cache' ] : ''
97
+ ) ;
95
98
96
99
await run ( ) ;
97
100
@@ -108,7 +111,9 @@ describe('run', () => {
108
111
it ( 'should not save cache for yarn1' , async ( ) => {
109
112
inputs [ 'cache' ] = 'yarn' ;
110
113
getStateSpy . mockImplementation ( key =>
111
- key === State . CachePrimaryKey || key === State . CacheMatchedKey
114
+ key === State . CachePackageManager
115
+ ? inputs [ 'cache' ]
116
+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
112
117
? yarnFileHash
113
118
: key === State . CachePaths
114
119
? '["/foo/bar"]'
@@ -117,8 +122,8 @@ describe('run', () => {
117
122
118
123
await run ( ) ;
119
124
120
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
121
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
125
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
126
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
122
127
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
123
128
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
124
129
expect ( infoSpy ) . toHaveBeenCalledWith (
@@ -130,7 +135,9 @@ describe('run', () => {
130
135
it ( 'should not save cache for yarn2' , async ( ) => {
131
136
inputs [ 'cache' ] = 'yarn' ;
132
137
getStateSpy . mockImplementation ( key =>
133
- key === State . CachePrimaryKey || key === State . CacheMatchedKey
138
+ key === State . CachePackageManager
139
+ ? inputs [ 'cache' ]
140
+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
134
141
? yarnFileHash
135
142
: key === State . CachePaths
136
143
? '["/foo/bar"]'
@@ -139,8 +146,8 @@ describe('run', () => {
139
146
140
147
await run ( ) ;
141
148
142
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
143
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
149
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
150
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
144
151
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
145
152
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
146
153
expect ( infoSpy ) . toHaveBeenCalledWith (
@@ -152,7 +159,9 @@ describe('run', () => {
152
159
it ( 'should not save cache for npm' , async ( ) => {
153
160
inputs [ 'cache' ] = 'npm' ;
154
161
getStateSpy . mockImplementation ( key =>
155
- key === State . CachePrimaryKey || key === State . CacheMatchedKey
162
+ key === State . CachePackageManager
163
+ ? inputs [ 'cache' ]
164
+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
156
165
? yarnFileHash
157
166
: key === State . CachePaths
158
167
? '["/foo/bar"]'
@@ -162,8 +171,8 @@ describe('run', () => {
162
171
163
172
await run ( ) ;
164
173
165
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
166
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
174
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
175
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
167
176
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
168
177
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
169
178
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
@@ -172,7 +181,9 @@ describe('run', () => {
172
181
it ( 'should not save cache for pnpm' , async ( ) => {
173
182
inputs [ 'cache' ] = 'pnpm' ;
174
183
getStateSpy . mockImplementation ( key =>
175
- key === State . CachePrimaryKey || key === State . CacheMatchedKey
184
+ key === State . CachePackageManager
185
+ ? inputs [ 'cache' ]
186
+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
176
187
? yarnFileHash
177
188
: key === State . CachePaths
178
189
? '["/foo/bar"]'
@@ -181,8 +192,8 @@ describe('run', () => {
181
192
182
193
await run ( ) ;
183
194
184
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
185
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
195
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
196
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
186
197
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
187
198
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
188
199
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
@@ -193,7 +204,9 @@ describe('run', () => {
193
204
it ( 'saves cache from yarn 1' , async ( ) => {
194
205
inputs [ 'cache' ] = 'yarn' ;
195
206
getStateSpy . mockImplementation ( ( key : string ) =>
196
- key === State . CacheMatchedKey
207
+ key === State . CachePackageManager
208
+ ? inputs [ 'cache' ]
209
+ : key === State . CacheMatchedKey
197
210
? yarnFileHash
198
211
: key === State . CachePrimaryKey
199
212
? npmFileHash
@@ -204,8 +217,8 @@ describe('run', () => {
204
217
205
218
await run ( ) ;
206
219
207
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
208
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
220
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
221
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
209
222
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
210
223
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
211
224
expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -221,7 +234,9 @@ describe('run', () => {
221
234
it ( 'saves cache from yarn 2' , async ( ) => {
222
235
inputs [ 'cache' ] = 'yarn' ;
223
236
getStateSpy . mockImplementation ( ( key : string ) =>
224
- key === State . CacheMatchedKey
237
+ key === State . CachePackageManager
238
+ ? inputs [ 'cache' ]
239
+ : key === State . CacheMatchedKey
225
240
? yarnFileHash
226
241
: key === State . CachePrimaryKey
227
242
? npmFileHash
@@ -232,8 +247,8 @@ describe('run', () => {
232
247
233
248
await run ( ) ;
234
249
235
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
236
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
250
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
251
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
237
252
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
238
253
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
239
254
expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -249,7 +264,9 @@ describe('run', () => {
249
264
it ( 'saves cache from npm' , async ( ) => {
250
265
inputs [ 'cache' ] = 'npm' ;
251
266
getStateSpy . mockImplementation ( ( key : string ) =>
252
- key === State . CacheMatchedKey
267
+ key === State . CachePackageManager
268
+ ? inputs [ 'cache' ]
269
+ : key === State . CacheMatchedKey
253
270
? npmFileHash
254
271
: key === State . CachePrimaryKey
255
272
? yarnFileHash
@@ -260,8 +277,8 @@ describe('run', () => {
260
277
261
278
await run ( ) ;
262
279
263
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
264
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
280
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
281
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
265
282
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
266
283
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
267
284
expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -277,7 +294,9 @@ describe('run', () => {
277
294
it ( 'saves cache from pnpm' , async ( ) => {
278
295
inputs [ 'cache' ] = 'pnpm' ;
279
296
getStateSpy . mockImplementation ( ( key : string ) =>
280
- key === State . CacheMatchedKey
297
+ key === State . CachePackageManager
298
+ ? inputs [ 'cache' ]
299
+ : key === State . CacheMatchedKey
281
300
? pnpmFileHash
282
301
: key === State . CachePrimaryKey
283
302
? npmFileHash
@@ -288,8 +307,8 @@ describe('run', () => {
288
307
289
308
await run ( ) ;
290
309
291
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
292
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
310
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
311
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
293
312
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
294
313
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
295
314
expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -305,7 +324,9 @@ describe('run', () => {
305
324
it ( 'save with -1 cacheId , should not fail workflow' , async ( ) => {
306
325
inputs [ 'cache' ] = 'npm' ;
307
326
getStateSpy . mockImplementation ( ( key : string ) =>
308
- key === State . CacheMatchedKey
327
+ key === State . CachePackageManager
328
+ ? inputs [ 'cache' ]
329
+ : key === State . CacheMatchedKey
309
330
? npmFileHash
310
331
: key === State . CachePrimaryKey
311
332
? yarnFileHash
@@ -319,8 +340,8 @@ describe('run', () => {
319
340
320
341
await run ( ) ;
321
342
322
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
323
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
343
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
344
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
324
345
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
325
346
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
326
347
expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -336,7 +357,9 @@ describe('run', () => {
336
357
it ( 'saves with error from toolkit, should fail workflow' , async ( ) => {
337
358
inputs [ 'cache' ] = 'npm' ;
338
359
getStateSpy . mockImplementation ( ( key : string ) =>
339
- key === State . CacheMatchedKey
360
+ key === State . CachePackageManager
361
+ ? inputs [ 'cache' ]
362
+ : key === State . CacheMatchedKey
340
363
? npmFileHash
341
364
: key === State . CachePrimaryKey
342
365
? yarnFileHash
@@ -350,8 +373,8 @@ describe('run', () => {
350
373
351
374
await run ( ) ;
352
375
353
- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
354
- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
376
+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
377
+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
355
378
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
356
379
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
357
380
expect ( infoSpy ) . not . toHaveBeenCalledWith (
0 commit comments