@@ -92,6 +92,9 @@ describe('run', () => {
9292
9393 it ( 'Package manager is not valid, skip caching' , async ( ) => {
9494 inputs [ 'cache' ] = 'yarn3' ;
95+ getStateSpy . mockImplementation ( key =>
96+ key === State . CachePackageManager ? inputs [ 'cache' ] : ''
97+ ) ;
9598
9699 await run ( ) ;
97100
@@ -108,7 +111,9 @@ describe('run', () => {
108111 it ( 'should not save cache for yarn1' , async ( ) => {
109112 inputs [ 'cache' ] = 'yarn' ;
110113 getStateSpy . mockImplementation ( key =>
111- key === State . CachePrimaryKey || key === State . CacheMatchedKey
114+ key === State . CachePackageManager
115+ ? inputs [ 'cache' ]
116+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
112117 ? yarnFileHash
113118 : key === State . CachePaths
114119 ? '["/foo/bar"]'
@@ -117,8 +122,8 @@ describe('run', () => {
117122
118123 await run ( ) ;
119124
120- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
121- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
125+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
126+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
122127 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
123128 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
124129 expect ( infoSpy ) . toHaveBeenCalledWith (
@@ -130,7 +135,9 @@ describe('run', () => {
130135 it ( 'should not save cache for yarn2' , async ( ) => {
131136 inputs [ 'cache' ] = 'yarn' ;
132137 getStateSpy . mockImplementation ( key =>
133- key === State . CachePrimaryKey || key === State . CacheMatchedKey
138+ key === State . CachePackageManager
139+ ? inputs [ 'cache' ]
140+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
134141 ? yarnFileHash
135142 : key === State . CachePaths
136143 ? '["/foo/bar"]'
@@ -139,8 +146,8 @@ describe('run', () => {
139146
140147 await run ( ) ;
141148
142- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
143- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
149+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
150+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
144151 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
145152 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
146153 expect ( infoSpy ) . toHaveBeenCalledWith (
@@ -152,7 +159,9 @@ describe('run', () => {
152159 it ( 'should not save cache for npm' , async ( ) => {
153160 inputs [ 'cache' ] = 'npm' ;
154161 getStateSpy . mockImplementation ( key =>
155- key === State . CachePrimaryKey || key === State . CacheMatchedKey
162+ key === State . CachePackageManager
163+ ? inputs [ 'cache' ]
164+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
156165 ? yarnFileHash
157166 : key === State . CachePaths
158167 ? '["/foo/bar"]'
@@ -162,8 +171,8 @@ describe('run', () => {
162171
163172 await run ( ) ;
164173
165- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
166- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
174+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
175+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
167176 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
168177 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
169178 expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
@@ -172,7 +181,9 @@ describe('run', () => {
172181 it ( 'should not save cache for pnpm' , async ( ) => {
173182 inputs [ 'cache' ] = 'pnpm' ;
174183 getStateSpy . mockImplementation ( key =>
175- key === State . CachePrimaryKey || key === State . CacheMatchedKey
184+ key === State . CachePackageManager
185+ ? inputs [ 'cache' ]
186+ : key === State . CachePrimaryKey || key === State . CacheMatchedKey
176187 ? yarnFileHash
177188 : key === State . CachePaths
178189 ? '["/foo/bar"]'
@@ -181,8 +192,8 @@ describe('run', () => {
181192
182193 await run ( ) ;
183194
184- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
185- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
195+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
196+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
186197 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
187198 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
188199 expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
@@ -193,7 +204,9 @@ describe('run', () => {
193204 it ( 'saves cache from yarn 1' , async ( ) => {
194205 inputs [ 'cache' ] = 'yarn' ;
195206 getStateSpy . mockImplementation ( ( key : string ) =>
196- key === State . CacheMatchedKey
207+ key === State . CachePackageManager
208+ ? inputs [ 'cache' ]
209+ : key === State . CacheMatchedKey
197210 ? yarnFileHash
198211 : key === State . CachePrimaryKey
199212 ? npmFileHash
@@ -204,8 +217,8 @@ describe('run', () => {
204217
205218 await run ( ) ;
206219
207- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
208- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
220+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
221+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
209222 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
210223 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
211224 expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -221,7 +234,9 @@ describe('run', () => {
221234 it ( 'saves cache from yarn 2' , async ( ) => {
222235 inputs [ 'cache' ] = 'yarn' ;
223236 getStateSpy . mockImplementation ( ( key : string ) =>
224- key === State . CacheMatchedKey
237+ key === State . CachePackageManager
238+ ? inputs [ 'cache' ]
239+ : key === State . CacheMatchedKey
225240 ? yarnFileHash
226241 : key === State . CachePrimaryKey
227242 ? npmFileHash
@@ -232,8 +247,8 @@ describe('run', () => {
232247
233248 await run ( ) ;
234249
235- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
236- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
250+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
251+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
237252 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
238253 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
239254 expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -249,7 +264,9 @@ describe('run', () => {
249264 it ( 'saves cache from npm' , async ( ) => {
250265 inputs [ 'cache' ] = 'npm' ;
251266 getStateSpy . mockImplementation ( ( key : string ) =>
252- key === State . CacheMatchedKey
267+ key === State . CachePackageManager
268+ ? inputs [ 'cache' ]
269+ : key === State . CacheMatchedKey
253270 ? npmFileHash
254271 : key === State . CachePrimaryKey
255272 ? yarnFileHash
@@ -260,8 +277,8 @@ describe('run', () => {
260277
261278 await run ( ) ;
262279
263- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
264- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
280+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
281+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
265282 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
266283 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
267284 expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -277,7 +294,9 @@ describe('run', () => {
277294 it ( 'saves cache from pnpm' , async ( ) => {
278295 inputs [ 'cache' ] = 'pnpm' ;
279296 getStateSpy . mockImplementation ( ( key : string ) =>
280- key === State . CacheMatchedKey
297+ key === State . CachePackageManager
298+ ? inputs [ 'cache' ]
299+ : key === State . CacheMatchedKey
281300 ? pnpmFileHash
282301 : key === State . CachePrimaryKey
283302 ? npmFileHash
@@ -288,8 +307,8 @@ describe('run', () => {
288307
289308 await run ( ) ;
290309
291- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
292- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
310+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
311+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
293312 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
294313 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
295314 expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -305,7 +324,9 @@ describe('run', () => {
305324 it ( 'save with -1 cacheId , should not fail workflow' , async ( ) => {
306325 inputs [ 'cache' ] = 'npm' ;
307326 getStateSpy . mockImplementation ( ( key : string ) =>
308- key === State . CacheMatchedKey
327+ key === State . CachePackageManager
328+ ? inputs [ 'cache' ]
329+ : key === State . CacheMatchedKey
309330 ? npmFileHash
310331 : key === State . CachePrimaryKey
311332 ? yarnFileHash
@@ -319,8 +340,8 @@ describe('run', () => {
319340
320341 await run ( ) ;
321342
322- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
323- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
343+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
344+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
324345 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
325346 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
326347 expect ( infoSpy ) . not . toHaveBeenCalledWith (
@@ -336,7 +357,9 @@ describe('run', () => {
336357 it ( 'saves with error from toolkit, should fail workflow' , async ( ) => {
337358 inputs [ 'cache' ] = 'npm' ;
338359 getStateSpy . mockImplementation ( ( key : string ) =>
339- key === State . CacheMatchedKey
360+ key === State . CachePackageManager
361+ ? inputs [ 'cache' ]
362+ : key === State . CacheMatchedKey
340363 ? npmFileHash
341364 : key === State . CachePrimaryKey
342365 ? yarnFileHash
@@ -350,8 +373,8 @@ describe('run', () => {
350373
351374 await run ( ) ;
352375
353- expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
354- expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
376+ expect ( getInputSpy ) . not . toHaveBeenCalled ( ) ;
377+ expect ( getStateSpy ) . toHaveBeenCalledTimes ( 4 ) ;
355378 expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
356379 expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
357380 expect ( infoSpy ) . not . toHaveBeenCalledWith (
0 commit comments