/
auto-canary-local.test.ts
56 lines (45 loc) · 1.34 KB
/
auto-canary-local.test.ts
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { Auto } from "../auto";
import SEMVER from "../semver";
import { dummyLog } from "../utils/logger";
jest.mock("env-ci", () => () => ({
branch: "local-test",
}));
const defaults = {
owner: "foo",
repo: "bar",
};
process.env.GH_TOKEN = "XXXX";
jest.mock("@octokit/rest", () => {
const Octokit = class MockOctokit {
static plugin = () => Octokit;
authenticate = () => undefined;
repos = {
get: jest.fn().mockReturnValue({}),
};
hook = {
error: () => undefined,
};
};
return { Octokit };
});
test("shipit should publish canary in locally when not on baseBranch", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
auto.logger = dummyLog();
// @ts-ignore
auto.checkClean = () => Promise.resolve(true);
await auto.loadConfig();
auto.git!.getLatestRelease = () => Promise.resolve("1.2.3");
auto.git!.getSha = () => Promise.resolve("abcdefghijklmnop");
jest.spyOn(auto.git!, "createComment").mockImplementation();
auto.release!.getCommitsInRelease = () => Promise.resolve([]);
auto.release!.getCommits = () => Promise.resolve([]);
const canary = jest.fn();
auto.hooks.canary.tap("test", canary);
await auto.shipit();
expect(canary).toHaveBeenCalledWith(
expect.objectContaining({
bump: SEMVER.patch,
canaryIdentifier: "-canary.abcdefg",
})
);
});