|
| 1 | +import { test } from 'node:test'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { previousRelease, releaseNotes } from './release-notes.mjs'; |
| 4 | + |
| 5 | +test('baseline is the highest published lower semantic version, excluding drafts', () => { |
| 6 | + assert.equal( |
| 7 | + previousRelease('0.2.0', [ |
| 8 | + { tag_name: 'v0.1.9' }, |
| 9 | + { tag_name: 'v0.1.10' }, |
| 10 | + { tag_name: 'v0.2.0-beta.1', draft: true }, |
| 11 | + { tag_name: 'nightly' }, |
| 12 | + { tag_name: 'v0.2.0' }, |
| 13 | + { tag_name: 'v0.3.0' }, |
| 14 | + ]).tag_name, |
| 15 | + 'v0.1.10', |
| 16 | + ); |
| 17 | + assert.equal(previousRelease('0.1.0', []), undefined); |
| 18 | +}); |
| 19 | + |
| 20 | +const commit = (sha, message) => ({ sha, commit: { message } }); |
| 21 | +const options = { |
| 22 | + repo: 'PDFMathTranslate/PDFMathReader', |
| 23 | + version: '0.1.3', |
| 24 | + sha: 'a'.repeat(40), |
| 25 | + previous: { tag_name: 'v0.1.2' }, |
| 26 | + assets: [ |
| 27 | + 'artifacts/PDFMathReader-darwin-arm64.zip', |
| 28 | + 'artifacts/PDFMathReader-linux-armv7l.tar.gz', |
| 29 | + ], |
| 30 | +}; |
| 31 | +test('notes group user changes, retain details, omit internal commits and trailers', () => { |
| 32 | + const feature = commit( |
| 33 | + 'b'.repeat(40), |
| 34 | + 'feat(reader): Formula OCR\n\nRecognize and copy LaTeX.\n\nCo-authored-by: Bot <bot@example.com>', |
| 35 | + ); |
| 36 | + const notes = releaseNotes({ |
| 37 | + ...options, |
| 38 | + commits: [ |
| 39 | + feature, |
| 40 | + feature, |
| 41 | + commit('c'.repeat(40), 'ux: Improve error dialog'), |
| 42 | + commit('d'.repeat(40), 'fix: Preserve preferences'), |
| 43 | + commit('e'.repeat(40), 'ci: Cache dependencies'), |
| 44 | + commit('f'.repeat(40), 'release: 0.1.3'), |
| 45 | + ], |
| 46 | + }); |
| 47 | + assert.match(notes, /1 new features and 2 fixes/); |
| 48 | + assert.match(notes, /\*\*Formula OCR\*\* — Recognize and copy LaTeX\./); |
| 49 | + assert.match(notes, /### Fixes and improvements/); |
| 50 | + assert.doesNotMatch(notes, /Bot|Cache dependencies|release: 0/); |
| 51 | + assert.match(notes, /releases\/download\/v0.1.3\/PDFMathReader-darwin-arm64.zip/); |
| 52 | + assert.match(notes, /Linux ARMv7/); |
| 53 | + assert.match(notes, /compare\/v0.1.2\.\.\.a{40}/); |
| 54 | +}); |
| 55 | +test('first release and maintenance-only changes still have useful notes', () => { |
| 56 | + const notes = releaseNotes({ ...options, previous: undefined, commits: [] }); |
| 57 | + assert.match(notes, /maintenance updates/); |
| 58 | + assert.match(notes, /commits\/a{40}/); |
| 59 | + assert.match(notes, /## Update/); |
| 60 | +}); |
| 61 | +test('commit text cannot inject HTML or Markdown headings', () => { |
| 62 | + const notes = releaseNotes({ |
| 63 | + ...options, |
| 64 | + commits: [commit('b'.repeat(40), 'fix: <script>\n\n# heading')], |
| 65 | + }); |
| 66 | + assert.doesNotMatch(notes, /<script>/); |
| 67 | + assert.match(notes, /\\# heading/); |
| 68 | +}); |
0 commit comments