@@ -41,7 +41,7 @@ describe('BuildRetriever', () => {
41
41
42
42
EXISTS_RESULT = false ;
43
43
existsSpy = spyOn ( fs , 'exists' ) . and . callFake (
44
- ( _path : string , callback : ( err ?: any ) => { } ) => callback ( EXISTS_RESULT ) ,
44
+ ( _path : string , callback : ( exists : boolean ) => { } ) => callback ( EXISTS_RESULT ) ,
45
45
) ;
46
46
} ) ;
47
47
@@ -96,6 +96,17 @@ describe('BuildRetriever', () => {
96
96
artifactRequest . done ( ) ;
97
97
} ) ;
98
98
99
+ it ( 'should not download the artifact if it already exists' , async ( ) => {
100
+ const artifactRequestInterceptor = nock ( BASE_URL ) . get ( ARTIFACT_PATH ) ;
101
+ const artifactRequest = artifactRequestInterceptor . reply ( 200 , ARTIFACT_CONTENTS ) ;
102
+ EXISTS_RESULT = true ;
103
+ await retriever . downloadBuildArtifact ( 12345 , 777 , 'COMMIT' , ARTIFACT_PATH ) ;
104
+ expect ( existsSpy ) . toHaveBeenCalled ( ) ;
105
+ expect ( getBuildArtifactUrlSpy ) . not . toHaveBeenCalled ( ) ;
106
+ expect ( artifactRequest . isDone ( ) ) . toEqual ( false ) ;
107
+ nock . removeInterceptor ( artifactRequestInterceptor ) ;
108
+ } ) ;
109
+
99
110
it ( 'should write the artifact file to disk' , async ( ) => {
100
111
const artifactRequest = nock ( BASE_URL ) . get ( ARTIFACT_PATH ) . reply ( 200 , ARTIFACT_CONTENTS ) ;
101
112
await retriever . downloadBuildArtifact ( 12345 , 777 , 'COMMIT' , ARTIFACT_PATH ) ;
0 commit comments