-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.test.js
42 lines (36 loc) · 1.26 KB
/
main.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// @flow
import * as core from "@actions/core";
import main from "../../src/main";
jest.mock("process");
jest.mock("@actions/core");
describe("main", () => {
const OLD_ENV = process.env;
it("calls setOutput when successful", async () => {
process.env = {
INPUT_FILE: "env/test.yml",
INPUT_A: "foo.bar",
INPUT_B: "provider.stage",
NOT_INPUT_C: "c",
INPUT_D: "qux[].bar",
INPUT_E: "foo",
INPUT_F: '"foo-bar"'
};
await main();
expect(core.setOutput).toHaveBeenCalledWith("a", "baz");
expect(core.setOutput).toHaveBeenCalledWith("b", "green");
expect(core.setOutput).toHaveBeenCalledWith("d", '["hello","world"]');
expect(core.setOutput).toHaveBeenCalledWith("e", '{"bar":"baz"}');
expect(core.setOutput).toHaveBeenCalledWith("f", 7);
});
it("calls setFailed when unsuccessful", async () => {
// $FlowFixMe
process.exit = jest.fn();
process.env = { INPUT_FILE: "env/not-found.yml", INPUT_A: "foo.bar", INPUT_B: "provider.stage", NOT_INPUT_C: "c" };
await main();
expect(core.setFailed).toHaveBeenCalledWith("ENOENT: no such file or directory, open 'env/not-found.yml'");
expect(process.exit).toHaveBeenCalledWith(1);
});
afterAll(() => {
process.env = OLD_ENV;
});
});