From 14139c9f7766ce3519131b717ad9df0ba9d9254f Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Tue, 21 Oct 2025 23:49:29 +0100 Subject: [PATCH] Add test for `uploadSarif` with `upload: never` --- src/upload-sarif.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/upload-sarif.test.ts b/src/upload-sarif.test.ts index f3305c92a..f8ac0d26b 100644 --- a/src/upload-sarif.test.ts +++ b/src/upload-sarif.test.ts @@ -195,3 +195,41 @@ test( }, }, ); + +test("uploadSarif doesn't upload if `upload` != `always`", async (t) => { + await util.withTmpDir(async (tempDir) => { + const logger = getRunnerLogger(true); + const features = createFeatures([]); + + const toFullPath = (filename: string) => path.join(tempDir, filename); + + const postProcessSarifFiles = sinon.stub( + uploadLib, + "postProcessSarifFiles", + ); + const uploadProcessedFiles = sinon.stub(uploadLib, "uploadProcessedFiles"); + + for (const analysisKind of Object.values(AnalysisKind)) { + const analysisConfig = getAnalysisConfig(analysisKind); + postProcessSarifFiles + .withArgs( + logger, + sinon.match.any, + sinon.match.any, + sinon.match.any, + sinon.match.any, + analysisConfig, + ) + .resolves({ sarif: { runs: [] }, analysisKey: "", environment: "" }); + } + + fs.writeFileSync(toFullPath("test.sarif"), ""); + fs.writeFileSync(toFullPath("test.quality.sarif"), ""); + + const actual = await uploadSarif(logger, features, "never", "", tempDir); + + t.truthy(actual); + t.assert(postProcessSarifFiles.calledTwice); + t.assert(uploadProcessedFiles.notCalled); + }); +});