Skip to content

Commit 384a11f

Browse files
committed
Run some unit tests in parallel
1 parent 281b265 commit 384a11f

27 files changed

+4723
-4105
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"lint": "eslint --report-unused-disable-directives --max-warnings=0 .",
1010
"lint-ci": "SARIF_ESLINT_IGNORE_SUPPRESSED=true eslint --report-unused-disable-directives --max-warnings=0 . --format @microsoft/eslint-formatter-sarif --output-file=eslint.sarif",
1111
"lint-fix": "eslint --report-unused-disable-directives --max-warnings=0 . --fix",
12-
"ava": "npm run transpile && ava --serial --verbose",
12+
"ava": "npm run transpile && ava --verbose",
1313
"test": "npm run ava -- src/",
1414
"test-debug": "npm run test -- --timeout=20m",
1515
"transpile": "tsc --build --verbose"

src/actions-util.test.ts

Lines changed: 83 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -133,75 +133,87 @@ test("getPullRequestBranches() returns undefined with push context", (t) => {
133133
);
134134
});
135135

136-
test("getPullRequestBranches() with Default Setup environment variables", (t) => {
137-
withMockedContext({}, () => {
138-
withMockedEnv(
139-
{
140-
CODE_SCANNING_REF: "refs/heads/feature-branch",
141-
CODE_SCANNING_BASE_BRANCH: "main",
142-
},
143-
() => {
144-
t.deepEqual(getPullRequestBranches(), {
145-
base: "main",
146-
head: "refs/heads/feature-branch",
147-
});
148-
t.is(isAnalyzingPullRequest(), true);
149-
},
150-
);
151-
});
152-
});
136+
test.serial(
137+
"getPullRequestBranches() with Default Setup environment variables",
138+
(t) => {
139+
withMockedContext({}, () => {
140+
withMockedEnv(
141+
{
142+
CODE_SCANNING_REF: "refs/heads/feature-branch",
143+
CODE_SCANNING_BASE_BRANCH: "main",
144+
},
145+
() => {
146+
t.deepEqual(getPullRequestBranches(), {
147+
base: "main",
148+
head: "refs/heads/feature-branch",
149+
});
150+
t.is(isAnalyzingPullRequest(), true);
151+
},
152+
);
153+
});
154+
},
155+
);
153156

154-
test("getPullRequestBranches() returns undefined when only CODE_SCANNING_REF is set", (t) => {
155-
withMockedContext({}, () => {
156-
withMockedEnv(
157-
{
158-
CODE_SCANNING_REF: "refs/heads/feature-branch",
159-
CODE_SCANNING_BASE_BRANCH: undefined,
160-
},
161-
() => {
162-
t.is(getPullRequestBranches(), undefined);
163-
t.is(isAnalyzingPullRequest(), false);
164-
},
165-
);
166-
});
167-
});
157+
test.serial(
158+
"getPullRequestBranches() returns undefined when only CODE_SCANNING_REF is set",
159+
(t) => {
160+
withMockedContext({}, () => {
161+
withMockedEnv(
162+
{
163+
CODE_SCANNING_REF: "refs/heads/feature-branch",
164+
CODE_SCANNING_BASE_BRANCH: undefined,
165+
},
166+
() => {
167+
t.is(getPullRequestBranches(), undefined);
168+
t.is(isAnalyzingPullRequest(), false);
169+
},
170+
);
171+
});
172+
},
173+
);
168174

169-
test("getPullRequestBranches() returns undefined when only CODE_SCANNING_BASE_BRANCH is set", (t) => {
170-
withMockedContext({}, () => {
171-
withMockedEnv(
172-
{
173-
CODE_SCANNING_REF: undefined,
174-
CODE_SCANNING_BASE_BRANCH: "main",
175-
},
176-
() => {
177-
t.is(getPullRequestBranches(), undefined);
178-
t.is(isAnalyzingPullRequest(), false);
179-
},
180-
);
181-
});
182-
});
175+
test.serial(
176+
"getPullRequestBranches() returns undefined when only CODE_SCANNING_BASE_BRANCH is set",
177+
(t) => {
178+
withMockedContext({}, () => {
179+
withMockedEnv(
180+
{
181+
CODE_SCANNING_REF: undefined,
182+
CODE_SCANNING_BASE_BRANCH: "main",
183+
},
184+
() => {
185+
t.is(getPullRequestBranches(), undefined);
186+
t.is(isAnalyzingPullRequest(), false);
187+
},
188+
);
189+
});
190+
},
191+
);
183192

