github-pages-deploy-action/__tests__/main.test.ts
James Ives 71b19fd2fb
Package Exporting (#181)
* Corrects exporting

* README Changes

* Forgot the compiled code.

* Configuration changes

* Moving action package

* Update README.md

* Update README.md

* Improving example

* Update README.md

* Update src/lib.ts

Co-Authored-By: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com>

* Correctly building types

* Update README.md

* Configuration update

* Update README.md

* Re-assigning

* Missing chnage

* More changes

* Some more information

* Setting changes to repositoryPath and tokenType

* Compiling

* Update package.json

* Token hiding

* Package Exporting Changes (#185)

* Initiial Changes

* Changes to action

* Compiled

* Added better logging for when debug is off...

* Removing base branch logging as it's not really required

* throw new Error -> throw

* Debug flag as an variable

* Update README.md

* More README Changes

* Update README.md

* Update README.md

* Update README.md

* error.message

* Fixes the debug flag

* Changing the directory routing for shell scripting

* Tidying!

* Changing to const

* Promotion

Co-authored-by: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com>
2020-03-02 07:52:38 -05:00

65 lines
1.5 KiB
TypeScript

// Initial env variable setup for tests.
process.env["INPUT_FOLDER"] = "build";
process.env["GITHUB_SHA"] = "123";
process.env["INPUT_DEBUG"] = "debug";
import "../src/main";
import { action } from "../src/constants";
import run from "../src/lib";
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(),
getInput: jest.fn(),
exportVariable: jest.fn()
}));
describe("main", () => {
afterEach(() => {
Object.assign(action, JSON.parse(originalAction));
});
it("should run through the commands", async () => {
Object.assign(action, {
repositoryPath: "JamesIves/github-pages-deploy-action",
folder: "build",
branch: "branch",
gitHubToken: "123",
pusher: {
name: "asd",
email: "as@cat"
},
isTest: false,
debug: true
});
await run(action);
expect(execute).toBeCalledTimes(19);
});
it("should throw if an error is encountered", async () => {
Object.assign(action, {
folder: "build",
branch: "branch",
baseBranch: "master",
gitHubToken: null,
ssh: null,
accessToken: null,
pusher: {
name: "asd",
email: "as@cat"
},
isTest: true
});
await run(action);
expect(execute).toBeCalledTimes(0);
expect(setFailed).toBeCalledTimes(1);
});
});