@@ -3,7 +3,7 @@ import { describe, it } from 'node:test';
33
44import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs' ;
55
6- import { transformHeadingNode } from '../buildContent.mjs' ;
6+ import { transformHeadingNode , gatherChangeEntries } from '../buildContent.mjs' ;
77
88const heading = {
99 type : 'heading' ,
@@ -67,3 +67,78 @@ describe('transformHeadingNode (deprecation Type -> AlertBox level)', () => {
6767 assert . equal ( levelAttr . value , 'danger' ) ;
6868 } ) ;
6969} ) ;
70+
71+ describe ( 'gatherChangeEntries' , ( ) => {
72+ it ( 'returns empty array when entry has no changes' , ( ) => {
73+ assert . deepEqual ( gatherChangeEntries ( { } ) , [ ] ) ;
74+ } ) ;
75+
76+ it ( 'collects lifecycle changes with formatted labels' , ( ) => {
77+ const result = gatherChangeEntries ( {
78+ added : [ 'v20.0.0' , 'v18.0.0' ] ,
79+ deprecated : 'v22.0.0' ,
80+ } ) ;
81+
82+ assert . equal ( result . length , 2 ) ;
83+ assert . deepEqual ( result [ 0 ] , {
84+ versions : [ 'v20.0.0' , 'v18.0.0' ] ,
85+ label : 'Added in: v20.0.0, v18.0.0' ,
86+ } ) ;
87+ assert . deepEqual ( result [ 1 ] , {
88+ versions : [ 'v22.0.0' ] ,
89+ label : 'Deprecated in: v22.0.0' ,
90+ } ) ;
91+ } ) ;
92+
93+ it ( 'extracts plain text labels from markdown descriptions' , ( ) => {
94+ const result = gatherChangeEntries ( {
95+ changes : [
96+ {
97+ version : 'v25.0.0' ,
98+ description :
99+ 'Add `modifyPrototype` option to conditionally modify the prototype.' ,
100+ 'pr-url' : 'https://github.com/nodejs/node/pull/123' ,
101+ } ,
102+ ] ,
103+ } ) ;
104+
105+ assert . equal ( result . length , 1 ) ;
106+ assert . equal (
107+ result [ 0 ] . label ,
108+ 'Add `modifyPrototype` option to conditionally modify the prototype.'
109+ ) ;
110+ assert . equal ( result [ 0 ] . url , 'https://github.com/nodejs/node/pull/123' ) ;
111+ assert . deepEqual ( result [ 0 ] . versions , [ 'v25.0.0' ] ) ;
112+ } ) ;
113+
114+ it ( 'produces a string label, not an object (regression for [object Object])' , ( ) => {
115+ const result = gatherChangeEntries ( {
116+ changes : [
117+ {
118+ version : 'v1.0.0' ,
119+ description : 'Some **bold** and _italic_ text.' ,
120+ } ,
121+ ] ,
122+ } ) ;
123+
124+ assert . equal ( typeof result [ 0 ] . label , 'string' ) ;
125+ assert . equal ( result [ 0 ] . label , 'Some **bold** and _italic_ text.' ) ;
126+ } ) ;
127+
128+ it ( 'combines lifecycle changes and explicit changes' , ( ) => {
129+ const result = gatherChangeEntries ( {
130+ added : 'v20.0.0' ,
131+ changes : [
132+ {
133+ version : 'v21.0.0' ,
134+ description : 'Added new feature.' ,
135+ 'pr-url' : 'https://example.com/pr/1' ,
136+ } ,
137+ ] ,
138+ } ) ;
139+
140+ assert . equal ( result . length , 2 ) ;
141+ assert . equal ( result [ 0 ] . label , 'Added in: v20.0.0' ) ;
142+ assert . equal ( result [ 1 ] . label , 'Added new feature.' ) ;
143+ } ) ;
144+ } ) ;
0 commit comments