Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { normalizeDesktopUpdateReleaseNotes } from "./releaseNotes.ts";
4
5describe("normalizeDesktopUpdateReleaseNotes", () => {
6 it("shows the newest changes and counts all real changes", () => {
7 const result = normalizeDesktopUpdateReleaseNotes(
8 [
9 "- feat: first change",
10 "- fix: second change",
11 "- fix: third change",
12 "- fix: fourth change",
13 "- fix: fifth change",
14 "- fix: sixth change",
15 "- fix: seventh change",
16 "- fix: eighth change",
17 "- fix(web): keep long task drawers usable on small screens by @human in #8313",
18 "- fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
19 "## New Contributors",
20 "- @human made their first contribution in #8435",
21 "**Full Changelog**: https://github.com/pingdotgg/t3code/compare/old...new",
22 ].join("\n"),
23 "0.0.36-nightly.20260828.1213",
24 "nightly",
25 );
26
27 expect(result).toEqual({
28 releaseNotes: [
29 {
30 version: "0.0.36-nightly.20260828.1213",
31 items: [
32 "fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
33 "fix(web): keep long task drawers usable on small screens by @human in #8313",
34 "fix: eighth change",
35 "fix: seventh change",
36 "fix: sixth change",
37 "fix: fifth change",
38 "fix: fourth change",
39 "fix: third change",
40 ],
41 totalItems: 10,
42 },
43 ],
44 omittedReleaseCount: 0,
45 });
46 });
47
48 it("excludes a GitHub HTML contributor section", () => {
49 const result = normalizeDesktopUpdateReleaseNotes(
50 "<h2>What's Changed</h2><ul><li>Older fix</li><li>Newer fix</li></ul>" +
51 "<h2>New Contributors</h2><ul><li>@human made their first contribution</li></ul>" +
52 "<h2>Full Changelog</h2>",
53 "1.2.3",
54 "latest",
55 );
56
57 expect(result).toEqual({
58 releaseNotes: [{ version: "1.2.3", items: ["Newer fix", "Older fix"], totalItems: 2 }],
59 omittedReleaseCount: 0,
60 });
61 });
62
63 it("does not count Markdown or HTML section headings as changes", () => {
64 const changes = Array.from({ length: 8 }, (_, index) => `Change ${index + 1}`);
65 const result = normalizeDesktopUpdateReleaseNotes(
66 [
67 { version: "1.2.4", note: ["### Features", ...changes].join("\n- ") },
68 {
69 version: "1.2.3",
70 note: `<h3>Fixes</h3><ul>${changes.map((change) => `<li>${change}</li>`).join("")}</ul>`,
71 },
72 ],
73 "1.2.4",
74 "latest",
75 );
76
77 expect(result.releaseNotes).toEqual([
78 { version: "1.2.4", items: changes.toReversed(), totalItems: 8 },
79 { version: "1.2.3", items: changes.toReversed(), totalItems: 8 },
80 ]);
81 });
82
83 it("drops releases from other trains before grouping on nightly", () => {
84 const releaseNotes = [
85 { version: "0.0.41-preview.20260914.1683", note: "- Maintainer test build" },
86 { version: "0.0.41-preview.20260913.1669", note: "- Maintainer test build" },
87 { version: "0.0.41-nightly.20260914.1707", note: "- Nightly change 2" },
88 { version: "0.0.41-nightly.20260914.1700", note: "- Nightly change 1" },
89 ];
90
91 const result = normalizeDesktopUpdateReleaseNotes(
92 releaseNotes,
93 "0.0.41-nightly.20260914.1707",
94 "nightly",
95 );
96
97 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
98 "0.0.41-nightly.20260914.1707",
99 "0.0.41-nightly.20260914.1700",
100 ]);
101 expect(result.omittedReleaseCount).toBe(0);
102 });
103
104 // regression: #11753 prerelease entries leaked into a channel's update changelog
105 it("keeps only stable releases on the latest channel", () => {
106 const result = normalizeDesktopUpdateReleaseNotes(
107 [
108 { version: "0.0.42", note: "- Stable change" },
109 { version: "0.0.42-nightly.20260915.1710", note: "- Nightly change" },
110 ],
111 "0.0.42",
112 "latest",
113 );
114
115 expect(result.releaseNotes.map(({ version }) => version)).toEqual(["0.0.42"]);
116 });
117
118 it("counts valid groups before applying the six-release limit", () => {
119 const releaseNotes = [
120 { version: "1.3.9", note: "- Change 9" },
121 { version: "1.3.8", note: "Full changelog: https://example.com/compare/x...y" },
122 { version: "1.3.7", note: "- Change 7" },
123 { version: "1.3.6", note: "- Change 6" },
124 { version: "1.3.5", note: "- Change 5" },
125 { version: "1.3.4", note: "- Change 4" },
126 { version: "1.3.3", note: "- Change 3" },
127 { version: "1.3.2", note: "- Change 2" },
128 ];
129
130 const result = normalizeDesktopUpdateReleaseNotes(releaseNotes, "1.3.9", "latest");
131
132 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
133 "1.3.9",
134 "1.3.7",
135 "1.3.6",
136 "1.3.5",
137 "1.3.4",
138 "1.3.3",
139 ]);
140 expect(result.omittedReleaseCount).toBe(1);
141 });
142
143 it("ignores malformed and empty entries instead of throwing", () => {
144 const result = normalizeDesktopUpdateReleaseNotes(
145 [
146 { version: "1.2.3", note: "- Valid change" },
147 { version: "1.2.2", note: "" },
148 { version: 42, note: "- Bad version type" },
149 { version: "1.2.1", note: { html: "<p>object note</p>" } },
150 "not an object",
151 null,
152 ],
153 "1.2.3",
154 "latest",
155 );
156
157 expect(result).toEqual({
158 releaseNotes: [{ version: "1.2.3", items: ["Valid change"], totalItems: 1 }],
159 omittedReleaseCount: 0,
160 });
161 });
162
163 it("does not throw on out-of-range numeric entities and keeps the literal", () => {
164 const result = normalizeDesktopUpdateReleaseNotes(
165 "- Broken entity �",
166 "1.0.0",
167 "latest",
168 );
169 expect(result).toEqual({
170 releaseNotes: [{ version: "1.0.0", items: ["Broken entity �"], totalItems: 1 }],
171 omittedReleaseCount: 0,
172 });
173 });
174});