Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
253 lines (225 loc) · 15 KB
/
Copy pathtest.js
File metadata and controls
253 lines (225 loc) · 15 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
245
246
247
248
249
250
251
252
253
// NOTE: to run this you will probably need to be authorized with GitHub.
// Run `./changelog-maker.js` by itself to set this up.
import { dirname, join } from 'path'
import { execSync } from 'child_process'
import assert from 'node:assert/strict'
import { test } from 'node:test'
import { styleText } from 'node:util'
import { commitToOutput, formatType } from './commit-to-output.js'
import { forEachConcurrent } from './for-each-concurrent.js'
import { isReleaseCommit } from './groups.js'
const __dirname = dirname(new URL(import.meta.url).pathname)
function exec (args) {
const stdout = execSync(`"${process.execPath}" ${join(__dirname, 'changelog-maker.js')} ${args}`).toString()
return stdout
}
test('test basic commit block', () => {
assert.equal(exec('--format=markdown --start-ref=v1.3.9 --end-ref=v1.3.10'),
`* \\[[\`e28b3f2813\`](https://github.com/nodejs/changelog-maker/commit/e28b3f2813)] - 1.3.10 (Rod Vagg)
* \\[[\`ace3af943e\`](https://github.com/nodejs/changelog-maker/commit/ace3af943e)] - Merge pull request #13 from jamsyoung/private-repo-support (Rod Vagg)
* \\[[\`25ec5428bc\`](https://github.com/nodejs/changelog-maker/commit/25ec5428bc)] - default to repo scope always - revert previous changes (James Young)
* \\[[\`424d6c22c1\`](https://github.com/nodejs/changelog-maker/commit/424d6c22c1)] - add --private arg to set repo scope, update readme (James Young)
* \\[[\`7c8c5e6215\`](https://github.com/nodejs/changelog-maker/commit/7c8c5e6215)] - 1.3.9 (Rod Vagg)
`)
})
test('test filter-release', () => {
assert.equal(exec('--format=markdown --start-ref=v1.3.9 --end-ref=v1.3.10 --filter-release'),
`* \\[[\`ace3af943e\`](https://github.com/nodejs/changelog-maker/commit/ace3af943e)] - Merge pull request #13 from jamsyoung/private-repo-support (Rod Vagg)
* \\[[\`25ec5428bc\`](https://github.com/nodejs/changelog-maker/commit/25ec5428bc)] - default to repo scope always - revert previous changes (James Young)
* \\[[\`424d6c22c1\`](https://github.com/nodejs/changelog-maker/commit/424d6c22c1)] - add --private arg to set repo scope, update readme (James Young)
`)
})
test('test simple', () => {
assert.equal(exec('--start-ref=v1.3.9 --end-ref=v1.3.10'),
`* [e28b3f2813] - 1.3.10 (Rod Vagg)
* [ace3af943e] - Merge pull request #13 from jamsyoung/private-repo-support (Rod Vagg)
* [25ec5428bc] - default to repo scope always - revert previous changes (James Young)
* [424d6c22c1] - add --private arg to set repo scope, update readme (James Young)
* [7c8c5e6215] - 1.3.9 (Rod Vagg)
`)
})
test('test sequence', () => {
assert.equal(exec('--start-ref=v2.2.7 --end-ref=9c700d29 --filter-release --format=sequence --reverse'),
`pick 50945246557b4a25133435b106d0e5dd5d88a9be # feature: make the commit url configurable via an additional argument (Jim Nielsen) https://github.com/nodejs/changelog-maker/pull/55
pick cc442b65343cd1bb7cb4ecc3c6e729b4e4625f97 # (SEMVER-MINOR) minor nit (Rod Vagg) https://github.com/nodejs/node/pull/23715 (semver-minor, build, i18n-api)
pick 6898501e18f231db40a84b511d2a6a4b8f5f17f3 # deps: update deps, introduce test & lint deps (Rod Vagg)
pick 42f248cf8904224a585e9f3834cc1283713c56cf # src: use \`standard\` for linting (Rod Vagg)
pick 4f2b7f8136358bc3ecd720e33457fdeff9581733 # deps: use strip-ansi instead of chalk.stripColor (Rod Vagg)
pick 64a8fdef3c35627ca50c48e9acb80c57a3f6d2a2 # test: basic test infrastructure (Rod Vagg)
pick 9c700d29104b5a22fcf79ba21f5f009d7f1cdfc5 # feature: refactor and improve --commit-url (Rod Vagg)
`)
})
test('test sequence-drop', () => {
assert.equal(exec('--start-ref=v2.2.7 --end-ref=9c700d29 --filter-release --format=sequence --reverse --sequence-drop=semver-minor'),
`pick 50945246557b4a25133435b106d0e5dd5d88a9be # feature: make the commit url configurable via an additional argument (Jim Nielsen) https://github.com/nodejs/changelog-maker/pull/55
drop cc442b65343cd1bb7cb4ecc3c6e729b4e4625f97 # (SEMVER-MINOR) minor nit (Rod Vagg) https://github.com/nodejs/node/pull/23715 (semver-minor, build, i18n-api)
pick 6898501e18f231db40a84b511d2a6a4b8f5f17f3 # deps: update deps, introduce test & lint deps (Rod Vagg)
pick 42f248cf8904224a585e9f3834cc1283713c56cf # src: use \`standard\` for linting (Rod Vagg)
pick 4f2b7f8136358bc3ecd720e33457fdeff9581733 # deps: use strip-ansi instead of chalk.stripColor (Rod Vagg)
pick 64a8fdef3c35627ca50c48e9acb80c57a3f6d2a2 # test: basic test infrastructure (Rod Vagg)
pick 9c700d29104b5a22fcf79ba21f5f009d7f1cdfc5 # feature: refactor and improve --commit-url (Rod Vagg)
`)
})
test('test plaintext', () => {
assert.equal(exec('--start-ref=9c700d2 --end-ref=dd937e9 --group --filter-release --format=plaintext'),
`feature:
* refactor and improve --commit-url (Rod Vagg)
test:
* update refs for testing (Rod Vagg)
`)
})
test('test messageonly', () => {
assert.equal(exec('--start-ref=9c700d2 --end-ref=dd937e9 --group --filter-release --format=messageonly'),
`feature:
* refactor and improve --commit-url
test:
* update refs for testing
`)
})
test('test group, semver labels, PR-URL', () => {
assert.equal(exec('--start-ref=v2.2.7 --end-ref=9c700d29 --group --filter-release'),
`${styleText(['green', 'bold'], '* [cc442b6534] - (SEMVER-MINOR) minor nit (Rod Vagg) https://github.com/nodejs/node/pull/23715')}
* [4f2b7f8136] - deps: use strip-ansi instead of chalk.stripColor (Rod Vagg)
* [6898501e18] - deps: update deps, introduce test & lint deps (Rod Vagg)
* [9c700d2910] - feature: refactor and improve --commit-url (Rod Vagg)
* [5094524655] - feature: make the commit url configurable via an additional argument (Jim Nielsen) https://github.com/nodejs/changelog-maker/pull/55
* [42f248cf89] - src: use \`standard\` for linting (Rod Vagg)
* [64a8fdef3c] - test: basic test infrastructure (Rod Vagg)
`)
})
test('test simple group, semver labels, PR-URL', () => {
assert.equal(exec('--format=markdown --start-ref=v2.2.7 --end-ref=9c700d29 --group --filter-release'),
`* \\[[\`cc442b6534\`](https://github.com/nodejs/changelog-maker/commit/cc442b6534)] - **(SEMVER-MINOR)** minor nit (Rod Vagg) [nodejs/node#23715](https://github.com/nodejs/node/pull/23715)
* \\[[\`4f2b7f8136\`](https://github.com/nodejs/changelog-maker/commit/4f2b7f8136)] - **deps**: use strip-ansi instead of chalk.stripColor (Rod Vagg)
* \\[[\`6898501e18\`](https://github.com/nodejs/changelog-maker/commit/6898501e18)] - **deps**: update deps, introduce test & lint deps (Rod Vagg)
* \\[[\`9c700d2910\`](https://github.com/nodejs/changelog-maker/commit/9c700d2910)] - **feature**: refactor and improve --commit-url (Rod Vagg)
* \\[[\`5094524655\`](https://github.com/nodejs/changelog-maker/commit/5094524655)] - **feature**: make the commit url configurable via an additional argument (Jim Nielsen) [#55](https://github.com/nodejs/changelog-maker/pull/55)
* \\[[\`42f248cf89\`](https://github.com/nodejs/changelog-maker/commit/42f248cf89)] - **src**: use \`standard\` for linting (Rod Vagg)
* \\[[\`64a8fdef3c\`](https://github.com/nodejs/changelog-maker/commit/64a8fdef3c)] - **test**: basic test infrastructure (Rod Vagg)
`)
})
test('test blank commit-url', () => {
let actual = exec('--format=markdown --start-ref=v2.2.7 --end-ref=9c700d29 --filter-release --commit-url=http://foo.bar/').split('\n')
actual.splice(0, actual.length - 3)
actual = actual.join('\n')
assert.equal(actual,
`* \\[[\`cc442b6534\`](http://foo.bar/)] - **(SEMVER-MINOR)** minor nit (Rod Vagg) [nodejs/node#23715](https://github.com/nodejs/node/pull/23715)
* \\[[\`5094524655\`](http://foo.bar/)] - **feature**: make the commit url configurable via an additional argument (Jim Nielsen) [#55](https://github.com/nodejs/changelog-maker/pull/55)
`)
})
test('test blank commit-url', () => {
let actual = exec('--format=markdown --start-ref=v2.2.7 --end-ref=9c700d29 --filter-release --commit-url=https://yeehaw.com/{ref}/{ref}/{ghUser}/{ghRepo}/').split('\n')
actual.splice(0, actual.length - 3)
actual = actual.join('\n')
assert.equal(actual,
`* \\[[\`cc442b6534\`](https://yeehaw.com/cc442b6534/cc442b6534/nodejs/changelog-maker/)] - **(SEMVER-MINOR)** minor nit (Rod Vagg) [nodejs/node#23715](https://github.com/nodejs/node/pull/23715)
* \\[[\`5094524655\`](https://yeehaw.com/5094524655/5094524655/nodejs/changelog-maker/)] - **feature**: make the commit url configurable via an additional argument (Jim Nielsen) [#55](https://github.com/nodejs/changelog-maker/pull/55)
`)
})
test('test backtick strings in commit messages', () => {
assert.equal(
exec('--format=markdown --start-ref=ce886b5130 --end-ref=0717fdc946 --filter-release --commit-url=https://yeehaw.com/{ref}/{ref}/{ghUser}/{ghRepo}/'),
`* \\[[\`0717fdc946\`](https://yeehaw.com/0717fdc946/0717fdc946/nodejs/changelog-maker/)] - **test**: \\\`commit\\_msg\\\` with an unescaped \\\` backtick char (Antoine du Hamel)
* \\[[\`9f1d897c88\`](https://yeehaw.com/9f1d897c88/9f1d897c88/nodejs/changelog-maker/)] - **test**: \\\`commit\\_msg\\\` with an escaped \\\\\\\` backtick char (Antoine du Hamel)
* \\[[\`4a3154bde0\`](https://yeehaw.com/4a3154bde0/4a3154bde0/nodejs/changelog-maker/)] - **test**: \`commit_msg\` starting with a backtick string (Antoine du Hamel)
* \\[[\`46384bb241\`](https://yeehaw.com/46384bb241/46384bb241/nodejs/changelog-maker/)] - **test**: commit\\_msg with \\\`backtick\\\\\\\` string (Antoine du Hamel)
* \\[[\`3b13c6804d\`](https://yeehaw.com/3b13c6804d/3b13c6804d/nodejs/changelog-maker/)] - **test**: commit\\_msg with \\\`\\\`backtick \\\` string\\\`\\\` (Antoine du Hamel)
* \\[[\`699ce8c377\`](https://yeehaw.com/699ce8c377/699ce8c377/nodejs/changelog-maker/)] - **test**: commit\\_msg with \`back_tick\` string (Antoine du Hamel)
* \\[[\`ce886b5130\`](https://yeehaw.com/ce886b5130/ce886b5130/nodejs/changelog-maker/)] - **test**: commit\\_msg with \`backtick\` string (Antoine du Hamel)
`)
})
test('test markdown punctuation chars in commit message and author name', () => {
assert.equal(
exec('--format=markdown --start-ref=f12fe589c4 --end-ref=f12fe589c4 --filter-release --commit-url=https://yeehaw.com/{ref}/{ref}/{ghUser}/{ghRepo}/'),
`* \\[[\`f12fe589c4\`](https://yeehaw.com/f12fe589c4/f12fe589c4/nodejs/changelog-maker/)] - **group\\_with\\_underscore**: test commit message (Author\\_name\\_with\\_underscore)
`)
})
test('test find-matching-prs', () => {
assert.equal(
exec('--start-ref=a059bc7ca9 --end-ref=a059bc7ca9 --find-matching-prs nodejs changelog-maker'),
`* [a059bc7ca9] - chore(deps): remove package-lock.json (Rod Vagg) https://github.com/nodejs/changelog-maker/pull/118
`)
})
test('test group, CVE-ID', () => {
const out = exec('--format=markdown --start-ref=43d428b3d2 --end-ref=43d428b3d2 --group --filter-release')
assert.equal(
out,
`* \\[[\`43d428b3d2\`](https://github.com/nodejs/changelog-maker/commit/43d428b3d2)] - **(CVE-2024-22020)** **feat**: add cveId support to commmit output (RafaelGSS) [nodejs/node#55819](https://github.com/nodejs/node/pull/55819)
`)
})
test('test conventionalcommit style', () => {
// testing that we capture `foo(bar)` as a group in `foo(bar): message`, not just `foo` in `foo: message`
const out = exec('--format=markdown --start-ref=35b762c7 --end-ref=375e0b7d')
assert.equal(
out,
`* \\[[\`375e0b7d48\`](https://github.com/nodejs/changelog-maker/commit/375e0b7d48)] - **test(cc,yay)**: add test case for conventional commits (Rod Vagg)
* \\[[\`6d6ef98c14\`](https://github.com/nodejs/changelog-maker/commit/6d6ef98c14)] - **feat(conventionalcommits)**: make group matching regexp cover CC style (Rod Vagg)
* \\[[\`b3c44809b7\`](https://github.com/nodejs/changelog-maker/commit/b3c44809b7)] - **chore(release)**: 4.2.1 \\[skip ci] (semantic-release-bot)
* \\[[\`fce438030c\`](https://github.com/nodejs/changelog-maker/commit/fce438030c)] - **chore(deps-dev)**: bump tap from 18.8.0 to 19.0.0 (dependabot\\[bot]) [#165](https://github.com/nodejs/changelog-maker/pull/165)
* \\[[\`ddb59f6a17\`](https://github.com/nodejs/changelog-maker/commit/ddb59f6a17)] - **chore(release)**: 4.2.0 \\[skip ci] (semantic-release-bot)
* \\[[\`f8391430af\`](https://github.com/nodejs/changelog-maker/commit/f8391430af)] - Merge pull request #167 from nodejs/add-cve-id-to-commitoutput (Rafael Gonzaga)
* \\[[\`f2f235bb05\`](https://github.com/nodejs/changelog-maker/commit/f2f235bb05)] - **test**: add cveId tests (RafaelGSS)
* \\[[\`43d428b3d2\`](https://github.com/nodejs/changelog-maker/commit/43d428b3d2)] - **(CVE-2024-22020)** **feat**: add cveId support to commmit output (RafaelGSS) [nodejs/node#55819](https://github.com/nodejs/node/pull/55819)
* \\[[\`35b762c78a\`](https://github.com/nodejs/changelog-maker/commit/35b762c78a)] - **chore(release)**: 4.1.1 \\[skip ci] (semantic-release-bot)
`)
})
test('test plaintext, CVE-ID', () => {
const out = exec('--start-ref=43d428b3d2 --end-ref=43d428b3d2 --group --filter-release --format=plaintext')
assert.equal(
out,
`feat:
* (CVE-2024-22020) add cveId support to commmit output (RafaelGSS) https://github.com/nodejs/node/pull/55819
`)
})
test('test forEachConcurrent starts items in order and limits concurrency', async () => {
const items = Array.from({ length: 20 }, (_, i) => i)
const started = []
let active = 0
let maxActive = 0
await forEachConcurrent(items, 3, async (item) => {
started.push(item)
maxActive = Math.max(maxActive, ++active)
await new Promise(setImmediate)
active--
})
assert.deepEqual(started, items)
assert.equal(maxActive, 3)
})
test('test isReleaseCommit, Alpha', () => {
assert.equal(isReleaseCommit('2026-10-20, Version 27.0.0-alpha.0.0.0 (Alpha)'), true)
assert.equal(isReleaseCommit('2026-11-03, Version 27.0.0-alpha.1.2.3 (Alpha)'), true)
assert.equal(isReleaseCommit('Working on v27.0.0-alpha.0.0.1'), true)
assert.equal(isReleaseCommit('Working on 27.0.0-alpha.1.2.3'), true)
})
test('test isReleaseCommit, non-release commits', () => {
assert.equal(isReleaseCommit('2026-10-20, Version 27.0.0-beta.0.0.0 (Alpha)'), false)
assert.equal(isReleaseCommit('2026-10-20, Version 27.0.0-alpha.0.0.0 (Beta)'), false)
assert.equal(isReleaseCommit('Working on v27.0.0-beta.0.0.1'), false)
assert.equal(isReleaseCommit('Working on v27.0.0-alpha.0.0'), false)
assert.equal(isReleaseCommit('Working on v27.0.0-alpha.0.0.1 and more'), false)
assert.equal(isReleaseCommit('doc: add 27.0.0-alpha.0.0.0 to changelog'), false)
assert.equal(isReleaseCommit('feature: refactor and improve --commit-url'), false)
})
test('test plaintext revert, with group', () => {
const commit = {
sha: 'e28b3f2813d6e8b5c4b3a2f1e0d9c8b7a6f5e4d3',
summary: 'Revert "fs: fix thing"',
author: { name: 'A' },
prUrl: 'https://github.com/nodejs/node/pull/1'
}
assert.equal(
commitToOutput(commit, formatType.PLAINTEXT, { user: 'nodejs', repo: 'node' }, '{ref}'),
' * Revert "fs: fix thing" (A) https://github.com/nodejs/node/pull/1'
)
})
test('test plaintext revert, without group', () => {
const commit = {
sha: 'e28b3f2813d6e8b5c4b3a2f1e0d9c8b7a6f5e4d3',
summary: 'Revert "fix thing"',
author: { name: 'A' }
}
assert.equal(
commitToOutput(commit, formatType.PLAINTEXT, { user: 'nodejs', repo: 'node' }, '{ref}'),
' * Revert "fix thing" (A)'
)
})