@@ -128,11 +128,21 @@ test("finding SARIF files", async (t) => {
128128 "file" ,
129129 ) ;
130130
131- // add some `.quality.sarif` files that should be ignored, unless we look for them specifically
132- fs . writeFileSync ( path . join ( tmpDir , "a.quality.sarif" ) , "" ) ;
133- fs . writeFileSync ( path . join ( tmpDir , "dir1" , "b.quality.sarif" ) , "" ) ;
131+ // add some non-Code Scanning files that should be ignored, unless we look for them specifically
132+ for ( const analysisKind of analyses . supportedAnalysisKinds ) {
133+ if ( analysisKind === AnalysisKind . CodeScanning ) continue ;
134134
135- const expectedSarifFiles = [
135+ const analysis = analyses . getAnalysisConfig ( analysisKind ) ;
136+
137+ fs . writeFileSync ( path . join ( tmpDir , `a${ analysis . sarifExtension } ` ) , "" ) ;
138+ fs . writeFileSync (
139+ path . join ( tmpDir , "dir1" , `b${ analysis . sarifExtension } ` ) ,
140+ "" ,
141+ ) ;
142+ }
143+
144+ const expectedSarifFiles : Partial < Record < AnalysisKind , string [ ] > > = { } ;
145+ expectedSarifFiles [ AnalysisKind . CodeScanning ] = [
136146 path . join ( tmpDir , "a.sarif" ) ,
137147 path . join ( tmpDir , "b.sarif" ) ,
138148 path . join ( tmpDir , "dir1" , "d.sarif" ) ,
@@ -143,35 +153,56 @@ test("finding SARIF files", async (t) => {
143153 CodeScanning . sarifPredicate ,
144154 ) ;
145155
146- t . deepEqual ( sarifFiles , expectedSarifFiles ) ;
156+ t . deepEqual ( sarifFiles , expectedSarifFiles [ AnalysisKind . CodeScanning ] ) ;
147157
148- const expectedQualitySarifFiles = [
149- path . join ( tmpDir , "a.quality.sarif" ) ,
150- path . join ( tmpDir , "dir1" , "b.quality.sarif" ) ,
151- ] ;
152- const qualitySarifFiles = uploadLib . findSarifFilesInDir (
153- tmpDir ,
154- CodeQuality . sarifPredicate ,
155- ) ;
158+ for ( const analysisKind of analyses . supportedAnalysisKinds ) {
159+ if ( analysisKind === AnalysisKind . CodeScanning ) continue ;
160+
161+ const analysis = analyses . getAnalysisConfig ( analysisKind ) ;
156162
157- t . deepEqual ( qualitySarifFiles , expectedQualitySarifFiles ) ;
163+ expectedSarifFiles [ analysisKind ] = [
164+ path . join ( tmpDir , `a${ analysis . sarifExtension } ` ) ,
165+ path . join ( tmpDir , "dir1" , `b${ analysis . sarifExtension } ` ) ,
166+ ] ;
167+ const foundSarifFiles = uploadLib . findSarifFilesInDir (
168+ tmpDir ,
169+ analysis . sarifPredicate ,
170+ ) ;
171+
172+ t . deepEqual ( foundSarifFiles , expectedSarifFiles [ analysisKind ] ) ;
173+ }
158174
159175 const groupedSarifFiles = await uploadLib . getGroupedSarifFilePaths (
160176 getRunnerLogger ( true ) ,
161177 tmpDir ,
162178 ) ;
163179
164180 t . not ( groupedSarifFiles , undefined ) ;
165- t . not ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , undefined ) ;
166- t . not ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , undefined ) ;
167- t . deepEqual (
168- groupedSarifFiles [ AnalysisKind . CodeScanning ] ,
169- expectedSarifFiles ,
170- ) ;
171- t . deepEqual (
172- groupedSarifFiles [ AnalysisKind . CodeQuality ] ,
173- expectedQualitySarifFiles ,
181+ for ( const analysisKind of analyses . supportedAnalysisKinds ) {
182+ t . not ( groupedSarifFiles [ analysisKind ] , undefined ) ;
183+ t . deepEqual (
184+ groupedSarifFiles [ analysisKind ] ,
185+ expectedSarifFiles [ analysisKind ] ,
186+ ) ;
187+ }
188+ } ) ;
189+ } ) ;
190+
191+ test ( "getGroupedSarifFilePaths - CSRA" , async ( t ) => {
192+ await withTmpDir ( async ( tmpDir ) => {
193+ const sarifPath = path . join ( tmpDir , "a.csra.sarif" ) ;
194+ fs . writeFileSync ( sarifPath , "" ) ;
195+
196+ const groupedSarifFiles = await uploadLib . getGroupedSarifFilePaths (
197+ getRunnerLogger ( true ) ,
198+ sarifPath ,
174199 ) ;
200+
201+ t . not ( groupedSarifFiles , undefined ) ;
202+ t . is ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , undefined ) ;
203+ t . is ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , undefined ) ;
204+ t . not ( groupedSarifFiles [ AnalysisKind . CSRA ] , undefined ) ;
205+ t . deepEqual ( groupedSarifFiles [ AnalysisKind . CSRA ] , [ sarifPath ] ) ;
175206 } ) ;
176207} ) ;
177208
@@ -188,6 +219,7 @@ test("getGroupedSarifFilePaths - Code Quality file", async (t) => {
188219 t . not ( groupedSarifFiles , undefined ) ;
189220 t . is ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , undefined ) ;
190221 t . not ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , undefined ) ;
222+ t . is ( groupedSarifFiles [ AnalysisKind . CSRA ] , undefined ) ;
191223 t . deepEqual ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , [ sarifPath ] ) ;
192224 } ) ;
193225} ) ;
@@ -205,6 +237,7 @@ test("getGroupedSarifFilePaths - Code Scanning file", async (t) => {
205237 t . not ( groupedSarifFiles , undefined ) ;
206238 t . not ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , undefined ) ;
207239 t . is ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , undefined ) ;
240+ t . is ( groupedSarifFiles [ AnalysisKind . CSRA ] , undefined ) ;
208241 t . deepEqual ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , [ sarifPath ] ) ;
209242 } ) ;
210243} ) ;
@@ -222,6 +255,7 @@ test("getGroupedSarifFilePaths - Other file", async (t) => {
222255 t . not ( groupedSarifFiles , undefined ) ;
223256 t . not ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , undefined ) ;
224257 t . is ( groupedSarifFiles [ AnalysisKind . CodeQuality ] , undefined ) ;
258+ t . is ( groupedSarifFiles [ AnalysisKind . CSRA ] , undefined ) ;
225259 t . deepEqual ( groupedSarifFiles [ AnalysisKind . CodeScanning ] , [ sarifPath ] ) ;
226260 } ) ;
227261} ) ;
0 commit comments