/
next.test.ts
106 lines (88 loc) · 2.53 KB
/
next.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { Auto } from "../auto";
import { dummyLog } from "../utils/logger";
import makeCommitFromMsg from "./make-commit-from-msg";
import execPromise from "../utils/exec-promise";
const exec = jest.fn();
jest.mock("../utils/exec-promise");
// @ts-ignore
execPromise.mockImplementation(exec);
exec.mockResolvedValue("");
jest.mock("../utils/git-reset.ts");
jest.mock("../utils/load-plugins.ts");
jest.mock("env-ci", () => () => ({ isCi: false, branch: "next" }));
const defaults = {
baseBranch: "main",
owner: "foo",
repo: "bar",
};
jest.mock("@octokit/rest", () => {
const Octokit = class MockOctokit {
static plugin = () => Octokit;
authenticate = () => undefined;
search = {
issuesAndPullRequests: () => ({ data: { items: [] } }),
};
repos = {
get: jest.fn().mockReturnValue({}),
};
hook = {
error: () => undefined,
};
issues = {
listLabelsOnIssue: jest.fn().mockReturnValue({ data: [] }),
};
users = {
getAuthenticated: jest.fn().mockResolvedValue({}),
};
};
return { Octokit };
});
// @ts-ignore
jest.mock("gitlog", () => ({
gitlogPromise: () =>
Promise.resolve([
{
rawBody: "foo",
hash: "123",
},
{
rawBody: "foo",
hash: "456",
},
]),
}));
test("falls back to local baseBranch if it doesn't exist on origin", async () => {
const auto = new Auto({ ...defaults, plugins: [] });
// @ts-ignore
auto.checkClean = () => Promise.resolve(true);
auto.logger = dummyLog();
await auto.loadConfig();
auto.remote = "origin";
auto.git!.publish = () => Promise.resolve({ data: {} } as any);
auto.git!.getLastTagNotInBaseBranch = () => Promise.reject(new Error("Test"));
auto.git!.getLatestTagInBranch = () => Promise.reject(new Error("Test"));
auto.git!.getLatestRelease = () => Promise.resolve("abcd");
auto.release!.generateReleaseNotes = () => Promise.resolve("notes");
auto.release!.getCommitsInRelease = () =>
Promise.resolve([
makeCommitFromMsg("Test Commit", { labels: ["skip-release"] }),
]);
jest.spyOn(auto.release!, "getCommits").mockImplementation();
const next = jest.fn();
auto.hooks.next.tap("test", next);
await auto.next({});
expect(exec).toHaveBeenCalledWith("git", [
"rev-list",
"--boundary",
"next...origin/main",
"--left-only",
]);
auto.git!.shaExists = () => Promise.resolve(false);
await auto.next({});
expect(exec).toHaveBeenCalledWith("git", [
"rev-list",
"--boundary",
"next...main",
"--left-only",
]);
});