|
1 | | -import { readFile } from "node:fs/promises"; |
| 1 | +import { readFile, writeFile } from "node:fs/promises"; |
2 | 2 | import { join } from "node:path"; |
3 | 3 |
|
4 | 4 | import { generateChangelogEntry, parseChangelog, updateChangelog } from "#core/changelog"; |
@@ -508,4 +508,44 @@ describe("updateChangelog", () => { |
508 | 508 | expect(content).toContain("add feature A"); |
509 | 509 | expect(content).toContain("add feature B"); |
510 | 510 | }); |
| 511 | + |
| 512 | + it("should not rewrite the changelog when version is unchanged", async () => { |
| 513 | + const testdirPath = await testdir({}); |
| 514 | + const context = createChangelogTestContext(testdirPath); |
| 515 | + |
| 516 | + const existingChangelog = dedent` |
| 517 | + # @ucdjs/test |
| 518 | +
|
| 519 | + ## 0.1.0 (2025-01-15) |
| 520 | +
|
| 521 | + ### Features |
| 522 | +
|
| 523 | + * initial release |
| 524 | + `; |
| 525 | + |
| 526 | + await writeFile(join(testdirPath, "CHANGELOG.md"), `${existingChangelog}\n`, "utf-8"); |
| 527 | + |
| 528 | + mockExec.mockResolvedValueOnce({ stdout: existingChangelog, stderr: "", exitCode: 0 }); |
| 529 | + |
| 530 | + await updateChangelog({ |
| 531 | + normalizedOptions: context.normalizedOptions, |
| 532 | + workspacePackage: context.workspacePackage, |
| 533 | + version: "0.1.0", |
| 534 | + previousVersion: "0.1.0", |
| 535 | + commits: [ |
| 536 | + createCommit({ |
| 537 | + type: "feat", |
| 538 | + message: "feat: this should not be written", |
| 539 | + hash: "def456", |
| 540 | + shortHash: "def456", |
| 541 | + }), |
| 542 | + ], |
| 543 | + date: "2025-01-16", |
| 544 | + githubClient: context.githubClient, |
| 545 | + }); |
| 546 | + |
| 547 | + const content = await readFile(join(testdirPath, "CHANGELOG.md"), "utf-8"); |
| 548 | + |
| 549 | + expect(content).toBe(`${existingChangelog}\n`); |
| 550 | + }); |
511 | 551 | }); |
0 commit comments