Add some unit tests for sync-checks.ts

This commit is contained in:
Michael B. Gale
2026-03-13 19:35:44 +00:00
parent 6a3dc8c62e
commit b2bd6a3229
2 changed files with 51 additions and 2 deletions
+49
View File
@@ -0,0 +1,49 @@
#!/usr/bin/env npx tsx
/*
Tests for the sync-checks.ts script
*/
import * as assert from "node:assert/strict";
import { describe, it } from "node:test";
import { CheckInfo, Exclusions, removeExcluded } from "./sync-checks";
const toCheckInfo = (name: string) =>
({ context: name, app_id: -1 }) satisfies CheckInfo;
const expectedPartialMatches = ["PR Check - Foo", "https://example.com"].map(
toCheckInfo,
);
const expectedExactMatches = ["CodeQL", "Update"].map(toCheckInfo);
const testChecks = expectedExactMatches.concat(expectedPartialMatches);
const emptyExclusions: Exclusions = {
is: [],
contains: [],
};
describe("removeExcluded", async () => {
await it("retains all checks if no exclusions are configured", () => {
const retained = removeExcluded(emptyExclusions, testChecks);
assert.deepEqual(retained, testChecks);
});
await it("removes exact matches", () => {
const retained = removeExcluded(
{ ...emptyExclusions, is: ["CodeQL", "Update"] },
testChecks,
);
assert.deepEqual(retained, expectedPartialMatches);
});
await it("removes partial matches", () => {
const retained = removeExcluded(
{ ...emptyExclusions, contains: ["https://", "PR Check"] },
testChecks,
);
assert.deepEqual(retained, expectedExactMatches);
});
});
+2 -2
View File
@@ -30,7 +30,7 @@ const codeqlActionRepo = {
};
/** Represents a configuration of which checks should not be set up as required checks. */
interface Exclusions {
export interface Exclusions {
/** A list of strings that, if contained in a check name, are excluded. */
contains: string[];
/** A list of check names that are excluded if their name is an exact match. */
@@ -55,7 +55,7 @@ function getApiClient(token: string): ApiClient {
* Represents information about a check run. We track the `app_id` that generated the check,
* because the API will require it in addition to the name in the future.
*/
interface CheckInfo {
export interface CheckInfo {
/** The display name of the check. */
context: string;
/** The ID of the app that generated the check. */