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("splits a plain string note into items under the fallback version", () => {
7 const notes = normalizeDesktopUpdateReleaseNotes(
8 "## What's changed\n- First fix\n- Second fix",
9 "1.2.3",
10 );
11 expect(notes).toEqual([{ version: "1.2.3", items: ["First fix", "Second fix"] }]);
12 });
13
14 it("keeps per-version groups and drops empty ones", () => {
15 const notes = normalizeDesktopUpdateReleaseNotes(
16 [
17 { version: "1.2.3", note: "- Newer change" },
18 { version: "1.2.2", note: "Full changelog: https://example.com/compare/x...y" },
19 { version: "1.2.1", note: "- Older change" },
20 ],
21 "1.2.3",
22 );
23 expect(notes).toEqual([
24 { version: "1.2.3", items: ["Newer change"] },
25 { version: "1.2.1", items: ["Older change"] },
26 ]);
27 });
28
29 it("decodes valid HTML entities", () => {
30 const notes = normalizeDesktopUpdateReleaseNotes("- Fix & polish 😀", "1.0.0");
31 expect(notes).toEqual([{ version: "1.0.0", items: ["Fix & polish 😀"] }]);
32 });
33
34 it("ignores malformed entries instead of throwing", () => {
35 const notes = normalizeDesktopUpdateReleaseNotes(
36 [
37 { version: "1.2.3", note: "- Valid change" },
38 { version: 42, note: "- Bad version type" },
39 { version: "1.2.1", note: { html: "<p>object note</p>" } },
40 "not an object",
41 null,
42 ],
43 "1.2.3",
44 );
45 expect(notes).toEqual([{ version: "1.2.3", items: ["Valid change"] }]);
46 });
47
48 it("returns non-empty groups even when preceded by many boilerplate-only groups", () => {
49 const boilerplate = Array.from({ length: 7 }, (_, index) => ({
50 version: `1.3.${9 - index}`,
51 note: "Full changelog: https://example.com/compare/x...y",
52 }));
53 const notes = normalizeDesktopUpdateReleaseNotes(
54 [...boilerplate, { version: "1.3.2", note: "- Older but real change" }],
55 "1.3.9",
56 );
57 expect(notes).toEqual([{ version: "1.3.2", items: ["Older but real change"] }]);
58 });
59
60 it("does not throw on out-of-range numeric entities and keeps the literal", () => {
61 expect(() =>
62 normalizeDesktopUpdateReleaseNotes("- Broken entity �", "1.0.0"),
63 ).not.toThrow();
64 const notes = normalizeDesktopUpdateReleaseNotes("- Broken entity �", "1.0.0");
65 expect(notes).toEqual([{ version: "1.0.0", items: ["Broken entity �"] }]);
66 });
67});