-
-
Notifications
You must be signed in to change notification settings - Fork 413
Expand file tree
/
Copy pathutils.test.ts
More file actions
244 lines (199 loc) · 5.69 KB
/
Copy pathutils.test.ts
File metadata and controls
244 lines (199 loc) · 5.69 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import { createFixture } from "fs-fixture";
import { afterEach, expect, test, vi } from "vitest";
import {
BumpLevels,
getChangelogEntry,
sortTheThings,
throwOnRemovedCommitModeInput,
validateChangesetsCliVersion,
isObject,
isString,
} from "./utils.ts";
let changelog = `# @keystone-alpha/email
## 3.0.1
### Patch Changes
- [19fe6c1b](https://github.com/keystonejs/keystone-5/commit/19fe6c1b):
Move frontmatter in docs into comments
## 3.0.0
### Major Changes
- [2164a779](https://github.com/keystonejs/keystone-5/commit/2164a779):
- Replace jade with pug because Jade was renamed to Pug, and \`jade\` package is outdated
### Patch Changes
- [81dc0be5](https://github.com/keystonejs/keystone-5/commit/81dc0be5):
- Update dependencies
## 2.0.0
- [patch][b69fb9b7](https://github.com/keystonejs/keystone-5/commit/b69fb9b7):
- Update dev devependencies
- [major][f97e4ecf](https://github.com/keystonejs/keystone-5/commit/f97e4ecf):
- Export { emailSender } as the API, rather than a default export
## 1.0.2
- [patch][7417ea3a](https://github.com/keystonejs/keystone-5/commit/7417ea3a):
- Update patch-level dependencies
## 1.0.1
- [patch][1f0bc236](https://github.com/keystonejs/keystone-5/commit/1f0bc236):
- Update the package.json author field to "The Keystone Development Team"
## 1.0.0
- [major] 8b6734ae:
- This is the first release of keystone-alpha (previously voussoir).
All packages in the \`@voussoir\` namespace are now available in the \`@keystone-alpha\` namespace, starting at version \`1.0.0\`.
To upgrade your project you must update any \`@voussoir/<foo>\` dependencies in \`package.json\` to point to \`@keystone-alpha/<foo>: "^1.0.0"\` and update any \`require\`/\`import\` statements in your code.
# @voussoir/email
## 0.0.2
- [patch] 113e16d4:
- Remove unused dependencies
- [patch] 625c1a6d:
- Update mjml-dependency
`;
afterEach(() => {
vi.unstubAllEnvs();
});
test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.0");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.major);
});
test("it works", () => {
let entry = getChangelogEntry(changelog, "3.0.1");
expect(entry.content).toMatchSnapshot();
expect(entry.highestLevel).toBe(BumpLevels.patch);
});
test("it sorts the things right", () => {
let things = [
{
name: "a",
highestLevel: BumpLevels.major,
private: true,
},
{
name: "b",
highestLevel: BumpLevels.patch,
private: false,
},
{
name: "c",
highestLevel: BumpLevels.major,
private: false,
},
];
expect(things.sort(sortTheThings)).toMatchSnapshot();
});
test.each([
["commit-mode", "git-cli", "push-with-git-cli: true"],
["commit-mode", "github-api", "push-with-git-cli: false"],
["commitMode", "git-cli", "push-with-git-cli: true"],
["commitMode", "github-api", "push-with-git-cli: false"],
])(
"explains how to migrate the removed %s input from %s",
(inputName, value, replacement) => {
vi.stubEnv(`INPUT_${inputName.toUpperCase()}`, value);
expect(() => throwOnRemovedCommitModeInput()).toThrow(replacement);
},
);
test("throws when the project declares Changesets CLI v2", async () => {
await using fixture = await createFixture({
"package.json": JSON.stringify({
name: "project",
devDependencies: { "@changesets/cli": "^2.29.7" },
}),
"package-lock.json": "",
});
await expect(validateChangesetsCliVersion(fixture.path)).rejects.toThrow(
"This version of the Changesets action is designed to work with Changesets CLI v3. Changesets CLI v2 is not supported; use Changesets action v1 instead, which is compatible with CLI v2.",
);
});
test("accepts a Changesets CLI v3 contract without an installed CLI", async () => {
await using fixture = await createFixture({
"package.json": JSON.stringify({
name: "project",
devDependencies: { "@changesets/cli": "^3.0.0" },
}),
"package-lock.json": "",
});
await expect(
validateChangesetsCliVersion(fixture.path),
).resolves.toBeUndefined();
});
test("throws when the project has Changesets CLI v2 installed", async () => {
await using fixture = await createFixture({
"package.json": JSON.stringify({
name: "project",
devDependencies: { "@changesets/cli": "^3.0.0" },
}),
"package-lock.json": "",
"node_modules/@changesets/cli/package.json": JSON.stringify({
name: "@changesets/cli",
version: "2.29.7",
}),
});
await expect(validateChangesetsCliVersion(fixture.path)).rejects.toThrow(
"This version of the Changesets action is designed to work with Changesets CLI v3. Changesets CLI v2 is not supported; use Changesets action v1 instead, which is compatible with CLI v2.",
);
});
test.each([
{
input: null,
expected: false,
},
{
input: undefined,
expected: false,
},
{
input: "changesets",
expected: false,
},
{
input: 1,
expected: false,
},
{
input: true,
expected: false,
},
{
input: [],
expected: false,
},
{
input: {},
expected: true,
},
])("isObject: $input should return $expected", ({ input, expected }) => {
expect(isObject(input)).toBe(expected);
});
test.each([
{
input: null,
expected: false,
},
{
input: undefined,
expected: false,
},
{
input: "changesets",
expected: true,
},
{
input: 1,
expected: false,
},
{
input: true,
expected: false,
},
{
input: [],
expected: false,
},
{
input: {},
expected: false,
},
{
input: () => "test",
expected: false,
},
])("isString: $input should return $expected", ({ input, expected }) => {
expect(isString(input)).toBe(expected);
});