diff --git a/src/actions-util.ts b/src/actions-util.ts index 592a70ace..dea22d5c5 100644 --- a/src/actions-util.ts +++ b/src/actions-util.ts @@ -21,6 +21,21 @@ import { */ declare const __CODEQL_ACTION_VERSION__: string; +/** + * Abstracts over GitHub Actions functions so that we do not have to stub + * global functions in tests. + */ +export interface ActionsEnv { + getOptionalInput: (name: string) => string | undefined; +} + +/** + * Gets the real `ActionsEnv` used by production code. + */ +export function getActionsEnv(): ActionsEnv { + return { getOptionalInput }; +} + /** * Wrapper around core.getInput for inputs that always have a value. * Also see getOptionalInput. diff --git a/src/testing-utils.ts b/src/testing-utils.ts index 1702d6835..2660c21a6 100644 --- a/src/testing-utils.ts +++ b/src/testing-utils.ts @@ -10,7 +10,7 @@ import test, { import nock from "nock"; import * as sinon from "sinon"; -import { getActionVersion } from "./actions-util"; +import { ActionsEnv, getActionVersion } from "./actions-util"; import { AnalysisKind } from "./analyses"; import * as apiClient from "./api-client"; import { GitHubApiDetails } from "./api-client"; @@ -172,6 +172,15 @@ export function makeMacro( return wrapper; } +/** + * Gets an `ActionsEnv` instance for use in tests. + */ +export function getTestActionsEnv(): ActionsEnv { + return { + getOptionalInput: () => undefined, + }; +} + /** * Default values for environment variables typically set in an Actions * environment. Tests can override individual variables by passing them in the