|
| 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 | +}); |
0 commit comments