@@ -19,6 +19,26 @@ interface UploadSarifExpectedResult {
1919 expectedFiles ?: string [ ] ;
2020}
2121
22+ function mockPostProcessSarifFiles ( ) {
23+ const postProcessSarifFiles = sinon . stub ( uploadLib , "postProcessSarifFiles" ) ;
24+
25+ for ( const analysisKind of Object . values ( AnalysisKind ) ) {
26+ const analysisConfig = getAnalysisConfig ( analysisKind ) ;
27+ postProcessSarifFiles
28+ . withArgs (
29+ sinon . match . any ,
30+ sinon . match . any ,
31+ sinon . match . any ,
32+ sinon . match . any ,
33+ sinon . match . any ,
34+ analysisConfig ,
35+ )
36+ . resolves ( { sarif : { runs : [ ] } , analysisKey : "" , environment : "" } ) ;
37+ }
38+
39+ return postProcessSarifFiles ;
40+ }
41+
2242const uploadSarifMacro = test . macro ( {
2343 exec : async (
2444 t : ExecutionContext < unknown > ,
@@ -33,27 +53,14 @@ const uploadSarifMacro = test.macro({
3353
3454 const toFullPath = ( filename : string ) => path . join ( tempDir , filename ) ;
3555
36- const postProcessSarifFiles = sinon . stub (
37- uploadLib ,
38- "postProcessSarifFiles" ,
39- ) ;
56+ const postProcessSarifFiles = mockPostProcessSarifFiles ( ) ;
4057 const uploadProcessedFiles = sinon . stub (
4158 uploadLib ,
4259 "uploadProcessedFiles" ,
4360 ) ;
4461
4562 for ( const analysisKind of Object . values ( AnalysisKind ) ) {
4663 const analysisConfig = getAnalysisConfig ( analysisKind ) ;
47- postProcessSarifFiles
48- . withArgs (
49- logger ,
50- sinon . match . any ,
51- sinon . match . any ,
52- sinon . match . any ,
53- sinon . match . any ,
54- analysisConfig ,
55- )
56- . resolves ( { sarif : { runs : [ ] } , analysisKey : "" , environment : "" } ) ;
5764 uploadProcessedFiles
5865 . withArgs ( logger , sinon . match . any , analysisConfig , sinon . match . any )
5966 . resolves ( expectedResult [ analysisKind as AnalysisKind ] ?. uploadResult ) ;
@@ -203,26 +210,9 @@ test("uploadSarif doesn't upload if `upload` != `always`", async (t) => {
203210
204211 const toFullPath = ( filename : string ) => path . join ( tempDir , filename ) ;
205212
206- const postProcessSarifFiles = sinon . stub (
207- uploadLib ,
208- "postProcessSarifFiles" ,
209- ) ;
213+ const postProcessSarifFiles = mockPostProcessSarifFiles ( ) ;
210214 const uploadProcessedFiles = sinon . stub ( uploadLib , "uploadProcessedFiles" ) ;
211215
212- for ( const analysisKind of Object . values ( AnalysisKind ) ) {
213- const analysisConfig = getAnalysisConfig ( analysisKind ) ;
214- postProcessSarifFiles
215- . withArgs (
216- logger ,
217- sinon . match . any ,
218- sinon . match . any ,
219- sinon . match . any ,
220- sinon . match . any ,
221- analysisConfig ,
222- )
223- . resolves ( { sarif : { runs : [ ] } , analysisKey : "" , environment : "" } ) ;
224- }
225-
226216 fs . writeFileSync ( toFullPath ( "test.sarif" ) , "" ) ;
227217 fs . writeFileSync ( toFullPath ( "test.quality.sarif" ) , "" ) ;
228218
@@ -233,3 +223,35 @@ test("uploadSarif doesn't upload if `upload` != `always`", async (t) => {
233223 t . assert ( uploadProcessedFiles . notCalled ) ;
234224 } ) ;
235225} ) ;
226+
227+ test ( "uploadSarif writes processed SARIF files if output directory is provided" , async ( t ) => {
228+ await util . withTmpDir ( async ( tempDir ) => {
229+ const logger = getRunnerLogger ( true ) ;
230+ const features = createFeatures ( [ ] ) ;
231+
232+ const toFullPath = ( filename : string ) => path . join ( tempDir , filename ) ;
233+
234+ const postProcessSarifFiles = mockPostProcessSarifFiles ( ) ;
235+
236+ fs . writeFileSync ( toFullPath ( "test.sarif" ) , "" ) ;
237+ fs . writeFileSync ( toFullPath ( "test.quality.sarif" ) , "" ) ;
238+
239+ const processedOutPath = path . join ( tempDir , "processed" ) ;
240+ const actual = await uploadSarif (
241+ logger ,
242+ features ,
243+ "never" ,
244+ "" ,
245+ tempDir ,
246+ "" ,
247+ processedOutPath ,
248+ ) ;
249+
250+ t . truthy ( actual ) ;
251+ t . assert ( postProcessSarifFiles . calledTwice ) ;
252+ t . assert ( fs . existsSync ( path . join ( processedOutPath , "upload.sarif" ) ) ) ;
253+ t . assert (
254+ fs . existsSync ( path . join ( processedOutPath , "upload.quality.sarif" ) ) ,
255+ ) ;
256+ } ) ;
257+ } ) ;
0 commit comments