import test from "node:test"; import assert from "node:assert/strict"; import { extractVersionNotes } from "../lib/extract-version-notes.mjs"; const changelog = `# Fusion changelog ## 1.2.0 ### @runfusion/fusion #### Patch Changes - Added release integration. ## 1.1.0 ### @runfusion/fusion #### Patch Changes - Fixed parser bug. ## 1.0.0 ### @runfusion/fusion #### Patch Changes - Initial release. `; test("extracts correct section for known version", () => { const notes = extractVersionNotes(changelog, "1.1.0"); assert.match(notes, /Fixed parser bug\./); assert.doesNotMatch(notes, /Added release integration\./); }); test("returns full multiline body including sub-headings", () => { const notes = extractVersionNotes(changelog, "1.2.0"); assert.match(notes, /^### @runfusion\/fusion/m); assert.match(notes, /^#### Patch Changes/m); assert.match(notes, /- Added release integration\./); }); test("returns fallback when version not found", () => { const notes = extractVersionNotes(changelog, "9.9.9"); assert.equal(notes, "Release v9.9.9"); }); test("returns fallback when changelog content is empty", () => { const notes = extractVersionNotes("", "1.2.0"); assert.equal(notes, "Release v1.2.0"); }); test("handles version as last section with no trailing heading", () => { const notes = extractVersionNotes(changelog, "1.0.0"); assert.match(notes, /Initial release\./); }); test("handles single-version changelog", () => { const single = `# Changelog\n\n## 2.0.0\n\n### pkg\n\n#### Patch Changes\n\n- Solo entry.\n`; const notes = extractVersionNotes(single, "2.0.0"); assert.match(notes, /Solo entry\./); }); test("does not bleed into adjacent version sections", () => { const notes = extractVersionNotes(changelog, "1.1.0"); assert.doesNotMatch(notes, /Initial release\./); assert.doesNotMatch(notes, /Added release integration\./); });