Skip to content

Commit 9fe42f6

Browse files
committed
Add some unit tests for sync-checks.ts
1 parent c5a984e commit 9fe42f6

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

pr-checks/sync-checks.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env npx tsx
2+
3+
/*
4+
Tests for the sync-checks.ts script
5+
*/
6+
7+
import * as assert from "node:assert/strict";
8+
import { describe, it } from "node:test";
9+
10+
import { CheckInfo, Exclusions, removeExcluded } from "./sync-checks";
11+
12+
const toCheckInfo = (name: string) =>
13+
({ context: name, app_id: -1 }) satisfies CheckInfo;
14+
15+
const expectedPartialMatches = ["PR Check - Foo", "https://example.com"].map(
16+
toCheckInfo,
17+
);
18+
19+
const expectedExactMatches = ["CodeQL", "Update"].map(toCheckInfo);
20+
21+
const testChecks = expectedExactMatches.concat(expectedPartialMatches);
22+
23+
const emptyExclusions: Exclusions = {
24+
is: [],
25+
contains: [],
26+
};
27+
28+
describe("removeExcluded", async () => {
29+
await it("retains all checks if no exclusions are configured", () => {
30+
const retained = removeExcluded(emptyExclusions, testChecks);
31+
assert.deepEqual(retained, testChecks);
32+
});
33+
34+
await it("removes exact matches", () => {
35+
const retained = removeExcluded(
36+
{ ...emptyExclusions, is: ["CodeQL", "Update"] },
37+
testChecks,
38+
);
39+
assert.deepEqual(retained, expectedPartialMatches);
40+
});
41+
42+
await it("removes partial matches", () => {
43+
const retained = removeExcluded(
44+
{ ...emptyExclusions, contains: ["https://", "PR Check"] },
45+
testChecks,
46+
);
47+
assert.deepEqual(retained, expectedExactMatches);
48+
});
49+
});

pr-checks/sync-checks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const codeqlActionRepo = {
3030
};
3131

3232
/** Represents a configuration of which checks should not be set up as required checks. */
33-
interface Exclusions {
33+
export interface Exclusions {
3434
/** A list of strings that, if contained in a check name, are excluded. */
3535
contains: string[];
3636
/** A list of check names that are excluded if their name is an exact match. */
@@ -55,7 +55,7 @@ function getApiClient(token: string): ApiClient {
5555
* Represents information about a check run. We track the `app_id` that generated the check,
5656
* because the API will require it in addition to the name in the future.
5757
*/
58-
interface CheckInfo {
58+
export interface CheckInfo {
5959
/** The display name of the check. */
6060
context: string;
6161
/** The ID of the app that generated the check. */

0 commit comments

Comments
 (0)