mirror of
https://github.com/github/codeql-action.git
synced 2026-04-30 02:40:12 +00:00
Add some unit tests for sync-checks.ts
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user