Skip to content

Commit 320fdb3

Browse files
committed
Tests: ensure uploadSpecifiedFiles wasn't called if we don't expect it to be
1 parent f6ff68d commit 320fdb3

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/upload-sarif.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const uploadSarifMacro = test.macro({
109109
"uploadSpecifiedFiles",
110110
);
111111

112-
for (const analysisKind of Object.keys(expectedResult)) {
112+
for (const analysisKind of Object.values(AnalysisKind)) {
113113
uploadSpecifiedFiles
114114
.withArgs(
115115
sinon.match.any,
@@ -135,8 +135,10 @@ const uploadSarifMacro = test.macro({
135135
for (const analysisKind of Object.values(AnalysisKind)) {
136136
const analyisKindResult = expectedResult[analysisKind];
137137
if (analyisKindResult) {
138+
// We are expecting a result for this analysis kind, check that we have it.
138139
t.deepEqual(actual[analysisKind], analyisKindResult.uploadResult);
139-
140+
// Additionally, check that the mocked `uploadSpecifiedFiles` was called with only the file paths
141+
// that we expected it to be called with.
140142
t.assert(
141143
uploadSpecifiedFiles.calledWith(
142144
analyisKindResult.expectedFiles?.map(toFullPath) ??
@@ -151,7 +153,24 @@ const uploadSarifMacro = test.macro({
151153
),
152154
);
153155
} else {
156+
// Otherwise, we are not expecting a result for this analysis kind. However, note that `undefined`
157+
// is also returned by our mocked `uploadSpecifiedFiles` when there is no expected result for this
158+
// analysis kind.
154159
t.is(actual[analysisKind], undefined);
160+
// Therefore, we also check that the mocked `uploadSpecifiedFiles` was not called for this analysis kind.
161+
t.assert(
162+
!uploadSpecifiedFiles.calledWith(
163+
sinon.match.any,
164+
sinon.match.any,
165+
sinon.match.any,
166+
features,
167+
logger,
168+
analysisKind === AnalysisKind.CodeScanning
169+
? CodeScanning
170+
: CodeQuality,
171+
),
172+
`uploadSpecifiedFiles was called for ${analysisKind}, but should not have been.`,
173+
);
155174
}
156175
}
157176
});

0 commit comments

Comments
 (0)