-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrelease-notes.test.ts
More file actions
182 lines (160 loc) · 5.55 KB
/
Copy pathrelease-notes.test.ts
File metadata and controls
182 lines (160 loc) · 5.55 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
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
/**
* CHANGELOG.md has accumulated several heading styles over the years — bare
* `## 1.2.3 - date` from the current generator, bracketed `## [1.2.3]` from
* Keep a Changelog, and `## [v1.2.3]` from the generator before that.
*
* parseChangelogText decides which of them become GitHub Release notes, and a
* heading it does not recognize is skipped in silence: no error, no warning,
* just a published release with an empty body. That is exactly how v4.3.0
* shipped with no notes, so every style the file actually contains is pinned
* here.
*
* @module
*/
import { assertEquals } from "@std/assert";
import { normalizeTag, parseChangelogText } from "./release-notes.ts";
// =============================================================================
// parseChangelogText — heading styles
// =============================================================================
Deno.test("parseChangelogText reads a bare '## <version> - <date>' heading", () => {
const entries = parseChangelogText(
["## 4.3.0 - 2026-08-08", "", "- feat(cli): add a thing", ""].join("\n"),
);
assertEquals(entries.length, 1);
assertEquals(entries[0]!.version, "4.3.0");
assertEquals(entries[0]!.tag, "v4.3.0");
assertEquals(entries[0]!.date, "2026-08-08");
});
Deno.test("parseChangelogText reads a bracketed '## [<version>] - <date>' heading", () => {
const entries = parseChangelogText(
["## [4.1.0] - 2025-01-01", "", "- fix: an older thing", ""].join("\n"),
);
assertEquals(entries.length, 1);
assertEquals(entries[0]!.version, "4.1.0");
assertEquals(entries[0]!.tag, "v4.1.0");
assertEquals(entries[0]!.date, "2025-01-01");
});
// The regression that emptied the v4.3.0 release notes: the `v` inside the
// brackets survived into the version string, the `^\d` guard below the match
// then read it as a non-version heading like [Unreleased], and the section
// vanished from the parse entirely.
Deno.test("parseChangelogText reads a v-prefixed '## [v<version>]' heading", () => {
const entries = parseChangelogText(
["## [v4.1.61] - 2025-01-01", "", "- fix: a legacy-style section", ""]
.join("\n"),
);
assertEquals(entries.length, 1);
assertEquals(entries[0]!.version, "4.1.61");
assertEquals(entries[0]!.tag, "v4.1.61");
assertEquals(entries[0]!.date, "2025-01-01");
});
Deno.test("parseChangelogText keeps all three heading styles in file order", () => {
const entries = parseChangelogText(
[
"# Changelog",
"",
"## 4.3.0 - 2026-08-08",
"",
"- newest",
"",
"## [4.2.0] - 2025-06-01",
"",
"- middle",
"",
"## [v4.1.61] - 2025-01-01",
"",
"- oldest",
"",
].join("\n"),
);
assertEquals(entries.map((entry) => entry.tag), [
"v4.3.0",
"v4.2.0",
"v4.1.61",
]);
});
// =============================================================================
// parseChangelogText — non-version headings
// =============================================================================
Deno.test("parseChangelogText skips Unreleased in both heading styles", () => {
const entries = parseChangelogText(
[
"# Changelog",
"",
"## Unreleased",
"",
"- not shipped yet",
"",
"## [Unreleased]",
"",
"- also not shipped",
"",
"## 4.3.0 - 2026-08-08",
"",
"- shipped",
"",
].join("\n"),
);
assertEquals(entries.map((entry) => entry.version), ["4.3.0"]);
});
// =============================================================================
// parseChangelogText — notes body
// =============================================================================
Deno.test("parseChangelogText captures the body between two headings", () => {
const entries = parseChangelogText(
[
"# Changelog",
"",
"## 4.3.0 - 2026-08-08",
"",
"### Features",
"",
"- add a thing",
"",
"## 4.2.0 - 2026-07-01",
"",
"- an older thing",
"",
].join("\n"),
);
assertEquals(entries.length, 2);
assertEquals(
entries[0]!.notes,
"## 4.3.0 - 2026-08-08\n\n### Features\n\n- add a thing\n",
);
assertEquals(
entries[1]!.notes,
"## 4.2.0 - 2026-07-01\n\n- an older thing\n",
);
});
// The rendered heading drops the legacy `v`, so notes read the same regardless
// of which generator wrote the section.
Deno.test("parseChangelogText renders a v-prefixed section under its bare version", () => {
const entries = parseChangelogText(
["## [v4.1.61] - 2025-01-01", "", "- a legacy-style section", ""].join(
"\n",
),
);
assertEquals(
entries[0]!.notes,
"## 4.1.61 - 2025-01-01\n\n- a legacy-style section\n",
);
});
Deno.test("parseChangelogText returns no entries when nothing is a version", () => {
assertEquals(
parseChangelogText("# Changelog\n\n## [Unreleased]\n\n- soon\n"),
[],
);
});
// =============================================================================
// normalizeTag
// =============================================================================
Deno.test("normalizeTag adds the v prefix, keeps it, and strips refs/tags/", () => {
// The three shapes a tag arrives in: a VERSION file read, a hand-typed
// --tag, and GITHUB_REF from a tag-triggered workflow.
assertEquals(normalizeTag("4.3.0"), "v4.3.0");
assertEquals(normalizeTag("v4.3.0"), "v4.3.0");
assertEquals(normalizeTag("refs/tags/v4.3.0"), "v4.3.0");
assertEquals(normalizeTag(" v4.3.0 "), "v4.3.0");
});