forked from actions-rs/core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d8d76b
commit d47048d
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import * as core from "@actions/core"; | ||
import * as github from "@actions/github"; | ||
|
||
import * as io from "@actions/io"; | ||
|
||
import { Cross } from "core"; | ||
|
||
jest.mock("@actions/exec"); | ||
jest.mock("@actions/cache"); | ||
|
||
describe("cross", () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
github.context.sha = "sha"; | ||
|
||
jest.spyOn(github.context, "repo", "get").mockReturnValue({ | ||
repo: "repo", | ||
owner: "owner", | ||
}); | ||
}); | ||
|
||
it("Cross", async () => { | ||
const spy = jest.spyOn(io, "which").mockResolvedValue("/home/user/.cross/bin/cross"); | ||
|
||
await expect(Cross.get()).resolves.not.toBeNull(); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Cross not found", async () => { | ||
const spy = jest.spyOn(io, "which").mockRejectedValue(new Error("Could not find path to cross")); | ||
|
||
await expect(Cross.get()).rejects.toThrow("Could not find path to cross"); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Cross install", async () => { | ||
const spy = jest.spyOn(io, "which").mockResolvedValueOnce("/home/user/.cross/bin/cross"); | ||
const spy2 = jest.spyOn(process, "cwd").mockReturnValueOnce("/somewhere/on/the/machine"); | ||
const spy3 = jest.spyOn(process, "chdir").mockReturnValue(undefined); | ||
|
||
await expect(Cross.install("10.0")).resolves.toBeInstanceOf(Cross); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy2).toHaveBeenCalledTimes(1); | ||
expect(spy3.mock.calls).toMatchObject([["/tmp"], ["/somewhere/on/the/machine"]]); | ||
}); | ||
|
||
it("Cross getOrInstall", async () => { | ||
const spy = jest.spyOn(io, "which").mockResolvedValueOnce("/home/user/.cross/bin/cross"); | ||
|
||
await expect(Cross.getOrInstall()).resolves.toBeInstanceOf(Cross); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it("Cross getOrInstall fail", async () => { | ||
const spy = jest.spyOn(io, "which").mockResolvedValueOnce("/home/user/.cross/bin/cross"); | ||
const spy2 = jest.spyOn(Cross, "get").mockRejectedValue(new Error("Not found")); | ||
const spy3 = jest.spyOn(core, "debug"); | ||
|
||
await expect(Cross.getOrInstall()).resolves.toBeInstanceOf(Cross); | ||
|
||
expect(spy).toHaveBeenCalledTimes(1); | ||
expect(spy2).toHaveBeenCalledTimes(1); | ||
expect(spy3.mock.calls).toMatchObject([["Error: Not found"]]); | ||
}); | ||
}); |