@@ -3,62 +3,163 @@ import { describe, expect, it } from "vite-plus/test";
33import { normalizeDesktopUpdateReleaseNotes } from "./releaseNotes.ts" ;
44
55describe ( "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" ,
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>" ,
952 "1.2.3" ,
1053 ) ;
11- expect ( notes ) . toEqual ( [ { version : "1.2.3" , items : [ "First fix" , "Second fix" ] } ] ) ;
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+ ] ) ;
1278 } ) ;
1379
14- it ( "keeps per-version groups and drops empty ones " , ( ) => {
15- const notes = normalizeDesktopUpdateReleaseNotes (
80+ it ( "keeps per-version order and drops empty groups " , ( ) => {
81+ const result = normalizeDesktopUpdateReleaseNotes (
1682 [
17- { version : "1.2.3" , note : "- Newer change " } ,
83+ { version : "1.2.3" , note : "- Newer release " } ,
1884 { version : "1.2.2" , note : "Full changelog: https://example.com/compare/x...y" } ,
19- { version : "1.2.1" , note : "- Older change " } ,
85+ { version : "1.2.1" , note : "- Older release " } ,
2086 ] ,
2187 "1.2.3" ,
2288 ) ;
23- expect ( notes ) . toEqual ( [
24- { version : "1.2.3" , items : [ "Newer change" ] } ,
25- { version : "1.2.1" , items : [ "Older change" ] } ,
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" ,
26120 ] ) ;
121+ expect ( result . omittedReleaseCount ) . toBe ( 1 ) ;
27122 } ) ;
28123
29124 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 😀" ] } ] ) ;
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+ } ) ;
32130 } ) ;
33131
34- it ( "ignores malformed entries instead of throwing" , ( ) => {
35- const notes = normalizeDesktopUpdateReleaseNotes (
132+ it ( "ignores malformed and empty entries instead of throwing" , ( ) => {
133+ const result = normalizeDesktopUpdateReleaseNotes (
36134 [
37135 { version : "1.2.3" , note : "- Valid change" } ,
136+ { version : "1.2.2" , note : "" } ,
38137 { version : 42 , note : "- Bad version type" } ,
39138 { version : "1.2.1" , note : { html : "<p>object note</p>" } } ,
40139 "not an object" ,
41140 null ,
42141 ] ,
43142 "1.2.3" ,
44143 ) ;
45- expect ( notes ) . toEqual ( [ { version : "1.2.3" , items : [ "Valid change" ] } ] ) ;
144+
145+ expect ( result ) . toEqual ( {
146+ releaseNotes : [ { version : "1.2.3" , items : [ "Valid change" ] , totalItems : 1 } ] ,
147+ omittedReleaseCount : 0 ,
148+ } ) ;
46149 } ) ;
47150
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" ] } ] ) ;
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+ } ) ;
58156 } ) ;
59157
60158 it ( "does not throw on out-of-range numeric entities and keeps the literal" , ( ) => {
61- const notes = normalizeDesktopUpdateReleaseNotes ( "- Broken entity �" , "1.0.0" ) ;
62- expect ( notes ) . toEqual ( [ { version : "1.0.0" , items : [ "Broken entity �" ] } ] ) ;
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+ } ) ;
63164 } ) ;
64165} ) ;
0 commit comments