-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.test.ts
More file actions
157 lines (133 loc) · 5.25 KB
/
Copy pathoptions.test.ts
File metadata and controls
157 lines (133 loc) · 5.25 KB
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
import { ReleaseError } from "#shared/errors";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { DEFAULT_TYPES, normalizeReleaseScriptsOptions } from "../src/options";
const VALID_OPTIONS = {
githubToken: "ghp_token",
repo: "owner/repo",
} as const;
describe("normalizeReleaseScriptsOptions", () => {
describe("validation", () => {
it("throws ReleaseError when githubToken is empty", () => {
expect(() => normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, githubToken: "" })).toThrow(
ReleaseError,
);
});
it("throws ReleaseError when githubToken is only whitespace", () => {
expect(() =>
normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, githubToken: " " }),
).toThrow(ReleaseError);
});
it("throws ReleaseError when repo has no slash", () => {
expect(() =>
normalizeReleaseScriptsOptions({
...VALID_OPTIONS,
repo: "justarepo" as `${string}/${string}`,
}),
).toThrow(ReleaseError);
});
it("throws ReleaseError when repo is empty string", () => {
expect(() =>
normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, repo: "" as `${string}/${string}` }),
).toThrow(ReleaseError);
});
});
describe("defaults", () => {
it("sets default branch names", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.branch.default).toBe("main");
expect(opts.branch.release).toBe("release/next");
});
it("sets default npm options", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.npm.access).toBe("public");
expect(opts.npm.provenance).toBe(true);
expect(opts.npm.otp).toBeUndefined();
});
it("enables changelog by default", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.changelog.enabled).toBe(true);
expect(opts.changelog.emojis).toBe(true);
expect(opts.changelog.combinePrereleaseIntoFirstStable).toBe(false);
});
it("uses DEFAULT_TYPES when no types provided", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.types).toEqual(DEFAULT_TYPES);
});
it("enables safeguards by default", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.safeguards).toBe(true);
});
it("sets globalCommitMode to dependencies by default", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.globalCommitMode).toBe("dependencies");
});
});
describe("owner/repo parsing", () => {
it("splits repo into owner and repo fields", () => {
const opts = normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, repo: "acme/my-lib" });
expect(opts.owner).toBe("acme");
expect(opts.repo).toBe("my-lib");
});
it("trims whitespace from githubToken", () => {
const opts = normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, githubToken: " tok " });
expect(opts.githubToken).toBe("tok");
});
});
describe("packages option normalization", () => {
it("passes true through as-is", () => {
const opts = normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, packages: true });
expect(opts.packages).toBe(true);
});
it("passes string array through as-is", () => {
const opts = normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, packages: ["@scope/a"] });
expect(opts.packages).toEqual(["@scope/a"]);
});
it("normalizes object form with defaults", () => {
const opts = normalizeReleaseScriptsOptions({ ...VALID_OPTIONS, packages: {} });
expect(opts.packages).toEqual({ include: [], exclude: [], excludePrivate: false });
});
it("preserves provided include/exclude/excludePrivate values", () => {
const opts = normalizeReleaseScriptsOptions({
...VALID_OPTIONS,
packages: { include: ["@a/b"], exclude: ["@c/d"], excludePrivate: true },
});
expect(opts.packages).toEqual({ include: ["@a/b"], exclude: ["@c/d"], excludePrivate: true });
});
});
describe("types merging", () => {
it("merges custom types on top of DEFAULT_TYPES", () => {
const opts = normalizeReleaseScriptsOptions({
...VALID_OPTIONS,
types: { refactor: { title: "♻️ Refactors" } },
});
expect(opts.types.feat).toEqual(DEFAULT_TYPES.feat);
expect(opts.types.refactor).toEqual({ title: "♻️ Refactors" });
});
it("allows overriding a default type", () => {
const opts = normalizeReleaseScriptsOptions({
...VALID_OPTIONS,
types: { feat: { title: "✨ Features" } },
});
expect(opts.types.feat).toEqual({ title: "✨ Features" });
});
});
describe("ci mode", () => {
let previousCi: string | undefined;
beforeEach(() => {
previousCi = process.env.CI;
process.env.CI = "true";
});
afterEach(() => {
if (previousCi === undefined) {
delete process.env.CI;
} else {
process.env.CI = previousCi;
}
});
it("disables prompts when CI=true", () => {
const opts = normalizeReleaseScriptsOptions(VALID_OPTIONS);
expect(opts.prompts.versions).toBe(false);
expect(opts.prompts.packages).toBe(false);
});
});
});