@ -107,18 +107,20 @@ describe('run', () => {
describe ( 'Validate unchanged cache is not saved' , ( ) = > {
it ( 'should not save cache for yarn1' , async ( ) = > {
inputs [ 'cache' ] = 'yarn' ;
getStateSpy . mockImplementation ( ( ) = > yarnFileHash ) ;
getCommandOutputSpy
. mockImplementationOnce ( ( ) = > '1.2.3' )
. mockImplementationOnce ( ( ) = > ` ${ commonPath } /yarn1 ` ) ;
getStateSpy . mockImplementation ( key = >
key === State . CachePrimaryKey || key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` yarn path is ${ commonPath } /yarn1 ` ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( 'Consumed yarn version is 1.2.3' ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( infoSpy ) . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ yarnFileHash } , not saving cache. `
) ;
@ -127,18 +129,20 @@ describe('run', () => {
it ( 'should not save cache for yarn2' , async ( ) = > {
inputs [ 'cache' ] = 'yarn' ;
getStateSpy . mockImplementation ( ( ) = > yarnFileHash ) ;
getCommandOutputSpy
. mockImplementationOnce ( ( ) = > '2.2.3' )
. mockImplementationOnce ( ( ) = > ` ${ commonPath } /yarn2 ` ) ;
getStateSpy . mockImplementation ( key = >
key === State . CachePrimaryKey || key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` yarn path is ${ commonPath } /yarn2 ` ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( 'Consumed yarn version is 2.2.3' ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( infoSpy ) . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ yarnFileHash } , not saving cache. `
) ;
@ -147,35 +151,40 @@ describe('run', () => {
it ( 'should not save cache for npm' , async ( ) = > {
inputs [ 'cache' ] = 'npm' ;
getStateSpy . mockImplementation ( ( ) = > npmFileHash ) ;
getStateSpy . mockImplementation ( key = >
key === State . CachePrimaryKey || key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /npm ` ) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` npm path is ${ commonPath } /npm ` ) ;
expect ( infoSpy ) . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ npmFileHash } , not saving cache. `
) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
it ( 'should not save cache for pnpm' , async ( ) = > {
inputs [ 'cache' ] = 'pnpm' ;
getStateSpy . mockImplementation ( ( ) = > pnpmFileHash ) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /pnpm ` ) ;
getStateSpy . mockImplementation ( key = >
key === State . CachePrimaryKey || key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` pnpm path is ${ commonPath } /pnpm ` ) ;
expect ( infoSpy ) . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ pnpmFileHash } , not saving cache. `
) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( setFailedSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
} ) ;
@ -183,24 +192,22 @@ describe('run', () => {
describe ( 'action saves the cache' , ( ) = > {
it ( 'saves cache from yarn 1' , async ( ) = > {
inputs [ 'cache' ] = 'yarn' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return yarnFileHash ;
} else {
return npmFileHash ;
}
} ) ;
getCommandOutputSpy
. mockImplementationOnce ( ( ) = > '1.2.3' )
. mockImplementationOnce ( ( ) = > ` ${ commonPath } /yarn1 ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePrimaryKey
? npmFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` yarn path is ${ commonPath } /yarn1 ` ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( 'Consumed yarn version is 1.2.3' ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ yarnFileHash } , not saving cache. `
) ;
@ -213,24 +220,22 @@ describe('run', () => {
it ( 'saves cache from yarn 2' , async ( ) = > {
inputs [ 'cache' ] = 'yarn' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return yarnFileHash ;
} else {
return npmFileHash ;
}
} ) ;
getCommandOutputSpy
. mockImplementationOnce ( ( ) = > '2.2.3' )
. mockImplementationOnce ( ( ) = > ` ${ commonPath } /yarn2 ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? yarnFileHash
: key === State . CachePrimaryKey
? npmFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( ` yarn path is ${ commonPath } /yarn2 ` ) ;
expect ( debugSpy ) . toHaveBeenCalledWith ( 'Consumed yarn version is 2.2.3' ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ yarnFileHash } , not saving cache. `
) ;
@ -243,21 +248,22 @@ describe('run', () => {
it ( 'saves cache from npm' , async ( ) = > {
inputs [ 'cache' ] = 'npm' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return npmFileHash ;
} else {
return yarnFileHash ;
}
} ) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /npm ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? npmFileHash
: key === State . CachePrimaryKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalled With( ` npm path is ${ commonPath } /npm ` ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalled Times( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ npmFileHash } , not saving cache. `
) ;
@ -270,21 +276,22 @@ describe('run', () => {
it ( 'saves cache from pnpm' , async ( ) = > {
inputs [ 'cache' ] = 'pnpm' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return pnpmFileHash ;
} else {
return npmFileHash ;
}
} ) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /pnpm ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? pnpmFileHash
: key === State . CachePrimaryKey
? npmFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalled With( ` pnpm path is ${ commonPath } /pnpm ` ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalled Times( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ pnpmFileHash } , not saving cache. `
) ;
@ -297,14 +304,15 @@ describe('run', () => {
it ( 'save with -1 cacheId , should not fail workflow' , async ( ) = > {
inputs [ 'cache' ] = 'npm' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return npmFileHash ;
} else {
return yarnFileHash ;
}
} ) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /npm ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? npmFileHash
: key === State . CachePrimaryKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
saveCacheSpy . mockImplementation ( ( ) = > {
return - 1 ;
} ) ;
@ -312,9 +320,9 @@ describe('run', () => {
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalled With( ` npm path is ${ commonPath } /npm ` ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalled Times( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ npmFileHash } , not saving cache. `
) ;
@ -327,14 +335,15 @@ describe('run', () => {
it ( 'saves with error from toolkit, should fail workflow' , async ( ) = > {
inputs [ 'cache' ] = 'npm' ;
getStateSpy . mockImplementation ( ( name : string ) = > {
if ( name === State . CacheMatchedKey ) {
return npmFileHash ;
} else {
return yarnFileHash ;
}
} ) ;
getCommandOutputSpy . mockImplementationOnce ( ( ) = > ` ${ commonPath } /npm ` ) ;
getStateSpy . mockImplementation ( ( key : string ) = >
key === State . CacheMatchedKey
? npmFileHash
: key === State . CachePrimaryKey
? yarnFileHash
: key === State . CachePaths
? '["/foo/bar"]'
: 'not expected'
) ;
saveCacheSpy . mockImplementation ( ( ) = > {
throw new cache . ValidationError ( 'Validation failed' ) ;
} ) ;
@ -342,9 +351,9 @@ describe('run', () => {
await run ( ) ;
expect ( getInputSpy ) . toHaveBeenCalled ( ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 2 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 1 ) ;
expect ( debugSpy ) . toHaveBeenCalled With( ` npm path is ${ commonPath } /npm ` ) ;
expect ( getStateSpy ) . toHaveBeenCalledTimes ( 3 ) ;
expect ( getCommandOutputSpy ) . toHaveBeenCalledTimes ( 0 ) ;
expect ( debugSpy ) . toHaveBeenCalled Times( 0 ) ;
expect ( infoSpy ) . not . toHaveBeenCalledWith (
` Cache hit occurred on the primary key ${ npmFileHash } , not saving cache. `
) ;