@@ -377,13 +377,20 @@ describe('dependency cache', () => {
377377 ReturnType < typeof cache . saveCache > ,
378378 Parameters < typeof cache . saveCache >
379379 > ;
380+ let spyGlobCreate : jest . SpyInstance <
381+ ReturnType < typeof glob . create > ,
382+ Parameters < typeof glob . create >
383+ > ;
380384
381385 beforeEach ( ( ) => {
382386 spyCacheSave = jest
383387 . spyOn ( cache , 'saveCache' )
384388 . mockImplementation ( ( paths : string [ ] , key : string ) =>
385389 Promise . resolve ( 0 )
386390 ) ;
391+ spyGlobCreate = jest
392+ . spyOn ( glob , 'create' )
393+ . mockResolvedValue ( createGlobber ( [ 'wrapper-path' ] ) ) ;
387394 spyWarning . mockImplementation ( ( ) => null ) ;
388395 } ) ;
389396
@@ -469,17 +476,24 @@ describe('dependency cache', () => {
469476 } ) ;
470477 it ( 'does not fail the post step when the wrapper distribution path is missing' , async ( ) => {
471478 createFile ( join ( workspace , 'pom.xml' ) ) ;
479+ createDirectory ( join ( workspace , '.mvn' ) ) ;
480+ createDirectory ( join ( workspace , '.mvn' , 'wrapper' ) ) ;
481+ createFile (
482+ join ( workspace , '.mvn' , 'wrapper' , 'maven-wrapper.properties' )
483+ ) ;
472484 createStateForWrapperRestore ( 'maven-wrapper' , false ) ;
473- spyCacheSave . mockImplementation ( ( paths : string [ ] , key : string ) => {
474- if ( paths . includes ( join ( os . homedir ( ) , '.m2' , 'wrapper' , 'dists' ) ) ) {
475- return Promise . reject (
476- new cache . ValidationError ( 'Path Validation Error' )
477- ) ;
478- }
479- return Promise . resolve ( 0 ) ;
480- } ) ;
485+ spyGlobCreate . mockResolvedValue ( createGlobber ( [ ] ) ) ;
481486
482- await expect ( save ( 'maven' ) ) . resolves . not . toThrow ( ) ;
487+ await expect ( save ( 'maven' ) ) . resolves . toBeUndefined ( ) ;
488+ expect ( spyCacheSave ) . not . toHaveBeenCalledWith (
489+ [ join ( os . homedir ( ) , '.m2' , 'wrapper' , 'dists' ) ] ,
490+ expect . any ( String )
491+ ) ;
492+ expect ( spyCacheSave ) . toHaveBeenCalledWith (
493+ [ join ( os . homedir ( ) , '.m2' , 'repository' ) ] ,
494+ 'setup-java-cache-primary-key'
495+ ) ;
496+ expect ( spyWarning ) . not . toHaveBeenCalled ( ) ;
483497 } ) ;
484498 } ) ;
485499 describe ( 'for gradle' , ( ) => {
@@ -553,6 +567,23 @@ describe('dependency cache', () => {
553567 expect . any ( String )
554568 ) ;
555569 } ) ;
570+ it ( 'does not fail the post step when the wrapper distribution path is missing' , async ( ) => {
571+ createFile ( join ( workspace , 'build.gradle' ) ) ;
572+ createFile ( join ( workspace , 'gradle-wrapper.properties' ) ) ;
573+ createStateForWrapperRestore ( 'gradle-wrapper' , false ) ;
574+ spyGlobCreate . mockResolvedValue ( createGlobber ( [ ] ) ) ;
575+
576+ await expect ( save ( 'gradle' ) ) . resolves . toBeUndefined ( ) ;
577+ expect ( spyCacheSave ) . not . toHaveBeenCalledWith (
578+ [ join ( os . homedir ( ) , '.gradle' , 'wrapper' ) ] ,
579+ expect . any ( String )
580+ ) ;
581+ expect ( spyCacheSave ) . toHaveBeenCalledWith (
582+ [ join ( os . homedir ( ) , '.gradle' , 'caches' ) ] ,
583+ 'setup-java-cache-primary-key'
584+ ) ;
585+ expect ( spyWarning ) . not . toHaveBeenCalled ( ) ;
586+ } ) ;
556587 } ) ;
557588 describe ( 'for sbt' , ( ) => {
558589 it ( 'uploads cache even if no build.sbt found' , async ( ) => {
@@ -663,6 +694,20 @@ function createDirectory(path: string) {
663694 fs . mkdirSync ( path ) ;
664695}
665696
697+ function createGlobber (
698+ paths : string [ ]
699+ ) : Awaited < ReturnType < typeof glob . create > > {
700+ return {
701+ getSearchPaths : ( ) => [ ] ,
702+ glob : ( ) => Promise . resolve ( paths ) ,
703+ globGenerator : async function * ( ) {
704+ for ( const path of paths ) {
705+ yield path ;
706+ }
707+ }
708+ } ;
709+ }
710+
666711function projectRoot ( workspace : string ) : string {
667712 if ( os . platform ( ) === 'darwin' ) {
668713 return `/private${ workspace } ` ;
0 commit comments