diff --git a/src/action-common.ts b/src/action-common.ts index 5af58f08b..424a9181d 100644 --- a/src/action-common.ts +++ b/src/action-common.ts @@ -1,3 +1,4 @@ +import { ActionsEnv } from "./actions-util"; import { Env } from "./environment"; import { FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; @@ -12,6 +13,10 @@ export interface FeatureState { /** Information about environment variables. */ env: Env; }; + Actions: { + /** Access to Actions-related functionality. */ + actions: ActionsEnv; + }; FeatureFlags: { /** Information about enabled feature flags. */ features: FeatureEnablement; diff --git a/src/testing-utils.ts b/src/testing-utils.ts index 64a62175a..2f8506ca3 100644 --- a/src/testing-utils.ts +++ b/src/testing-utils.ts @@ -11,7 +11,12 @@ import nock from "nock"; import * as sinon from "sinon"; import { ActionState, StateFeature } from "./action-common"; -import { ActionsEnv, ActionsEnvVars, getActionVersion } from "./actions-util"; +import { + ActionsEnv, + ActionsEnvVars, + getActionsEnv, + getActionVersion, +} from "./actions-util"; import { AnalysisKind } from "./analyses"; import * as apiClient from "./api-client"; import { GitHubApiDetails } from "./api-client"; @@ -190,7 +195,7 @@ export function getTestActionsEnv(): ActionsEnv { } /** For testing purposes, we make all available state features accessible in `TestEnv`. */ -type AllState = ["Logger", "Env", "FeatureFlags"]; +type AllState = ["Logger", "Env", "Actions", "FeatureFlags"]; /** * Wraps a function that accepts an `ActionState` for testing in different environments. @@ -218,6 +223,7 @@ export class TestEnv< : { logger: new RecordingLogger(), env: getTestEnv(), + actions: getActionsEnv(), features: createFeatures([]), }; } @@ -256,6 +262,12 @@ export class TestEnv< return result; } + public withActions(actions: ActionsEnv): TestEnv { + const result = this.clone(); + result.state.actions = actions; + return result; + } + call(): R { if (!this.args) { throw new Error("Trying to call function in TestEnv without arguments.");