@hubspot/npm-scripts 0.3.2 → 0.3.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/package.json +1 -1
- package/src/__tests__/release.test.js +7 -3
- package/src/release/__tests__/steps.test.d.ts +1 -0
- package/src/release/__tests__/steps.test.js +407 -0
- package/src/release/__tests__/validate.test.d.ts +1 -0
- package/src/release/__tests__/validate.test.js +276 -0
- package/src/release/__tests__/version.test.d.ts +1 -0
- package/src/release/__tests__/version.test.js +104 -0
- package/src/release/errors.d.ts +4 -0
- package/src/release/errors.js +9 -0
- package/src/release/steps.d.ts +11 -0
- package/src/release/steps.js +158 -0
- package/src/release/types.d.ts +86 -0
- package/src/release/types.js +1 -0
- package/src/release/validate.d.ts +7 -0
- package/src/release/validate.js +82 -0
- package/src/release/version.d.ts +2 -0
- package/src/release/version.js +23 -0
- package/src/release.d.ts +1 -1
- package/src/release.js +113 -181
- package/src/utils/__tests__/npm.test.js +7 -1
package/README.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# @hubspot/npm-scripts
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
3
8
|
**A collection of scripts for internal HubSpot npm package development and management.**
|
|
4
9
|
|
|
5
10
|
## Tools
|
package/package.json
CHANGED
|
@@ -43,7 +43,7 @@ vi.mock('fs-extra', () => ({
|
|
|
43
43
|
readJsonSync: vi.fn(),
|
|
44
44
|
},
|
|
45
45
|
}));
|
|
46
|
-
vi.mock('semver', async () =>
|
|
46
|
+
vi.mock('semver', async () => vi.importActual('semver'));
|
|
47
47
|
vi.mock('yargs', () => ({
|
|
48
48
|
default: vi.fn(),
|
|
49
49
|
}));
|
|
@@ -171,8 +171,12 @@ describe('release handler', () => {
|
|
|
171
171
|
expect(gitCleanup).toHaveBeenCalledWith(expect.any(String), false, undefined, undefined);
|
|
172
172
|
});
|
|
173
173
|
it('should call gitCleanup when the custom build function throws', async () => {
|
|
174
|
-
const buildFn = vi
|
|
175
|
-
|
|
174
|
+
const buildFn = vi
|
|
175
|
+
.fn()
|
|
176
|
+
.mockRejectedValue(new Error('custom build failed'));
|
|
177
|
+
const handler = setupAndGetHandler(DEFAULT_PACKAGE_JSON, {
|
|
178
|
+
build: buildFn,
|
|
179
|
+
});
|
|
176
180
|
await withExitMocked(() => handler({
|
|
177
181
|
versionIncrement: 'patch',
|
|
178
182
|
tag: 'next',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { exec as _exec, execSync } from 'node:child_process';
|
|
3
|
+
import open from 'open';
|
|
4
|
+
import { logger } from '../../utils/logging.js';
|
|
5
|
+
import { EXIT_CODES } from '../../utils/process.js';
|
|
6
|
+
import { gitCleanup } from '../../utils/git.js';
|
|
7
|
+
import { publish, updateNextTag, updatePreviousTag } from '../../utils/npm.js';
|
|
8
|
+
import { confirm } from '../../utils/prompting.js';
|
|
9
|
+
import { TAG, INCREMENT } from '../../constants/release.js';
|
|
10
|
+
import { confirmRelease, runBuild, tryBuild, createTempBranch, bumpVersion, ensureNpmAuth, tryPublish, updateDistTagsForLatest, finalizeRelease, logReleaseSuccess, } from '../steps.js';
|
|
11
|
+
import { ReleaseError } from '../errors.js';
|
|
12
|
+
vi.mock('util', () => ({ promisify: vi.fn(fn => fn) }));
|
|
13
|
+
vi.mock('node:child_process', () => ({ exec: vi.fn(), execSync: vi.fn() }));
|
|
14
|
+
vi.mock('open', () => ({ default: vi.fn().mockResolvedValue(undefined) }));
|
|
15
|
+
vi.mock('../../utils/logging.js', () => ({
|
|
16
|
+
logger: { log: vi.fn(), error: vi.fn(), success: vi.fn() },
|
|
17
|
+
}));
|
|
18
|
+
vi.mock('../../utils/process.js', () => ({
|
|
19
|
+
EXIT_CODES: { SUCCESS: 0, ERROR: 1 },
|
|
20
|
+
}));
|
|
21
|
+
vi.mock('../../utils/git.js', () => ({ gitCleanup: vi.fn() }));
|
|
22
|
+
vi.mock('../../utils/npm.js', () => ({
|
|
23
|
+
publish: vi.fn(),
|
|
24
|
+
updateNextTag: vi.fn(),
|
|
25
|
+
updatePreviousTag: vi.fn(),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock('../../utils/prompting.js', () => ({ confirm: vi.fn() }));
|
|
28
|
+
const mockedExec = vi.mocked(_exec);
|
|
29
|
+
const mockedExecSync = vi.mocked(execSync);
|
|
30
|
+
const mockedGitCleanup = vi.mocked(gitCleanup);
|
|
31
|
+
const mockedPublish = vi.mocked(publish);
|
|
32
|
+
const mockedUpdateNextTag = vi.mocked(updateNextTag);
|
|
33
|
+
const mockedUpdatePreviousTag = vi.mocked(updatePreviousTag);
|
|
34
|
+
const mockedConfirm = vi.mocked(confirm);
|
|
35
|
+
const REGISTRY = 'https://registry.npmjs.org/';
|
|
36
|
+
const PACKAGE_NAME = '@hubspot/test-package';
|
|
37
|
+
describe('release/steps', () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
vi.resetAllMocks();
|
|
40
|
+
mockedExec.mockResolvedValue({ stdout: '', stderr: '' });
|
|
41
|
+
mockedGitCleanup.mockResolvedValue(undefined);
|
|
42
|
+
mockedPublish.mockResolvedValue(undefined);
|
|
43
|
+
mockedUpdateNextTag.mockResolvedValue(undefined);
|
|
44
|
+
mockedUpdatePreviousTag.mockResolvedValue(undefined);
|
|
45
|
+
mockedConfirm.mockResolvedValue(true);
|
|
46
|
+
});
|
|
47
|
+
describe('confirmRelease', () => {
|
|
48
|
+
it('should log \\nDRY RUN when isDryRun is true', async () => {
|
|
49
|
+
await confirmRelease({
|
|
50
|
+
isDryRun: true,
|
|
51
|
+
currentVersion: '1.0.0-beta.1',
|
|
52
|
+
newVersion: '1.0.1-beta.0',
|
|
53
|
+
tag: TAG.NEXT,
|
|
54
|
+
localVersion: '1.0.0-beta.1',
|
|
55
|
+
versionIncrement: INCREMENT.PATCH,
|
|
56
|
+
});
|
|
57
|
+
expect(logger.log).toHaveBeenCalledWith('\nDRY RUN');
|
|
58
|
+
});
|
|
59
|
+
it('should not log \\nDRY RUN when isDryRun is false', async () => {
|
|
60
|
+
await confirmRelease({
|
|
61
|
+
isDryRun: false,
|
|
62
|
+
currentVersion: '1.0.0-beta.1',
|
|
63
|
+
newVersion: '1.0.1-beta.0',
|
|
64
|
+
tag: TAG.NEXT,
|
|
65
|
+
localVersion: '1.0.0-beta.1',
|
|
66
|
+
versionIncrement: INCREMENT.PATCH,
|
|
67
|
+
});
|
|
68
|
+
expect(logger.log).not.toHaveBeenCalledWith('\nDRY RUN');
|
|
69
|
+
});
|
|
70
|
+
it('should throw ReleaseError with SUCCESS exit code when user declines', async () => {
|
|
71
|
+
mockedConfirm.mockResolvedValue(false);
|
|
72
|
+
await expect(confirmRelease({
|
|
73
|
+
isDryRun: false,
|
|
74
|
+
currentVersion: '1.0.0-beta.1',
|
|
75
|
+
newVersion: '1.0.1-beta.0',
|
|
76
|
+
tag: TAG.NEXT,
|
|
77
|
+
localVersion: '1.0.0-beta.1',
|
|
78
|
+
versionIncrement: INCREMENT.PATCH,
|
|
79
|
+
})).rejects.toMatchObject({ exitCode: EXIT_CODES.SUCCESS });
|
|
80
|
+
});
|
|
81
|
+
it('should only call confirm once for non-latest tags', async () => {
|
|
82
|
+
await confirmRelease({
|
|
83
|
+
isDryRun: false,
|
|
84
|
+
currentVersion: '1.0.0-beta.1',
|
|
85
|
+
newVersion: '1.0.1-beta.0',
|
|
86
|
+
tag: TAG.NEXT,
|
|
87
|
+
localVersion: '1.0.0-beta.1',
|
|
88
|
+
versionIncrement: INCREMENT.PATCH,
|
|
89
|
+
});
|
|
90
|
+
expect(mockedConfirm).toHaveBeenCalledTimes(1);
|
|
91
|
+
});
|
|
92
|
+
it('should only call confirm once when localVersion contains beta and tag is latest', async () => {
|
|
93
|
+
await confirmRelease({
|
|
94
|
+
isDryRun: false,
|
|
95
|
+
currentVersion: '1.0.0',
|
|
96
|
+
newVersion: '1.0.1',
|
|
97
|
+
tag: TAG.LATEST,
|
|
98
|
+
localVersion: '1.0.0-beta.1',
|
|
99
|
+
versionIncrement: INCREMENT.PATCH,
|
|
100
|
+
});
|
|
101
|
+
expect(mockedConfirm).toHaveBeenCalledTimes(1);
|
|
102
|
+
});
|
|
103
|
+
it('should call confirm twice when tag is latest and localVersion has no beta', async () => {
|
|
104
|
+
await confirmRelease({
|
|
105
|
+
isDryRun: false,
|
|
106
|
+
currentVersion: '1.0.0',
|
|
107
|
+
newVersion: '1.0.1',
|
|
108
|
+
tag: TAG.LATEST,
|
|
109
|
+
localVersion: '1.0.0',
|
|
110
|
+
versionIncrement: INCREMENT.PATCH,
|
|
111
|
+
});
|
|
112
|
+
expect(mockedConfirm).toHaveBeenCalledTimes(2);
|
|
113
|
+
});
|
|
114
|
+
it('should throw ReleaseError with SUCCESS when user declines the beta warning', async () => {
|
|
115
|
+
mockedConfirm.mockResolvedValueOnce(true).mockResolvedValueOnce(false);
|
|
116
|
+
await expect(confirmRelease({
|
|
117
|
+
isDryRun: false,
|
|
118
|
+
currentVersion: '1.0.0',
|
|
119
|
+
newVersion: '1.0.1',
|
|
120
|
+
tag: TAG.LATEST,
|
|
121
|
+
localVersion: '1.0.0',
|
|
122
|
+
versionIncrement: INCREMENT.PATCH,
|
|
123
|
+
})).rejects.toMatchObject({ exitCode: EXIT_CODES.SUCCESS });
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('runBuild', () => {
|
|
127
|
+
it('should call the provided build function when given', async () => {
|
|
128
|
+
const build = vi.fn().mockResolvedValue(undefined);
|
|
129
|
+
await runBuild(build);
|
|
130
|
+
expect(build).toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
it('should not run yarn build when a custom build function is provided', async () => {
|
|
133
|
+
const build = vi.fn().mockResolvedValue(undefined);
|
|
134
|
+
await runBuild(build);
|
|
135
|
+
expect(mockedExec).not.toHaveBeenCalledWith('yarn build');
|
|
136
|
+
});
|
|
137
|
+
it('should run yarn and yarn build when no build function is provided', async () => {
|
|
138
|
+
await runBuild();
|
|
139
|
+
expect(mockedExec).toHaveBeenCalledWith('yarn');
|
|
140
|
+
expect(mockedExec).toHaveBeenCalledWith('yarn build');
|
|
141
|
+
});
|
|
142
|
+
it('should propagate errors from the custom build function', async () => {
|
|
143
|
+
const build = vi.fn().mockRejectedValue(new Error('build failed'));
|
|
144
|
+
await expect(runBuild(build)).rejects.toThrow('build failed');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('tryBuild', () => {
|
|
148
|
+
const BASE_ARGS = {
|
|
149
|
+
newVersion: '1.0.1-beta.0',
|
|
150
|
+
isExperimental: false,
|
|
151
|
+
onTempBranch: true,
|
|
152
|
+
tempBranch: 'v1.0.1-beta.0-publish',
|
|
153
|
+
originalBranch: 'master',
|
|
154
|
+
};
|
|
155
|
+
it('should run the build successfully', async () => {
|
|
156
|
+
await tryBuild(BASE_ARGS);
|
|
157
|
+
expect(mockedExec).toHaveBeenCalledWith('yarn build');
|
|
158
|
+
});
|
|
159
|
+
it('should call gitCleanup with tempBranch and originalBranch when build fails and onTempBranch is true', async () => {
|
|
160
|
+
mockedExec.mockImplementation((cmd) => {
|
|
161
|
+
if (cmd === 'yarn build') {
|
|
162
|
+
return Promise.reject(new Error('build failed'));
|
|
163
|
+
}
|
|
164
|
+
return Promise.resolve({ stdout: '', stderr: '' });
|
|
165
|
+
});
|
|
166
|
+
await expect(tryBuild(BASE_ARGS)).rejects.toThrow(ReleaseError);
|
|
167
|
+
expect(mockedGitCleanup).toHaveBeenCalledWith('1.0.1-beta.0', true, 'v1.0.1-beta.0-publish', 'master');
|
|
168
|
+
});
|
|
169
|
+
it('should call gitCleanup without tempBranch when onTempBranch is false and build fails', async () => {
|
|
170
|
+
mockedExec.mockImplementation((cmd) => {
|
|
171
|
+
if (cmd === 'yarn build') {
|
|
172
|
+
return Promise.reject(new Error('build failed'));
|
|
173
|
+
}
|
|
174
|
+
return Promise.resolve({ stdout: '', stderr: '' });
|
|
175
|
+
});
|
|
176
|
+
await expect(tryBuild({ ...BASE_ARGS, onTempBranch: false })).rejects.toThrow(ReleaseError);
|
|
177
|
+
expect(mockedGitCleanup).toHaveBeenCalledWith('1.0.1-beta.0', true, undefined, undefined);
|
|
178
|
+
});
|
|
179
|
+
it('should throw ReleaseError with empty message when build fails', async () => {
|
|
180
|
+
mockedExec.mockImplementation((cmd) => {
|
|
181
|
+
if (cmd === 'yarn build') {
|
|
182
|
+
return Promise.reject(new Error('build failed'));
|
|
183
|
+
}
|
|
184
|
+
return Promise.resolve({ stdout: '', stderr: '' });
|
|
185
|
+
});
|
|
186
|
+
await expect(tryBuild(BASE_ARGS)).rejects.toMatchObject({ message: '' });
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
describe('createTempBranch', () => {
|
|
190
|
+
it('should create a branch when on the main branch and not dry run', async () => {
|
|
191
|
+
await createTempBranch('master', 'master', undefined, false, 'v1.0.1-beta.0-publish');
|
|
192
|
+
expect(mockedExec).toHaveBeenCalledWith('git checkout -b v1.0.1-beta.0-publish');
|
|
193
|
+
});
|
|
194
|
+
it('should create a branch when on the previous branch and not dry run', async () => {
|
|
195
|
+
await createTempBranch('previous-branch', 'master', 'previous-branch', false, 'v0.9.1-publish');
|
|
196
|
+
expect(mockedExec).toHaveBeenCalledWith('git checkout -b v0.9.1-publish');
|
|
197
|
+
});
|
|
198
|
+
it('should not create a branch when on a feature branch', async () => {
|
|
199
|
+
await createTempBranch('feature-branch', 'master', undefined, false, 'v1.0.1-beta.0-publish');
|
|
200
|
+
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git checkout -b'));
|
|
201
|
+
});
|
|
202
|
+
it('should not create a branch during a dry run even on main', async () => {
|
|
203
|
+
await createTempBranch('master', 'master', undefined, true, 'v1.0.1-beta.0-publish');
|
|
204
|
+
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git checkout -b'));
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe('bumpVersion', () => {
|
|
208
|
+
it('should run yarn version with --no-git-tag-version for experimental releases', async () => {
|
|
209
|
+
await bumpVersion('1.0.0-experimental.2', true);
|
|
210
|
+
expect(mockedExec).toHaveBeenCalledWith('yarn version --no-git-tag-version --new-version 1.0.0-experimental.2');
|
|
211
|
+
});
|
|
212
|
+
it('should run yarn version without --no-git-tag-version for non-experimental releases', async () => {
|
|
213
|
+
await bumpVersion('1.0.1-beta.0', false);
|
|
214
|
+
expect(mockedExec).toHaveBeenCalledWith('yarn version --new-version 1.0.1-beta.0');
|
|
215
|
+
});
|
|
216
|
+
it('should log success after bumping', async () => {
|
|
217
|
+
await bumpVersion('1.0.1-beta.0', false);
|
|
218
|
+
expect(logger.success).toHaveBeenCalled();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
describe('ensureNpmAuth', () => {
|
|
222
|
+
it('should return without prompting when isDryRun is true', async () => {
|
|
223
|
+
await ensureNpmAuth(true, REGISTRY);
|
|
224
|
+
expect(mockedExec).not.toHaveBeenCalled();
|
|
225
|
+
});
|
|
226
|
+
it('should check whoami and return when already authenticated', async () => {
|
|
227
|
+
await ensureNpmAuth(false, REGISTRY);
|
|
228
|
+
expect(mockedExec).toHaveBeenCalledWith(`npm whoami --registry ${REGISTRY}`);
|
|
229
|
+
});
|
|
230
|
+
it('should call npm adduser when whoami fails', async () => {
|
|
231
|
+
mockedExec.mockRejectedValue(new Error('not logged in'));
|
|
232
|
+
await ensureNpmAuth(false, REGISTRY);
|
|
233
|
+
expect(mockedExecSync).toHaveBeenCalledWith(`npm adduser --registry ${REGISTRY}`, { stdio: 'inherit' });
|
|
234
|
+
});
|
|
235
|
+
it('should throw ReleaseError with message Failed to authenticate with npm when adduser also fails', async () => {
|
|
236
|
+
mockedExec.mockRejectedValue(new Error('not logged in'));
|
|
237
|
+
mockedExecSync.mockImplementation(() => {
|
|
238
|
+
throw new Error('adduser failed');
|
|
239
|
+
});
|
|
240
|
+
await expect(ensureNpmAuth(false, REGISTRY)).rejects.toThrow('Failed to authenticate with npm');
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe('tryPublish', () => {
|
|
244
|
+
const BASE_ARGS = {
|
|
245
|
+
tag: TAG.NEXT,
|
|
246
|
+
isDryRun: false,
|
|
247
|
+
ignoreScripts: false,
|
|
248
|
+
registry: REGISTRY,
|
|
249
|
+
newVersion: '1.0.1-beta.0',
|
|
250
|
+
isExperimental: false,
|
|
251
|
+
onTempBranch: true,
|
|
252
|
+
tempBranch: 'v1.0.1-beta.0-publish',
|
|
253
|
+
originalBranch: 'master',
|
|
254
|
+
};
|
|
255
|
+
it('should call publish with the correct tag isDryRun ignoreScripts registry args', async () => {
|
|
256
|
+
await tryPublish(BASE_ARGS);
|
|
257
|
+
expect(mockedPublish).toHaveBeenCalledWith(TAG.NEXT, false, false, REGISTRY);
|
|
258
|
+
});
|
|
259
|
+
it('should call gitCleanup with tempBranch and originalBranch when onTempBranch is true and publish fails', async () => {
|
|
260
|
+
mockedPublish.mockRejectedValue(new Error('publish failed'));
|
|
261
|
+
await expect(tryPublish(BASE_ARGS)).rejects.toThrow(ReleaseError);
|
|
262
|
+
expect(mockedGitCleanup).toHaveBeenCalledWith('1.0.1-beta.0', true, 'v1.0.1-beta.0-publish', 'master');
|
|
263
|
+
});
|
|
264
|
+
it('should call gitCleanup with undefined tempBranch and originalBranch when onTempBranch is false and publish fails', async () => {
|
|
265
|
+
mockedPublish.mockRejectedValue(new Error('publish failed'));
|
|
266
|
+
await expect(tryPublish({ ...BASE_ARGS, onTempBranch: false })).rejects.toThrow(ReleaseError);
|
|
267
|
+
expect(mockedGitCleanup).toHaveBeenCalledWith('1.0.1-beta.0', true, undefined, undefined);
|
|
268
|
+
});
|
|
269
|
+
it('should throw ReleaseError with empty message after a publish failure', async () => {
|
|
270
|
+
mockedPublish.mockRejectedValue(new Error('publish failed'));
|
|
271
|
+
await expect(tryPublish(BASE_ARGS)).rejects.toMatchObject({
|
|
272
|
+
message: '',
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
describe('updateDistTagsForLatest', () => {
|
|
277
|
+
const BASE_ARGS = {
|
|
278
|
+
tag: TAG.LATEST,
|
|
279
|
+
versionIncrement: INCREMENT.PATCH,
|
|
280
|
+
packageName: PACKAGE_NAME,
|
|
281
|
+
newVersion: '1.0.1',
|
|
282
|
+
currentLatestTag: '1.0.0',
|
|
283
|
+
isDryRun: false,
|
|
284
|
+
registry: REGISTRY,
|
|
285
|
+
tempBranch: 'v1.0.1-publish',
|
|
286
|
+
};
|
|
287
|
+
it('should do nothing when tag is not latest', async () => {
|
|
288
|
+
await updateDistTagsForLatest({ ...BASE_ARGS, tag: TAG.NEXT });
|
|
289
|
+
expect(mockedUpdateNextTag).not.toHaveBeenCalled();
|
|
290
|
+
});
|
|
291
|
+
it('should call updateNextTag for a latest release', async () => {
|
|
292
|
+
await updateDistTagsForLatest(BASE_ARGS);
|
|
293
|
+
expect(mockedUpdateNextTag).toHaveBeenCalledWith(PACKAGE_NAME, '1.0.1', false, REGISTRY);
|
|
294
|
+
});
|
|
295
|
+
it('should call updatePreviousTag only for a major latest release', async () => {
|
|
296
|
+
await updateDistTagsForLatest({
|
|
297
|
+
...BASE_ARGS,
|
|
298
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
299
|
+
});
|
|
300
|
+
expect(mockedUpdatePreviousTag).toHaveBeenCalledWith(PACKAGE_NAME, '1.0.0', false, REGISTRY);
|
|
301
|
+
});
|
|
302
|
+
it('should not call updatePreviousTag for a non-major latest release', async () => {
|
|
303
|
+
await updateDistTagsForLatest(BASE_ARGS);
|
|
304
|
+
expect(mockedUpdatePreviousTag).not.toHaveBeenCalled();
|
|
305
|
+
});
|
|
306
|
+
it('should log an error and resolve when updateNextTag fails', async () => {
|
|
307
|
+
mockedUpdateNextTag.mockRejectedValue(new Error('dist-tag failed'));
|
|
308
|
+
await expect(updateDistTagsForLatest(BASE_ARGS)).resolves.toBeUndefined();
|
|
309
|
+
expect(logger.error).toHaveBeenCalled();
|
|
310
|
+
});
|
|
311
|
+
it('should log an error and resolve when updatePreviousTag fails', async () => {
|
|
312
|
+
mockedUpdatePreviousTag.mockRejectedValue(new Error('dist-tag failed'));
|
|
313
|
+
await expect(updateDistTagsForLatest({
|
|
314
|
+
...BASE_ARGS,
|
|
315
|
+
versionIncrement: INCREMENT.MAJOR,
|
|
316
|
+
})).resolves.toBeUndefined();
|
|
317
|
+
expect(logger.error).toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
describe('finalizeRelease', () => {
|
|
321
|
+
const BASE_ARGS = {
|
|
322
|
+
isDryRun: false,
|
|
323
|
+
isExperimental: false,
|
|
324
|
+
newVersion: '1.0.1-beta.0',
|
|
325
|
+
localVersion: '1.0.0-beta.1',
|
|
326
|
+
tempBranch: 'v1.0.1-beta.0-publish',
|
|
327
|
+
isPrevious: false,
|
|
328
|
+
previousBranch: 'previous-branch',
|
|
329
|
+
mainBranch: 'master',
|
|
330
|
+
repositoryUrl: 'https://github.com/test/repo',
|
|
331
|
+
};
|
|
332
|
+
it('should call gitCleanup and throw ReleaseError with SUCCESS exit code on dry run', async () => {
|
|
333
|
+
await expect(finalizeRelease({ ...BASE_ARGS, isDryRun: true })).rejects.toMatchObject({ exitCode: EXIT_CODES.SUCCESS });
|
|
334
|
+
expect(mockedGitCleanup).toHaveBeenCalledWith('1.0.1-beta.0', true);
|
|
335
|
+
});
|
|
336
|
+
it('should not push or open a browser on dry run', async () => {
|
|
337
|
+
await expect(finalizeRelease({ ...BASE_ARGS, isDryRun: true })).rejects.toThrow(ReleaseError);
|
|
338
|
+
expect(mockedExec).not.toHaveBeenCalledWith(expect.stringContaining('git push'));
|
|
339
|
+
expect(vi.mocked(open)).not.toHaveBeenCalled();
|
|
340
|
+
});
|
|
341
|
+
it('should reset the package.json version and return on experimental release', async () => {
|
|
342
|
+
await finalizeRelease({ ...BASE_ARGS, isExperimental: true });
|
|
343
|
+
expect(mockedExec).toHaveBeenCalledWith(`yarn version --no-git-tag-version --new-version ${BASE_ARGS.localVersion}`);
|
|
344
|
+
});
|
|
345
|
+
it('should run git push with the correct tempBranch and newVersion on a normal release', async () => {
|
|
346
|
+
await finalizeRelease(BASE_ARGS);
|
|
347
|
+
expect(mockedExec).toHaveBeenCalledWith(`git push --atomic origin ${BASE_ARGS.tempBranch} v${BASE_ARGS.newVersion}`);
|
|
348
|
+
});
|
|
349
|
+
it('should use mainBranch in the compare URL when isPrevious is false', async () => {
|
|
350
|
+
await finalizeRelease(BASE_ARGS);
|
|
351
|
+
expect(vi.mocked(open)).toHaveBeenCalledWith(`https://github.com/test/repo/compare/master...v1.0.1-beta.0-publish`);
|
|
352
|
+
});
|
|
353
|
+
it('should use previousBranch in the compare URL when isPrevious is true', async () => {
|
|
354
|
+
await finalizeRelease({ ...BASE_ARGS, isPrevious: true });
|
|
355
|
+
expect(vi.mocked(open)).toHaveBeenCalledWith(`https://github.com/test/repo/compare/previous-branch...v1.0.1-beta.0-publish`);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
describe('logReleaseSuccess', () => {
|
|
359
|
+
const BASE_ARGS = {
|
|
360
|
+
packageName: PACKAGE_NAME,
|
|
361
|
+
newVersion: '1.0.1-beta.0',
|
|
362
|
+
tag: TAG.NEXT,
|
|
363
|
+
repositoryUrl: 'https://github.com/test/repo',
|
|
364
|
+
isDryRun: false,
|
|
365
|
+
};
|
|
366
|
+
it('should log the package name and npm URL', async () => {
|
|
367
|
+
await logReleaseSuccess(BASE_ARGS);
|
|
368
|
+
expect(logger.success).toHaveBeenCalledWith(`${PACKAGE_NAME} version 1.0.1-beta.0 published successfully`);
|
|
369
|
+
expect(logger.log).toHaveBeenCalledWith(`https://www.npmjs.com/package/${PACKAGE_NAME}?activeTab=versions`);
|
|
370
|
+
});
|
|
371
|
+
it('should not log the GitHub release reminder for next tag', async () => {
|
|
372
|
+
await logReleaseSuccess(BASE_ARGS);
|
|
373
|
+
expect(logger.log).not.toHaveBeenCalledWith(expect.stringContaining('Remember to create a new release on Github'));
|
|
374
|
+
});
|
|
375
|
+
it('should log the GitHub release reminder for latest tag', async () => {
|
|
376
|
+
await logReleaseSuccess({
|
|
377
|
+
...BASE_ARGS,
|
|
378
|
+
tag: TAG.LATEST,
|
|
379
|
+
newVersion: '1.0.1',
|
|
380
|
+
});
|
|
381
|
+
expect(logger.log).toHaveBeenCalledWith(expect.stringContaining('Remember to create a new release on Github'));
|
|
382
|
+
});
|
|
383
|
+
it('should invoke postLatestRelease with newVersion and dryRun for latest tag', async () => {
|
|
384
|
+
const postLatestRelease = vi.fn().mockResolvedValue(undefined);
|
|
385
|
+
await logReleaseSuccess({
|
|
386
|
+
...BASE_ARGS,
|
|
387
|
+
tag: TAG.LATEST,
|
|
388
|
+
newVersion: '1.0.1',
|
|
389
|
+
postLatestRelease,
|
|
390
|
+
});
|
|
391
|
+
expect(postLatestRelease).toHaveBeenCalledWith({
|
|
392
|
+
newVersion: '1.0.1',
|
|
393
|
+
dryRun: false,
|
|
394
|
+
});
|
|
395
|
+
});
|
|
396
|
+
it('should not invoke postLatestRelease for previous tag even if provided', async () => {
|
|
397
|
+
const postLatestRelease = vi.fn().mockResolvedValue(undefined);
|
|
398
|
+
await logReleaseSuccess({
|
|
399
|
+
...BASE_ARGS,
|
|
400
|
+
tag: TAG.PREVIOUS,
|
|
401
|
+
newVersion: '0.9.1',
|
|
402
|
+
postLatestRelease,
|
|
403
|
+
});
|
|
404
|
+
expect(postLatestRelease).not.toHaveBeenCalled();
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|