@@ -3,7 +3,7 @@ import * as path from "path";
33
44import test from "ava";
55
6- import { CodeQuality , CodeScanning } from "./analyses" ;
6+ import { AnalysisKind, CodeQuality, CodeScanning } from "./analyses";
77import { getRunnerLogger, Logger } from "./logging";
88import { setupTests } from "./testing-utils";
99import * as uploadLib from "./upload-lib";
@@ -127,27 +127,97 @@ test("finding SARIF files", async (t) => {
127127 fs.writeFileSync(path.join(tmpDir, "a.quality.sarif"), "");
128128 fs.writeFileSync(path.join(tmpDir, "dir1", "b.quality.sarif"), "");
129129
130+ const expectedSarifFiles = [
131+ path.join(tmpDir, "a.sarif"),
132+ path.join(tmpDir, "b.sarif"),
133+ path.join(tmpDir, "dir1", "d.sarif"),
134+ path.join(tmpDir, "dir1", "dir2", "e.sarif"),
135+ ];
130136 const sarifFiles = uploadLib.findSarifFilesInDir(
131137 tmpDir,
132138 CodeScanning.sarifPredicate,
133139 );
134140
135- t . deepEqual ( sarifFiles , [
136- path . join ( tmpDir , "a.sarif" ) ,
137- path . join ( tmpDir , "b.sarif" ) ,
138- path . join ( tmpDir , "dir1" , "d.sarif" ) ,
139- path . join ( tmpDir , "dir1" , "dir2" , "e.sarif" ) ,
140- ] ) ;
141+ t.deepEqual(sarifFiles, expectedSarifFiles);
141142
143+ const expectedQualitySarifFiles = [
144+ path.join(tmpDir, "a.quality.sarif"),
145+ path.join(tmpDir, "dir1", "b.quality.sarif"),
146+ ];
142147 const qualitySarifFiles = uploadLib.findSarifFilesInDir(
143148 tmpDir,
144149 CodeQuality.sarifPredicate,
145150 );
146151
147- t . deepEqual ( qualitySarifFiles , [
148- path . join ( tmpDir , "a.quality.sarif" ) ,
149- path . join ( tmpDir , "dir1" , "b.quality.sarif" ) ,
150- ] ) ;
152+ t.deepEqual(qualitySarifFiles, expectedQualitySarifFiles);
153+
154+ const groupedSarifFiles = await uploadLib.getGroupedSarifFilePaths(
155+ getRunnerLogger(true),
156+ tmpDir,
157+ );
158+
159+ t.not(groupedSarifFiles, undefined);
160+ t.not(groupedSarifFiles[AnalysisKind.CodeScanning], undefined);
161+ t.not(groupedSarifFiles[AnalysisKind.CodeQuality], undefined);
162+ t.deepEqual(
163+ groupedSarifFiles[AnalysisKind.CodeScanning],
164+ expectedSarifFiles,
165+ );
166+ t.deepEqual(
167+ groupedSarifFiles[AnalysisKind.CodeQuality],
168+ expectedQualitySarifFiles,
169+ );
170+ });
171+ });
172+
173+ test("getGroupedSarifFilePaths - Code Quality file", async (t) => {
174+ await withTmpDir(async (tmpDir) => {
175+ const sarifPath = path.join(tmpDir, "a.quality.sarif");
176+ fs.writeFileSync(sarifPath, "");
177+
178+ const groupedSarifFiles = await uploadLib.getGroupedSarifFilePaths(
179+ getRunnerLogger(true),
180+ sarifPath,
181+ );
182+
183+ t.not(groupedSarifFiles, undefined);
184+ t.is(groupedSarifFiles[AnalysisKind.CodeScanning], undefined);
185+ t.not(groupedSarifFiles[AnalysisKind.CodeQuality], undefined);
186+ t.deepEqual(groupedSarifFiles[AnalysisKind.CodeQuality], [sarifPath]);
187+ });
188+ });
189+
190+ test("getGroupedSarifFilePaths - Code Scanning file", async (t) => {
191+ await withTmpDir(async (tmpDir) => {
192+ const sarifPath = path.join(tmpDir, "a.sarif");
193+ fs.writeFileSync(sarifPath, "");
194+
195+ const groupedSarifFiles = await uploadLib.getGroupedSarifFilePaths(
196+ getRunnerLogger(true),
197+ sarifPath,
198+ );
199+
200+ t.not(groupedSarifFiles, undefined);
201+ t.not(groupedSarifFiles[AnalysisKind.CodeScanning], undefined);
202+ t.is(groupedSarifFiles[AnalysisKind.CodeQuality], undefined);
203+ t.deepEqual(groupedSarifFiles[AnalysisKind.CodeScanning], [sarifPath]);
204+ });
205+ });
206+
207+ test("getGroupedSarifFilePaths - Other file", async (t) => {
208+ await withTmpDir(async (tmpDir) => {
209+ const sarifPath = path.join(tmpDir, "a.json");
210+ fs.writeFileSync(sarifPath, "");
211+
212+ const groupedSarifFiles = await uploadLib.getGroupedSarifFilePaths(
213+ getRunnerLogger(true),
214+ sarifPath,
215+ );
216+
217+ t.not(groupedSarifFiles, undefined);
218+ t.not(groupedSarifFiles[AnalysisKind.CodeScanning], undefined);
219+ t.is(groupedSarifFiles[AnalysisKind.CodeQuality], undefined);
220+ t.deepEqual(groupedSarifFiles[AnalysisKind.CodeScanning], [sarifPath]);
151221 });
152222});
153223
0 commit comments