-
Notifications
You must be signed in to change notification settings - Fork 201
/
gh-pages.test.ts
167 lines (142 loc) · 4.94 KB
/
gh-pages.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import { execPromise } from "@auto-it/core";
import GhPages, { IGhPagesPluginOptions } from "../src";
import { makeHooks } from "@auto-it/core/dist/utils/make-hooks";
import { dummyLog } from "@auto-it/core/dist/utils/logger";
import { execSync } from "child_process";
const execSyncSpy = execSync as jest.Mock;
jest.mock("child_process");
const execSpy = execPromise as jest.Mock;
jest.mock("@auto-it/core");
/** Create a test for gh-pages plugin */
function createTest(
options: IGhPagesPluginOptions,
autoOverrides: Record<string, any> = {}
) {
const releasedLabel = new GhPages(options);
const hooks = makeHooks();
releasedLabel.apply({
hooks,
logger: dummyLog(),
setGitUser: () => undefined,
...autoOverrides,
git: autoOverrides.git || {},
} as any);
return hooks;
}
describe("Gh-Pages Plugin", () => {
beforeEach(() => {
execSpy.mockReset();
});
describe("beforeShipit", () => {
test("should not release on anything but a latest release", async () => {
const hooks = createTest({ dir: "test" });
await hooks.beforeShipIt.promise({ releaseType: "canary" });
await hooks.beforeShipIt.promise({ releaseType: "next" });
await hooks.beforeShipIt.promise({ releaseType: "old" });
expect(execSpy).not.toHaveBeenCalled();
});
test("should not release on anything on a dry run", async () => {
const hooks = createTest({ dir: "test" });
await hooks.beforeShipIt.promise({ releaseType: "latest", dryRun: true });
expect(execSpy).not.toHaveBeenCalled();
});
test("should not release if there is a version bump", async () => {
const hooks = createTest({ dir: "test" }, { getVersion: () => "patch" });
await hooks.beforeShipIt.promise({ releaseType: "latest" });
expect(execSpy).not.toHaveBeenCalled();
});
test("should not release if there is no matching PR", async () => {
const hooks = createTest(
{ dir: "test" },
{
getVersion: () => "",
git: { getSha: () => "123", matchCommitToPr: () => undefined },
}
);
await hooks.beforeShipIt.promise({ releaseType: "latest" });
expect(execSpy).not.toHaveBeenCalled();
});
test("should not release if PR doesn't have documentation label", async () => {
const hooks = createTest(
{ dir: "test" },
{
getVersion: () => "",
git: { getSha: () => "123", matchCommitToPr: () => ({ labels: [] }) },
}
);
await hooks.beforeShipIt.promise({ releaseType: "latest" });
expect(execSpy).not.toHaveBeenCalled();
});
test("should release if noVersion + documentation label", async () => {
const hooks = createTest(
{ dir: "test" },
{
getVersion: () => "",
git: {
getSha: () => "123",
matchCommitToPr: () => ({ labels: ["documentation"] }),
},
}
);
await hooks.beforeShipIt.promise({ releaseType: "latest" });
expect(execSpy).toHaveBeenCalled();
});
});
describe("afterRelease", () => {
test("should not release if there is not GitHub release", async () => {
const hooks = createTest({ dir: "test" });
await hooks.afterRelease.promise({ response: undefined } as any);
expect(execSpy).not.toHaveBeenCalled();
});
test("should not release if it was pre-release", async () => {
const hooks = createTest({ dir: "test" });
await hooks.afterRelease.promise({
response: { data: { prerelease: true } },
} as any);
expect(execSpy).not.toHaveBeenCalled();
});
test("should run build command if present", async () => {
const buildCommand = "dew it";
const hooks = createTest({
dir: "test",
buildCommand,
});
await hooks.afterRelease.promise({
response: { data: { prerelease: false } },
} as any);
expect(execSyncSpy).toHaveBeenCalledWith(buildCommand);
});
test("should successfully deploy to gh-pages", async () => {
const hooks = createTest({ dir: "test" });
await hooks.afterRelease.promise({
response: { data: { prerelease: false } },
} as any);
expect(execSpy).toHaveBeenCalledWith("npx", [
"push-dir",
"--cleanup",
false,
"--remote=undefined",
"--dir=test",
"--branch=gh-pages",
'--message="Update docs [skip ci]"',
]);
});
test("should use verbose logs", async () => {
const logger = dummyLog();
logger.logLevel = "verbose";
const hooks = createTest({ dir: "test" }, { logger });
await hooks.afterRelease.promise({
response: { data: { prerelease: false } },
} as any);
expect(execSpy).toHaveBeenCalledWith("npx", [
"push-dir",
"--cleanup",
"--verbose",
"--remote=undefined",
"--dir=test",
"--branch=gh-pages",
'--message="Update docs [skip ci]"',
]);
});
});
});