2020-01-20 05:16:28 +08:00
|
|
|
// Initial env variable setup for tests.
|
|
|
|
process.env["INPUT_FOLDER"] = "build";
|
|
|
|
process.env["GITHUB_SHA"] = "123";
|
2020-03-02 20:52:38 +08:00
|
|
|
process.env["INPUT_DEBUG"] = "debug";
|
2020-01-20 05:16:28 +08:00
|
|
|
|
2020-03-02 20:52:38 +08:00
|
|
|
import "../src/main";
|
2020-01-20 05:16:28 +08:00
|
|
|
import { action } from "../src/constants";
|
2020-03-02 20:52:38 +08:00
|
|
|
import run from "../src/lib";
|
2020-01-20 05:16:28 +08:00
|
|
|
import { execute } from "../src/execute";
|
|
|
|
import { setFailed } from "@actions/core";
|
|
|
|
|
|
|
|
const originalAction = JSON.stringify(action);
|
|
|
|
|
|
|
|
jest.mock("../src/execute", () => ({
|
|
|
|
execute: jest.fn()
|
|
|
|
}));
|
|
|
|
|
|
|
|
jest.mock("@actions/core", () => ({
|
|
|
|
setFailed: jest.fn(),
|
2020-03-02 20:52:38 +08:00
|
|
|
getInput: jest.fn(),
|
|
|
|
exportVariable: jest.fn()
|
2020-01-20 05:16:28 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
describe("main", () => {
|
|
|
|
afterEach(() => {
|
|
|
|
Object.assign(action, JSON.parse(originalAction));
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should run through the commands", async () => {
|
|
|
|
Object.assign(action, {
|
2020-03-02 20:52:38 +08:00
|
|
|
repositoryPath: "JamesIves/github-pages-deploy-action",
|
|
|
|
folder: "build",
|
2020-01-20 05:16:28 +08:00
|
|
|
branch: "branch",
|
|
|
|
gitHubToken: "123",
|
|
|
|
pusher: {
|
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
},
|
2020-03-02 20:52:38 +08:00
|
|
|
isTest: false,
|
|
|
|
debug: true
|
2020-01-20 05:16:28 +08:00
|
|
|
});
|
2020-03-02 20:52:38 +08:00
|
|
|
await run(action);
|
|
|
|
expect(execute).toBeCalledTimes(19);
|
2020-01-20 05:16:28 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should throw if an error is encountered", async () => {
|
|
|
|
Object.assign(action, {
|
2020-03-02 20:52:38 +08:00
|
|
|
folder: "build",
|
2020-01-20 05:16:28 +08:00
|
|
|
branch: "branch",
|
|
|
|
baseBranch: "master",
|
|
|
|
gitHubToken: null,
|
|
|
|
ssh: null,
|
|
|
|
accessToken: null,
|
|
|
|
pusher: {
|
|
|
|
name: "asd",
|
|
|
|
email: "as@cat"
|
|
|
|
},
|
|
|
|
isTest: true
|
|
|
|
});
|
2020-03-02 20:52:38 +08:00
|
|
|
await run(action);
|
|
|
|
expect(execute).toBeCalledTimes(0);
|
2020-01-20 05:16:28 +08:00
|
|
|
expect(setFailed).toBeCalledTimes(1);
|
|
|
|
});
|
|
|
|
});
|