Skip to content

Commit 3ca82bb

Browse files
committed
Change withActions to only allow mutations
1 parent 42a3b94 commit 3ca82bb

2 files changed

Lines changed: 10 additions & 20 deletions

File tree

‎src/config/inputs.test.ts‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from "ava";
22
import sinon from "sinon";
33

4-
import { getActionsEnv } from "../actions-util";
4+
import { ActionsEnv } from "../actions-util";
55
import { Feature } from "../feature-flags";
66
import { RepositoryPropertyName } from "../feature-flags/properties";
77
import { callee } from "../testing-utils";
@@ -22,32 +22,26 @@ const expectedRepositoryPropertyResult: ComputedInput = {
2222
value: "repo-property-input-value",
2323
};
2424

25-
function stubGetToolsInput() {
26-
const actions = getActionsEnv();
25+
function stubGetToolsInput(actions: ActionsEnv) {
2726
sinon
2827
.stub(actions, "getOptionalInput")
2928
.withArgs(InputName.Tools)
3029
.returns(expectedWorkflowResult.value);
31-
return actions;
3230
}
3331

3432
const workflowLogMessage = `Using ${InputName.Tools} input from workflow:`;
3533

3634
test("getToolsInput - returns workflow input if available", async (t) => {
37-
const actions = stubGetToolsInput();
38-
3935
await callee(getToolsInput)
40-
.withActions(actions)
36+
.withActions(stubGetToolsInput)
4137
.withArgs({})
4238
.logs(t, workflowLogMessage)
4339
.passes(t.deepEqual, expectedWorkflowResult);
4440
});
4541

4642
test("getToolsInput - returns repository property value if enforced", async (t) => {
47-
const actions = stubGetToolsInput();
48-
4943
const target = callee(getToolsInput)
50-
.withActions(actions)
44+
.withActions(stubGetToolsInput)
5145
.withArgs({
5246
[RepositoryPropertyName.TOOLS]: `!${expectedRepositoryPropertyResult.value}`,
5347
});
@@ -65,10 +59,8 @@ test("getToolsInput - returns repository property value if enforced", async (t)
6559
});
6660

6761
test("getToolsInput - prefers workflow input", async (t) => {
68-
const actions = stubGetToolsInput();
69-
7062
const target = callee(getToolsInput)
71-
.withActions(actions)
63+
.withActions(stubGetToolsInput)
7264
.withArgs({
7365
[RepositoryPropertyName.TOOLS]: expectedRepositoryPropertyResult.value,
7466
});

‎src/testing-utils.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ type DelayedCheck<
228228
Fs extends ReadonlyArray<AllState[number]>,
229229
> = (env: Readonly<BaseEnvBuilder<Args, R, Fs>>) => Promise<any>;
230230

231-
export type ValueOrMutation<T> = T | ((val: T) => void);
231+
export type Mutation<T> = (val: T) => void;
232+
export type ValueOrMutation<T> = T | Mutation<T>;
232233

233234
/**
234235
* Wraps a function that accepts an `ActionState` for testing in different environments.
@@ -324,13 +325,10 @@ abstract class BaseEnvBuilder<
324325
return result;
325326
}
326327

327-
public withActions(arg: ValueOrMutation<ActionsEnv>): this {
328+
/** Applies `fn` to the `ActionsEnv`. */
329+
public withActions(fn: Mutation<ActionsEnv>): this {
328330
const result = this.clone();
329-
if (typeof arg === "function") {
330-
arg(result.state.actions);
331-
} else {
332-
result.state.actions = arg;
333-
}
331+
fn(result.state.actions);
334332
return result;
335333
}
336334

0 commit comments

Comments
 (0)