Skip to content

Commit b009eac

Browse files
committed
Add ActionsEnv support to ActionState
1 parent 26e9e9e commit b009eac

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/action-common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ActionsEnv } from "./actions-util";
12
import { Env } from "./environment";
23
import { FeatureEnablement } from "./feature-flags";
34
import { Logger } from "./logging";
@@ -12,6 +13,10 @@ export interface FeatureState {
1213
/** Information about environment variables. */
1314
env: Env;
1415
};
16+
Actions: {
17+
/** Access to Actions-related functionality. */
18+
actions: ActionsEnv;
19+
};
1520
FeatureFlags: {
1621
/** Information about enabled feature flags. */
1722
features: FeatureEnablement;

src/testing-utils.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ import nock from "nock";
1111
import * as sinon from "sinon";
1212

1313
import { ActionState, StateFeature } from "./action-common";
14-
import { ActionsEnv, ActionsEnvVars, getActionVersion } from "./actions-util";
14+
import {
15+
ActionsEnv,
16+
ActionsEnvVars,
17+
getActionsEnv,
18+
getActionVersion,
19+
} from "./actions-util";
1520
import { AnalysisKind } from "./analyses";
1621
import * as apiClient from "./api-client";
1722
import { GitHubApiDetails } from "./api-client";
@@ -190,7 +195,7 @@ export function getTestActionsEnv(): ActionsEnv {
190195
}
191196

192197
/** For testing purposes, we make all available state features accessible in `TestEnv`. */
193-
type AllState = ["Logger", "Env", "FeatureFlags"];
198+
type AllState = ["Logger", "Env", "Actions", "FeatureFlags"];
194199

195200
/**
196201
* Wraps a function that accepts an `ActionState` for testing in different environments.
@@ -218,6 +223,7 @@ export class TestEnv<
218223
: {
219224
logger: new RecordingLogger(),
220225
env: getTestEnv(),
226+
actions: getActionsEnv(),
221227
features: createFeatures([]),
222228
};
223229
}
@@ -256,6 +262,12 @@ export class TestEnv<
256262
return result;
257263
}
258264

265+
public withActions(actions: ActionsEnv): TestEnv<Args, R, Fs> {
266+
const result = this.clone();
267+
result.state.actions = actions;
268+
return result;
269+
}
270+
259271
call(): R {
260272
if (!this.args) {
261273
throw new Error("Trying to call function in TestEnv without arguments.");

0 commit comments

Comments
 (0)