release-it 19.0.0-next.0 → 19.0.0-next.2

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/test/git.init.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import childProcess from 'node:child_process';
2
+ import test, { beforeEach, describe } from 'node:test';
2
3
  import { mkdirSync } from 'node:fs';
3
- import test from 'ava';
4
+ import assert from 'node:assert/strict';
4
5
  import Shell from '../lib/shell.js';
5
6
  import Git from '../lib/plugin/git/Git.js';
6
7
  import { execOpts, readJSON } from '../lib/util.js';
@@ -8,246 +9,247 @@ import sh from './util/sh.js';
8
9
  import { factory } from './util/index.js';
9
10
  import { mkTmpDir, gitAdd } from './util/helpers.js';
10
11
 
11
- const { git } = readJSON(new URL('../config/release-it.json', import.meta.url));
12
-
13
- test.serial.beforeEach(t => {
14
- const bare = mkTmpDir();
15
- const target = mkTmpDir();
16
- process.chdir(bare);
17
- sh.exec(`git init --bare .`, execOpts);
18
- sh.exec(`git clone ${bare} ${target}`, execOpts);
19
- process.chdir(target);
20
- gitAdd('line', 'file', 'Add file');
21
- t.context = { bare, target };
22
- });
12
+ describe('git.init', () => {
13
+ const { git } = readJSON(new URL('../config/release-it.json', import.meta.url));
14
+
15
+ let bare;
16
+ let target;
17
+ beforeEach(() => {
18
+ bare = mkTmpDir();
19
+ target = mkTmpDir();
20
+ process.chdir(bare);
21
+ sh.exec(`git init --bare .`, execOpts);
22
+ sh.exec(`git clone ${bare} ${target}`, execOpts);
23
+ process.chdir(target);
24
+ gitAdd('line', 'file', 'Add file');
25
+ });
23
26
 
24
- test.serial('should throw if on wrong branch', async t => {
25
- const options = { git: { requireBranch: 'dev' } };
26
- const gitClient = factory(Git, { options });
27
- childProcess.execSync('git remote remove origin', execOpts);
28
- await t.throwsAsync(gitClient.init(), { message: /^Must be on branch dev/ });
29
- });
27
+ test('should throw if on wrong branch', async () => {
28
+ const options = { git: { requireBranch: 'dev' } };
29
+ const gitClient = factory(Git, { options });
30
+ childProcess.execSync('git remote remove origin', execOpts);
31
+ await assert.rejects(gitClient.init(), /Must be on branch dev/);
32
+ });
30
33
 
31
- test.serial('should throw if on negated branch', async t => {
32
- const options = { git: { requireBranch: '!main' } };
33
- const gitClient = factory(Git, { options });
34
- sh.exec('git checkout -b main', execOpts);
35
- await t.throwsAsync(gitClient.init(), { message: /^Must be on branch !main/ });
36
- });
34
+ test('should throw if on negated branch', async () => {
35
+ const options = { git: { requireBranch: '!main' } };
36
+ const gitClient = factory(Git, { options });
37
+ sh.exec('git checkout -b main', execOpts);
38
+ await assert.rejects(gitClient.init(), /Must be on branch !main/);
39
+ });
37
40
 
38
- test.serial('should not throw if required branch matches', async t => {
39
- const options = { git: { requireBranch: 'ma?*' } };
40
- const gitClient = factory(Git, { options });
41
- await t.notThrowsAsync(gitClient.init());
42
- });
41
+ test('should not throw if required branch matches', async () => {
42
+ const options = { git: { requireBranch: 'ma?*' } };
43
+ const gitClient = factory(Git, { options });
44
+ await assert.doesNotReject(gitClient.init());
45
+ });
43
46
 
44
- test.serial('should not throw if one of required branch matches', async t => {
45
- const options = { git: { requireBranch: ['release/*', 'hotfix/*'] } };
46
- const gitClient = factory(Git, { options });
47
- childProcess.execSync('git checkout -b release/v1', execOpts);
48
- await t.notThrowsAsync(gitClient.init());
49
- });
47
+ test('should not throw if one of required branch matches', async () => {
48
+ const options = { git: { requireBranch: ['release/*', 'hotfix/*'] } };
49
+ const gitClient = factory(Git, { options });
50
+ childProcess.execSync('git checkout -b release/v1', execOpts);
51
+ await assert.doesNotReject(gitClient.init());
52
+ });
50
53
 
51
- test.serial('should throw if there is no remote Git url', async t => {
52
- const gitClient = factory(Git, { options: { git } });
53
- childProcess.execSync('git remote remove origin', execOpts);
54
- await t.throwsAsync(gitClient.init(), { message: /^Could not get remote Git url/ });
55
- });
54
+ test('should throw if there is no remote Git url', async () => {
55
+ const gitClient = factory(Git, { options: { git } });
56
+ childProcess.execSync('git remote remove origin', execOpts);
57
+ await assert.rejects(gitClient.init(), /Could not get remote Git url/);
58
+ });
56
59
 
57
- test.serial('should throw if working dir is not clean', async t => {
58
- const gitClient = factory(Git, { options: { git } });
59
- childProcess.execSync('rm file', execOpts);
60
- await t.throwsAsync(gitClient.init(), { message: /^Working dir must be clean/ });
61
- });
60
+ test('should throw if working dir is not clean', async () => {
61
+ const gitClient = factory(Git, { options: { git } });
62
+ childProcess.execSync('rm file', execOpts);
63
+ await assert.rejects(gitClient.init(), /Working dir must be clean/);
64
+ });
62
65
 
63
- test.serial('should throw if no upstream is configured', async t => {
64
- const gitClient = factory(Git, { options: { git } });
65
- childProcess.execSync('git checkout -b foo', execOpts);
66
- await t.throwsAsync(gitClient.init(), { message: /^No upstream configured for current branch/ });
67
- });
66
+ test('should throw if no upstream is configured', async () => {
67
+ const gitClient = factory(Git, { options: { git } });
68
+ childProcess.execSync('git checkout -b foo', execOpts);
69
+ await assert.rejects(gitClient.init(), /No upstream configured for current branch/);
70
+ });
68
71
 
69
- test.serial('should throw if there are no commits', async t => {
70
- const options = { git: { requireCommits: true } };
71
- const gitClient = factory(Git, { options });
72
- childProcess.execSync('git tag 1.0.0', execOpts);
73
- await t.throwsAsync(gitClient.init(), { message: /^There are no commits since the latest tag/ });
74
- });
72
+ test('should throw if there are no commits', async () => {
73
+ const options = { git: { requireCommits: true } };
74
+ const gitClient = factory(Git, { options });
75
+ childProcess.execSync('git tag 1.0.0', execOpts);
76
+ await assert.rejects(gitClient.init(), /There are no commits since the latest tag/);
77
+ });
75
78
 
76
- test.serial('should not throw if there are commits', async t => {
77
- const options = { git: { requireCommits: true } };
78
- const gitClient = factory(Git, { options });
79
- childProcess.execSync('git tag 1.0.0', execOpts);
80
- gitAdd('line', 'file', 'Add file');
81
- await t.notThrowsAsync(gitClient.init(), 'There are no commits since the latest tag');
82
- });
79
+ test('should not throw if there are commits', async () => {
80
+ const options = { git: { requireCommits: true } };
81
+ const gitClient = factory(Git, { options });
82
+ childProcess.execSync('git tag 1.0.0', execOpts);
83
+ gitAdd('line', 'file', 'Add file');
84
+ await assert.doesNotReject(gitClient.init(), 'There are no commits since the latest tag');
85
+ });
83
86
 
84
- test.serial('should fail (exit code 1) if there are no commits', async t => {
85
- const options = { git: { requireCommits: true } };
86
- const gitClient = factory(Git, { options });
87
- childProcess.execSync('git tag 1.0.0', execOpts);
88
- await t.throwsAsync(gitClient.init(), { code: 1 });
89
- });
87
+ test('should fail (exit code 1) if there are no commits', async () => {
88
+ const options = { git: { requireCommits: true } };
89
+ const gitClient = factory(Git, { options });
90
+ childProcess.execSync('git tag 1.0.0', execOpts);
91
+ await assert.rejects(gitClient.init(), { code: 1 });
92
+ });
90
93
 
91
- test.serial('should not fail (exit code 0) if there are no commits', async t => {
92
- const options = { git: { requireCommits: true, requireCommitsFail: false } };
93
- const gitClient = factory(Git, { options });
94
- childProcess.execSync('git tag 1.0.0', execOpts);
95
- await t.throwsAsync(gitClient.init(), { code: 0 });
96
- });
94
+ test('should not fail (exit code 0) if there are no commits', async () => {
95
+ const options = { git: { requireCommits: true, requireCommitsFail: false } };
96
+ const gitClient = factory(Git, { options });
97
+ childProcess.execSync('git tag 1.0.0', execOpts);
98
+ await assert.rejects(gitClient.init(), { code: 0 });
99
+ });
97
100
 
98
- test.serial('should throw if there are no commits in specified path', async t => {
99
- const options = { git: { requireCommits: true, commitsPath: 'dir' } };
100
- const gitClient = factory(Git, { options });
101
- mkdirSync('dir', { recursive: true });
102
- sh.exec('git tag 1.0.0', execOpts);
103
- await t.throwsAsync(gitClient.init(), { message: /^There are no commits since the latest tag/ });
104
- });
101
+ test('should throw if there are no commits in specified path', async () => {
102
+ const options = { git: { requireCommits: true, commitsPath: 'dir' } };
103
+ const gitClient = factory(Git, { options });
104
+ mkdirSync('dir', { recursive: true });
105
+ sh.exec('git tag 1.0.0', execOpts);
106
+ await assert.rejects(gitClient.init(), { message: /^There are no commits since the latest tag/ });
107
+ });
105
108
 
106
- test.serial('should not throw if there are commits in specified path', async t => {
107
- const options = { git: { requireCommits: true, commitsPath: 'dir' } };
108
- const gitClient = factory(Git, { options });
109
- sh.exec('git tag 1.0.0', execOpts);
110
- gitAdd('line', 'dir/file', 'Add file');
111
- await t.notThrowsAsync(gitClient.init());
112
- });
109
+ test('should not throw if there are commits in specified path', async () => {
110
+ const options = { git: { requireCommits: true, commitsPath: 'dir' } };
111
+ const gitClient = factory(Git, { options });
112
+ sh.exec('git tag 1.0.0', execOpts);
113
+ gitAdd('line', 'dir/file', 'Add file');
114
+ await assert.doesNotReject(gitClient.init());
115
+ });
113
116
 
114
- test.serial('should not throw if there are no tags', async t => {
115
- const options = { git: { requireCommits: true } };
116
- const gitClient = factory(Git, { options });
117
- gitAdd('line', 'file', 'Add file');
118
- await t.notThrowsAsync(gitClient.init());
119
- });
117
+ test('should not throw if there are no tags', async () => {
118
+ const options = { git: { requireCommits: true } };
119
+ const gitClient = factory(Git, { options });
120
+ gitAdd('line', 'file', 'Add file');
121
+ await assert.doesNotReject(gitClient.init());
122
+ });
120
123
 
121
- test.serial('should not throw if origin remote is renamed', async t => {
122
- childProcess.execSync('git remote rename origin upstream', execOpts);
123
- const gitClient = factory(Git);
124
- await t.notThrowsAsync(gitClient.init());
125
- });
124
+ test('should not throw if origin remote is renamed', async () => {
125
+ childProcess.execSync('git remote rename origin upstream', execOpts);
126
+ const gitClient = factory(Git);
127
+ await assert.doesNotReject(gitClient.init());
128
+ });
126
129
 
127
- test.serial('should detect and include version prefix ("v")', async t => {
128
- const gitClient = factory(Git, { options: { git } });
129
- childProcess.execSync('git tag v1.0.0', execOpts);
130
- await gitClient.init();
131
- await gitClient.bump('1.0.1');
132
- t.is(gitClient.config.getContext('tagName'), 'v1.0.1');
133
- });
130
+ test('should detect and include version prefix ("v")', async () => {
131
+ const gitClient = factory(Git, { options: { git } });
132
+ childProcess.execSync('git tag v1.0.0', execOpts);
133
+ await gitClient.init();
134
+ await gitClient.bump('1.0.1');
135
+ assert.equal(gitClient.config.getContext('tagName'), 'v1.0.1');
136
+ });
134
137
 
135
- test.serial('should detect and exclude version prefix', async t => {
136
- const gitClient = factory(Git, { options: { git } });
137
- childProcess.execSync('git tag 1.0.0', execOpts);
138
- await gitClient.init();
139
- await gitClient.bump('1.0.1');
140
- t.is(gitClient.config.getContext('tagName'), '1.0.1');
141
- });
138
+ test('should detect and exclude version prefix', async () => {
139
+ const gitClient = factory(Git, { options: { git } });
140
+ childProcess.execSync('git tag 1.0.0', execOpts);
141
+ await gitClient.init();
142
+ await gitClient.bump('1.0.1');
143
+ assert.equal(gitClient.config.getContext('tagName'), '1.0.1');
144
+ });
142
145
 
143
- test.serial('should detect and exclude version prefix (configured)', async t => {
144
- const gitClient = factory(Git, { options: { git: { tagName: 'v${version}' } } });
145
- childProcess.execSync('git tag 1.0.0', execOpts);
146
- await gitClient.init();
147
- await gitClient.bump('1.0.1');
148
- t.is(gitClient.config.getContext('tagName'), 'v1.0.1');
149
- });
146
+ test('should detect and exclude version prefix (configured)', async () => {
147
+ const gitClient = factory(Git, { options: { git: { tagName: 'v${version}' } } });
148
+ childProcess.execSync('git tag 1.0.0', execOpts);
149
+ await gitClient.init();
150
+ await gitClient.bump('1.0.1');
151
+ assert.equal(gitClient.config.getContext('tagName'), 'v1.0.1');
152
+ });
150
153
 
151
- test.serial('should honor custom tagName configuration', async t => {
152
- const gitClient = factory(Git, { options: { git: { tagName: 'TAGNAME-${repo.project}-v${version}' } } });
153
- childProcess.execSync('git tag 1.0.0', execOpts);
154
- await gitClient.init();
155
- await gitClient.bump('1.0.1');
156
- const { project } = gitClient.getContext('repo');
157
- t.is(gitClient.config.getContext('tagName'), `TAGNAME-${project}-v1.0.1`);
158
- });
154
+ test('should honor custom tagName configuration', async () => {
155
+ const gitClient = factory(Git, { options: { git: { tagName: 'TAGNAME-${repo.project}-v${version}' } } });
156
+ childProcess.execSync('git tag 1.0.0', execOpts);
157
+ await gitClient.init();
158
+ await gitClient.bump('1.0.1');
159
+ const { project } = gitClient.getContext('repo');
160
+ assert.equal(gitClient.config.getContext('tagName'), `TAGNAME-${project}-v1.0.1`);
161
+ });
159
162
 
160
- test.serial('should get the latest tag after fetch', async t => {
161
- const shell = factory(Shell);
162
- const gitClient = factory(Git, { container: { shell } });
163
- const { bare, target } = t.context;
164
- const other = mkTmpDir();
165
- childProcess.execSync('git push', execOpts);
166
- childProcess.execSync(`git clone ${bare} ${other}`, execOpts);
167
-
168
- process.chdir(other);
169
- childProcess.execSync('git tag 1.0.0', execOpts);
170
- childProcess.execSync('git push --tags', execOpts);
171
- process.chdir(target);
172
- await gitClient.init();
173
- t.is(gitClient.config.getContext('latestTag'), '1.0.0');
174
- });
163
+ test('should get the latest tag after fetch', async () => {
164
+ const shell = factory(Shell);
165
+ const gitClient = factory(Git, { container: { shell } });
166
+ const other = mkTmpDir();
167
+ childProcess.execSync('git push', execOpts);
168
+ childProcess.execSync(`git clone ${bare} ${other}`, execOpts);
169
+
170
+ process.chdir(other);
171
+ childProcess.execSync('git tag 1.0.0', execOpts);
172
+ childProcess.execSync('git push --tags', execOpts);
173
+ process.chdir(target);
174
+ await gitClient.init();
175
+ assert.equal(gitClient.config.getContext('latestTag'), '1.0.0');
176
+ });
175
177
 
176
- test.serial('should get the latest custom tag after fetch when tagName is configured', async t => {
177
- const shell = factory(Shell);
178
- const gitClient = factory(Git, {
179
- options: { git: { tagName: 'TAGNAME-v${version}' } },
180
- container: { shell }
181
- });
182
- const { bare, target } = t.context;
183
- const other = mkTmpDir();
184
- childProcess.execSync('git push', execOpts);
185
- childProcess.execSync(`git clone ${bare} ${other}`, execOpts);
186
- process.chdir(other);
187
- childProcess.execSync('git tag TAGNAME-OTHER-v2.0.0', execOpts);
188
- childProcess.execSync('git tag TAGNAME-v1.0.0', execOpts);
189
- childProcess.execSync('git tag TAGNAME-OTHER-v2.0.2', execOpts);
190
- childProcess.execSync('git push --tags', execOpts);
191
- process.chdir(target);
192
- await gitClient.init();
193
- t.is(gitClient.config.getContext('latestTag'), 'TAGNAME-v1.0.0');
194
- });
178
+ test('should get the latest custom tag after fetch when tagName is configured', async () => {
179
+ const shell = factory(Shell);
180
+ const gitClient = factory(Git, {
181
+ options: { git: { tagName: 'TAGNAME-v${version}' } },
182
+ container: { shell }
183
+ });
184
+ const other = mkTmpDir();
185
+ childProcess.execSync('git push', execOpts);
186
+ childProcess.execSync(`git clone ${bare} ${other}`, execOpts);
187
+ process.chdir(other);
188
+ childProcess.execSync('git tag TAGNAME-OTHER-v2.0.0', execOpts);
189
+ childProcess.execSync('git tag TAGNAME-v1.0.0', execOpts);
190
+ childProcess.execSync('git tag TAGNAME-OTHER-v2.0.2', execOpts);
191
+ childProcess.execSync('git push --tags', execOpts);
192
+ process.chdir(target);
193
+ await gitClient.init();
194
+ assert.equal(gitClient.config.getContext('latestTag'), 'TAGNAME-v1.0.0');
195
+ });
195
196
 
196
- test.serial('should get the latest tag based on tagMatch', async t => {
197
- const shell = factory(Shell);
198
- const gitClient = factory(Git, {
199
- options: { git: { tagMatch: '[0-9][0-9]\\.[0-1][0-9]\\.[0-9]*' } },
200
- container: { shell }
201
- });
202
- childProcess.execSync('git tag 1.0.0', execOpts);
203
- childProcess.execSync('git tag 21.04.3', execOpts);
204
- childProcess.execSync('git tag 1.0.1', execOpts);
205
- childProcess.execSync('git push --tags', execOpts);
206
- await gitClient.init();
207
- t.is(gitClient.config.getContext('latestTag'), '21.04.3');
208
- });
197
+ test('should get the latest tag based on tagMatch', async () => {
198
+ const shell = factory(Shell);
199
+ const gitClient = factory(Git, {
200
+ options: { git: { tagMatch: '[0-9][0-9]\\.[0-1][0-9]\\.[0-9]*' } },
201
+ container: { shell }
202
+ });
203
+ childProcess.execSync('git tag 1.0.0', execOpts);
204
+ childProcess.execSync('git tag 21.04.3', execOpts);
205
+ childProcess.execSync('git tag 1.0.1', execOpts);
206
+ childProcess.execSync('git push --tags', execOpts);
207
+ await gitClient.init();
208
+ assert.equal(gitClient.config.getContext('latestTag'), '21.04.3');
209
+ });
209
210
 
210
- test.serial('should get the latest tag based on tagExclude', async t => {
211
- const shell = factory(Shell);
212
- const gitClient = factory(Git, {
213
- options: { git: { tagExclude: '*[-]*' } },
214
- container: { shell }
215
- });
216
- childProcess.execSync('git tag 1.0.0', execOpts);
217
- childProcess.execSync('git commit --allow-empty -m "commit 1"', execOpts);
218
- childProcess.execSync('git tag 1.0.1-rc.0', execOpts);
219
- childProcess.execSync('git tag 1.0.1', execOpts);
220
- childProcess.execSync('git commit --allow-empty -m "commit 2"', execOpts);
221
- childProcess.execSync('git tag 1.1.0-rc.0', execOpts);
222
- childProcess.execSync('git push --tags', execOpts);
223
- await gitClient.init();
224
- t.is(gitClient.config.getContext('latestTag'), '1.0.1');
225
- });
211
+ test('should get the latest tag based on tagExclude', async () => {
212
+ const shell = factory(Shell);
213
+ const gitClient = factory(Git, {
214
+ options: { git: { tagExclude: '*[-]*' } },
215
+ container: { shell }
216
+ });
217
+ childProcess.execSync('git tag 1.0.0', execOpts);
218
+ childProcess.execSync('git commit --allow-empty -m "commit 1"', execOpts);
219
+ childProcess.execSync('git tag 1.0.1-rc.0', execOpts);
220
+ childProcess.execSync('git tag 1.0.1', execOpts);
221
+ childProcess.execSync('git commit --allow-empty -m "commit 2"', execOpts);
222
+ childProcess.execSync('git tag 1.1.0-rc.0', execOpts);
223
+ childProcess.execSync('git push --tags', execOpts);
224
+ await gitClient.init();
225
+ assert.equal(gitClient.config.getContext('latestTag'), '1.0.1');
226
+ });
226
227
 
227
- test.serial('should generate correct changelog', async t => {
228
- const gitClient = factory(Git, { options: { git } });
229
- childProcess.execSync('git tag 1.0.0', execOpts);
230
- gitAdd('line', 'file', 'Add file');
231
- gitAdd('line', 'file', 'Add file');
232
- await gitClient.init();
233
- const changelog = await gitClient.getChangelog();
234
- t.regex(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
235
- });
228
+ test('should generate correct changelog', async () => {
229
+ const gitClient = factory(Git, { options: { git } });
230
+ childProcess.execSync('git tag 1.0.0', execOpts);
231
+ gitAdd('line', 'file', 'Add file');
232
+ gitAdd('line', 'file', 'Add file');
233
+ await gitClient.init();
234
+ const changelog = await gitClient.getChangelog();
235
+ assert.match(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
236
+ });
236
237
 
237
- test.serial('should get the full changelog since latest major tag', async t => {
238
- const shell = factory(Shell);
239
- const gitClient = factory(Git, {
240
- options: { git: { tagMatch: '[0-9]\\.[0-9]\\.[0-9]', changelog: git.changelog } },
241
- container: { shell }
242
- });
243
- childProcess.execSync('git tag 1.0.0', execOpts);
244
- gitAdd('line', 'file', 'Add file');
245
- childProcess.execSync('git tag 2.0.0-rc.0', execOpts);
246
- gitAdd('line', 'file', 'Add file');
247
- childProcess.execSync('git tag 2.0.0-rc.1', execOpts);
248
- gitAdd('line', 'file', 'Add file');
249
- await gitClient.init();
250
- t.is(gitClient.config.getContext('latestTag'), '1.0.0');
251
- const changelog = await gitClient.getChangelog();
252
- t.regex(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
238
+ test('should get the full changelog since latest major tag', async () => {
239
+ const shell = factory(Shell);
240
+ const gitClient = factory(Git, {
241
+ options: { git: { tagMatch: '[0-9]\\.[0-9]\\.[0-9]', changelog: git.changelog } },
242
+ container: { shell }
243
+ });
244
+ childProcess.execSync('git tag 1.0.0', execOpts);
245
+ gitAdd('line', 'file', 'Add file');
246
+ childProcess.execSync('git tag 2.0.0-rc.0', execOpts);
247
+ gitAdd('line', 'file', 'Add file');
248
+ childProcess.execSync('git tag 2.0.0-rc.1', execOpts);
249
+ gitAdd('line', 'file', 'Add file');
250
+ await gitClient.init();
251
+ assert.equal(gitClient.config.getContext('latestTag'), '1.0.0');
252
+ const changelog = await gitClient.getChangelog();
253
+ assert.match(changelog, /\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)\n\* Add file \(\w{7}\)/);
254
+ });
253
255
  });