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 );
25
26 expect(result).toEqual({
27 releaseNotes: [
28 {
29 version: "0.0.36-nightly.20260828.1213",
30 items: [
31 "fix(opencode): handle child approvals, stops, and model catalogs by @human in #8480",
32 "fix(web): keep long task drawers usable on small screens by @human in #8313",
33 "fix: eighth change",
34 "fix: seventh change",
35 "fix: sixth change",
36 "fix: fifth change",
37 "fix: fourth change",
38 "fix: third change",
39 ],
40 totalItems: 10,
41 },
42 ],
43 omittedReleaseCount: 0,
44 });
45 });
46
47 it("excludes a GitHub HTML contributor section", () => {
48 const result = normalizeDesktopUpdateReleaseNotes(
49 "<h2>What's Changed</h2><ul><li>Older fix</li><li>Newer fix</li></ul>" +
50 "<h2>New Contributors</h2><ul><li>@human made their first contribution</li></ul>" +
51 "<h2>Full Changelog</h2>",
52 "1.2.3",
53 );
54
55 expect(result).toEqual({
56 releaseNotes: [{ version: "1.2.3", items: ["Newer fix", "Older fix"], totalItems: 2 }],
57 omittedReleaseCount: 0,
58 });
59 });
60
61 it("does not count Markdown or HTML section headings as changes", () => {
62 const changes = Array.from({ length: 8 }, (_, index) => `Change ${index + 1}`);
63 const result = normalizeDesktopUpdateReleaseNotes(
64 [
65 { version: "1.2.4", note: ["### Features", ...changes].join("\n- ") },
66 {
67 version: "1.2.3",
68 note: `<h3>Fixes</h3><ul>${changes.map((change) => `<li>${change}</li>`).join("")}</ul>`,
69 },
70 ],
71 "1.2.4",
72 );
73
74 expect(result.releaseNotes).toEqual([
75 { version: "1.2.4", items: changes.toReversed(), totalItems: 8 },
76 { version: "1.2.3", items: changes.toReversed(), totalItems: 8 },
77 ]);
78 });
79
80 it("keeps per-version order and drops empty groups", () => {
81 const result = normalizeDesktopUpdateReleaseNotes(
82 [
83 { version: "1.2.3", note: "- Newer release" },
84 { version: "1.2.2", note: "Full changelog: https://example.com/compare/x...y" },
85 { version: "1.2.1", note: "- Older release" },
86 ],
87 "1.2.3",
88 );
89
90 expect(result).toEqual({
91 releaseNotes: [
92 { version: "1.2.3", items: ["Newer release"], totalItems: 1 },
93 { version: "1.2.1", items: ["Older release"], totalItems: 1 },
94 ],
95 omittedReleaseCount: 0,
96 });
97 });
98
99 it("counts valid groups before applying the six-release limit", () => {
100 const releaseNotes = [
101 { version: "1.3.9", note: "- Change 9" },
102 { version: "1.3.8", note: "Full changelog: https://example.com/compare/x...y" },
103 { version: "1.3.7", note: "- Change 7" },
104 { version: "1.3.6", note: "- Change 6" },
105 { version: "1.3.5", note: "- Change 5" },
106 { version: "1.3.4", note: "- Change 4" },
107 { version: "1.3.3", note: "- Change 3" },
108 { version: "1.3.2", note: "- Change 2" },
109 ];
110
111 const result = normalizeDesktopUpdateReleaseNotes(releaseNotes, "1.3.9");
112
113 expect(result.releaseNotes.map(({ version }) => version)).toEqual([
114 "1.3.9",
115 "1.3.7",
116 "1.3.6",
117 "1.3.5",
118 "1.3.4",
119 "1.3.3",
120 ]);
121 expect(result.omittedReleaseCount).toBe(1);
122 });
123
124 it("decodes valid HTML entities", () => {
125 const result = normalizeDesktopUpdateReleaseNotes("- Fix & polish 😀", "1.0.0");
126 expect(result).toEqual({
127 releaseNotes: [{ version: "1.0.0", items: ["Fix & polish 😀"], totalItems: 1 }],
128 omittedReleaseCount: 0,
129 });
130 });
131
132 it("ignores malformed and empty entries instead of throwing", () => {
133 const result = normalizeDesktopUpdateReleaseNotes(
134 [
135 { version: "1.2.3", note: "- Valid change" },
136 { version: "1.2.2", note: "" },
137 { version: 42, note: "- Bad version type" },
138 { version: "1.2.1", note: { html: "<p>object note</p>" } },
139 "not an object",
140 null,
141 ],
142 "1.2.3",
143 );
144
145 expect(result).toEqual({
146 releaseNotes: [{ version: "1.2.3", items: ["Valid change"], totalItems: 1 }],
147 omittedReleaseCount: 0,
148 });
149 });
150
151 it("returns an empty result for an invalid payload", () => {
152 expect(normalizeDesktopUpdateReleaseNotes({ note: "- Invalid" }, "1.0.0")).toEqual({
153 releaseNotes: [],
154 omittedReleaseCount: 0,
155 });
156 });
157
158 it("does not throw on out-of-range numeric entities and keeps the literal", () => {
159 const result = normalizeDesktopUpdateReleaseNotes("- Broken entity �", "1.0.0");
160 expect(result).toEqual({
161 releaseNotes: [{ version: "1.0.0", items: ["Broken entity �"], totalItems: 1 }],
162 omittedReleaseCount: 0,
163 });
164 });
165});