mirror of
https://github.com/github/codeql-action.git
synced 2026-05-09 15:20:28 +00:00
Add wrapper for test.macro
This commit is contained in:
+27
-3
@@ -2,7 +2,11 @@ import { TextDecoder } from "node:util";
|
||||
import path from "path";
|
||||
|
||||
import * as github from "@actions/github";
|
||||
import { ExecutionContext, TestFn } from "ava";
|
||||
import test, {
|
||||
type ExecutionContext,
|
||||
type MacroDeclarationOptions,
|
||||
type TestFn,
|
||||
} from "ava";
|
||||
import nock from "nock";
|
||||
import * as sinon from "sinon";
|
||||
|
||||
@@ -85,8 +89,8 @@ function wrapOutput(context: TestContext) {
|
||||
};
|
||||
}
|
||||
|
||||
export function setupTests(test: TestFn<any>) {
|
||||
const typedTest = test as TestFn<TestContext>;
|
||||
export function setupTests(testFn: TestFn<any>) {
|
||||
const typedTest = testFn as TestFn<TestContext>;
|
||||
|
||||
typedTest.beforeEach((t) => {
|
||||
// Set an empty CodeQL object so that all method calls will fail
|
||||
@@ -139,6 +143,26 @@ export function setupTests(test: TestFn<any>) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare a reusable test implementation, with better type safety than `test.macro`.
|
||||
*/
|
||||
export function makeMacro<Args extends unknown[]>(
|
||||
decl: MacroDeclarationOptions<Args, unknown>,
|
||||
) {
|
||||
const m = test.macro<Args>(decl);
|
||||
|
||||
const wrapper = (name: string, ...args: Args) => test(name, m, ...args);
|
||||
wrapper.test = (...args: Args) => test(m, ...args);
|
||||
wrapper.serial = (name: string, ...args: Args) =>
|
||||
test.serial(name, m, ...args);
|
||||
// Make the implementation available as `fn`. We don't call it `exec` so
|
||||
// that results from this function are not valid arguments to `test`
|
||||
// or `test.serial`.
|
||||
wrapper.fn = decl.exec;
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default values for environment variables typically set in an Actions
|
||||
* environment. Tests can override individual variables by passing them in the
|
||||
|
||||
Reference in New Issue
Block a user