184-
test("getPullRequestBranches() returns undefined when no PR context", (t) => {
185-
withMockedContext({}, () => {
186-
withMockedEnv(
187-
{
188-
CODE_SCANNING_REF: undefined,
189-
CODE_SCANNING_BASE_BRANCH: undefined,
190-
},
191-
() => {
192-
t.is(getPullRequestBranches(), undefined);
193-
t.is(isAnalyzingPullRequest(), false);
194-
},
195-
);
196-
});
197-
});
193+
test.serial(
194+
"getPullRequestBranches() returns undefined when no PR context",
195+
(t) => {
196+
withMockedContext({}, () => {
197+
withMockedEnv(
198+
{
199+
CODE_SCANNING_REF: undefined,
200+
CODE_SCANNING_BASE_BRANCH: undefined,
201+
},
202+
() => {
203+
t.is(getPullRequestBranches(), undefined);
204+
t.is(isAnalyzingPullRequest(), false);
205+
},
206+
);
207+
});
208+
},
209+
);
198210

199-
test("initializeEnvironment", (t) => {
211+
test.serial("initializeEnvironment", (t) => {
200212
initializeEnvironment("1.2.3");
201213
t.deepEqual(process.env[EnvVar.VERSION], "1.2.3");
202214
});
203215

204-
test("fixCodeQualityCategory", (t) => {
216+
test.serial("fixCodeQualityCategory", (t) => {
205217
withMockedEnv(
206218
{
207219
GITHUB_EVENT_NAME: "dynamic",
@@ -249,14 +261,17 @@ test("fixCodeQualityCategory", (t) => {
249261
);
250262
});
251263

252-
test("isDynamicWorkflow() returns true if event name is `dynamic`", (t) => {
253-
process.env.GITHUB_EVENT_NAME = "dynamic";
254-
t.assert(isDynamicWorkflow());
255-
process.env.GITHUB_EVENT_NAME = "push";
256-
t.false(isDynamicWorkflow());
257-
});
264+
test.serial(
265+
"isDynamicWorkflow() returns true if event name is `dynamic`",
266+
(t) => {
267+
process.env.GITHUB_EVENT_NAME = "dynamic";
268+
t.assert(isDynamicWorkflow());
269+
process.env.GITHUB_EVENT_NAME = "push";
270+
t.false(isDynamicWorkflow());
271+
},
272+
);
258273

259-
test("isDefaultSetup() returns true when expected", (t) => {
274+
test.serial("isDefaultSetup() returns true when expected", (t) => {
260275
process.env.GITHUB_EVENT_NAME = "dynamic";
261276
process.env[EnvVar.ANALYSIS_KEY] = "dynamic/github-code-scanning";
262277
t.assert(isDefaultSetup());

src/analyses.test.ts

Lines changed: 102 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,40 @@ test("Parsing analysis kinds requires at least one analysis kind", async (t) =>
5050
});
5151
});
5252

53-
test("getAnalysisKinds - returns expected analysis kinds for `analysis-kinds` input", async (t) => {
54-
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
55-
requiredInputStub
56-
.withArgs("analysis-kinds")
57-
.returns("code-scanning,code-quality");
58-
const result = await getAnalysisKinds(getRunnerLogger(true), true);
59-
t.assert(result.includes(AnalysisKind.CodeScanning));
60-
t.assert(result.includes(AnalysisKind.CodeQuality));
61-
});
62-
63-
test("getAnalysisKinds - includes `code-quality` when deprecated `quality-queries` input is used", async (t) => {
64-
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
65-
requiredInputStub.withArgs("analysis-kinds").returns("code-scanning");
66-
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
67-
optionalInputStub.withArgs("quality-queries").returns("code-quality");
68-
const result = await getAnalysisKinds(getRunnerLogger(true), true);
69-
t.assert(result.includes(AnalysisKind.CodeScanning));
70-
t.assert(result.includes(AnalysisKind.CodeQuality));
71-
});
72-
73-
test("getAnalysisKinds - throws if `analysis-kinds` input is invalid", async (t) => {
74-
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
75-
requiredInputStub.withArgs("analysis-kinds").returns("no-such-thing");
76-
await t.throwsAsync(getAnalysisKinds(getRunnerLogger(true), true));
77-
});
53+
test.serial(
54+
"getAnalysisKinds - returns expected analysis kinds for `analysis-kinds` input",
55+
async (t) => {
56+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
57+
requiredInputStub
58+
.withArgs("analysis-kinds")
59+
.returns("code-scanning,code-quality");
60+
const result = await getAnalysisKinds(getRunnerLogger(true), true);
61+
t.assert(result.includes(AnalysisKind.CodeScanning));
62+
t.assert(result.includes(AnalysisKind.CodeQuality));
63+
},
64+
);
65+
66+
test.serial(
67+
"getAnalysisKinds - includes `code-quality` when deprecated `quality-queries` input is used",
68+
async (t) => {
69+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
70+
requiredInputStub.withArgs("analysis-kinds").returns("code-scanning");
71+
const optionalInputStub = sinon.stub(actionsUtil, "getOptionalInput");
72+
optionalInputStub.withArgs("quality-queries").returns("code-quality");
73+
const result = await getAnalysisKinds(getRunnerLogger(true), true);
74+
t.assert(result.includes(AnalysisKind.CodeScanning));
75+
t.assert(result.includes(AnalysisKind.CodeQuality));
76+
},
77+
);
78+
79+
test.serial(
80+
"getAnalysisKinds - throws if `analysis-kinds` input is invalid",
81+
async (t) => {
82+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
83+
requiredInputStub.withArgs("analysis-kinds").returns("no-such-thing");
84+
await t.throwsAsync(getAnalysisKinds(getRunnerLogger(true), true));
85+
},
86+
);
7887

7988
// Test the compatibility matrix by looping through all analysis kinds.
8089
const analysisKinds = Object.values(AnalysisKind);
@@ -86,25 +95,31 @@ for (let i = 0; i < analysisKinds.length; i++) {
8695

8796
if (analysisKind === otherAnalysis) continue;
8897
if (compatibilityMatrix[analysisKind].has(otherAnalysis)) {
89-
test(`getAnalysisKinds - allows ${analysisKind} with ${otherAnalysis}`, async (t) => {
90-
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
91-
requiredInputStub
92-
.withArgs("analysis-kinds")
93-
.returns([analysisKind, otherAnalysis].join(","));
94-
const result = await getAnalysisKinds(getRunnerLogger(true), true);
95-
t.is(result.length, 2);
96-
});
98+
test.serial(
99+
`getAnalysisKinds - allows ${analysisKind} with ${otherAnalysis}`,
100+
async (t) => {
101+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
102+
requiredInputStub
103+
.withArgs("analysis-kinds")
104+
.returns([analysisKind, otherAnalysis].join(","));
105+
const result = await getAnalysisKinds(getRunnerLogger(true), true);
106+
t.is(result.length, 2);
107+
},
108+
);
97109
} else {
98-
test(`getAnalysisKinds - throws if ${analysisKind} is enabled with ${otherAnalysis}`, async (t) => {
99-
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
100-
requiredInputStub
101-
.withArgs("analysis-kinds")
102-
.returns([analysisKind, otherAnalysis].join(","));
103-
await t.throwsAsync(getAnalysisKinds(getRunnerLogger(true), true), {
104-
instanceOf: ConfigurationError,
105-
message: `${analysisKind} and ${otherAnalysis} cannot be enabled at the same time`,
106-
});
107-
});
110+
test.serial(
111+
`getAnalysisKinds - throws if ${analysisKind} is enabled with ${otherAnalysis}`,
112+
async (t) => {
113+
const requiredInputStub = sinon.stub(actionsUtil, "getRequiredInput");
114+
requiredInputStub
115+
.withArgs("analysis-kinds")
116+
.returns([analysisKind, otherAnalysis].join(","));
117+
await t.throwsAsync(getAnalysisKinds(getRunnerLogger(true), true), {
118+
instanceOf: ConfigurationError,
119+
message: `${analysisKind} and ${otherAnalysis} cannot be enabled at the same time`,
120+
});
121+
},
122+
);
108123
}
109124
}
110125
}
@@ -122,44 +137,50 @@ test("Code Scanning configuration does not accept other SARIF extensions", (t) =
122137
}
123138
});
124139

125-
test("Risk Assessment configuration transforms SARIF upload payload", (t) => {
126-
process.env[EnvVar.RISK_ASSESSMENT_ID] = "1";
127-
const payload = RiskAssessment.transformPayload({
128-
commit_oid: "abc",
129-
sarif: "sarif",
130-
ref: "ref",
131-
workflow_run_attempt: 1,
132-
workflow_run_id: 1,
133-
checkout_uri: "uri",
134-
tool_names: [],
135-
}) as AssessmentPayload;
136-
137-
const expected: AssessmentPayload = { sarif: "sarif", assessment_id: 1 };
138-
t.deepEqual(expected, payload);
139-
});
140-
141-
test("Risk Assessment configuration throws for negative assessment IDs", (t) => {
142-
process.env[EnvVar.RISK_ASSESSMENT_ID] = "-1";
143-
t.throws(
144-
() =>
145-
RiskAssessment.transformPayload({
146-
commit_oid: "abc",
147-
sarif: "sarif",
148-
ref: "ref",
149-
workflow_run_attempt: 1,
150-
workflow_run_id: 1,
151-
checkout_uri: "uri",
152-
tool_names: [],
153-
}),
154-
{
155-
instanceOf: Error,
156-
message: (msg) =>
157-
msg.startsWith(`${EnvVar.RISK_ASSESSMENT_ID} must not be negative: `),
158-
},
159-
);
160-
});
161-
162-
test("Risk Assessment configuration throws for invalid IDs", (t) => {
140+
test.serial(
141+
"Risk Assessment configuration transforms SARIF upload payload",
142+
(t) => {
143+
process.env[EnvVar.RISK_ASSESSMENT_ID] = "1";
144+
const payload = RiskAssessment.transformPayload({
145+
commit_oid: "abc",
146+
sarif: "sarif",
147+
ref: "ref",
148+
workflow_run_attempt: 1,
149+
workflow_run_id: 1,
150+
checkout_uri: "uri",
151+
tool_names: [],
152+
}) as AssessmentPayload;
153+
154+
const expected: AssessmentPayload = { sarif: "sarif", assessment_id: 1 };
155+
t.deepEqual(expected, payload);
156+
},
157+
);
158+
159+
test.serial(
160+
"Risk Assessment configuration throws for negative assessment IDs",
161+
(t) => {
162+
process.env[EnvVar.RISK_ASSESSMENT_ID] = "-1";
163+
t.throws(
164+
() =>
165+
RiskAssessment.transformPayload({
166+
commit_oid: "abc",
167+
sarif: "sarif",
168+
ref: "ref",
169+
workflow_run_attempt: 1,
170+
workflow_run_id: 1,
171+
checkout_uri: "uri",
172+
tool_names: [],
173+
}),
174+
{
175+
instanceOf: Error,
176+
message: (msg) =>
177+
msg.startsWith(`${EnvVar.RISK_ASSESSMENT_ID} must not be negative: `),
178+
},
179+
);
180+
},
181+
);
182+
183+
test.serial("Risk Assessment configuration throws for invalid IDs", (t) => {
163184
process.env[EnvVar.RISK_ASSESSMENT_ID] = "foo";
164185
t.throws(
165186
() =>

src/analyze.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ setupTests(test);
3232
* - Checks that the duration fields are populated for the correct language.
3333
* - Checks that the QA telemetry status report fields are populated when the QA feature flag is enabled.
3434
*/
35-
test("status report fields", async (t) => {
35+
test.serial("status report fields", async (t) => {
3636
return await util.withTmpDir(async (tmpDir) => {
3737
setupActionsVars(tmpDir, tmpDir);
3838

0 commit comments

Comments
 (0)