@@ -6,8 +6,7 @@ import { SortedChangeTypes } from '../../changefile/changeTypes';
66
77const { renderEntry, renderEntries, renderChangeTypeHeader, renderChangeTypeSection, renderHeader } = defaultRenderers ;
88
9- const leadingNewlineRegex = / ^ \n / ;
10- const trailingNewlineRegex = / \n $ / ;
9+ const leadingTrailingNewlineRegex = / ^ \n | \n $ / ;
1110
1211describe ( 'changelog renderers -' , ( ) => {
1312 function getRenderInfo ( ) : PackageChangelogRenderInfo {
@@ -32,6 +31,7 @@ describe('changelog renderers -', () => {
3231 } ,
3332 previousJson : { } as ChangelogJson ,
3433 renderers : { ...defaultRenderers } , // copy in case of modification
34+ defaultRenderers,
3535 } ;
3636 }
3737
@@ -53,87 +53,150 @@ describe('changelog renderers -', () => {
5353 return renderInfo ;
5454 }
5555
56- function doBasicTests ( result : string ) {
57- expect ( result ) . not . toMatch ( leadingNewlineRegex ) ;
58- expect ( result ) . not . toMatch ( trailingNewlineRegex ) ;
59- expect ( result ) . toMatchSnapshot ( ) ;
60- }
61-
6256 describe ( 'renderEntry' , ( ) => {
6357 it ( 'has correct output' , async ( ) => {
6458 const renderInfo = getRenderInfo ( ) ;
6559 const result = await renderEntry ( renderInfo . newVersionChangelog . comments . minor ! [ 0 ] , renderInfo ) ;
66- doBasicTests ( result ) ;
60+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
61+ expect ( result ) . toMatchInlineSnapshot ( `"- Awesome change (user1@example.com)"` ) ;
6762 } ) ;
6863
6964 it ( 'has correct grouped output' , async ( ) => {
7065 const renderInfo = getGroupedRenderInfo ( ) ;
7166 const result = await renderEntry ( renderInfo . newVersionChangelog . comments . minor ! [ 0 ] , renderInfo ) ;
72- doBasicTests ( result ) ;
67+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
68+ expect ( result ) . toMatchInlineSnapshot ( `"- Awesome change (user1@example.com)"` ) ;
69+ } ) ;
70+
71+ it ( 'escapes < outside of code blocks' , async ( ) => {
72+ const renderInfo = getRenderInfo ( ) ;
73+ renderInfo . newVersionChangelog . comments . minor ! [ 0 ] . comment = 'Add --config <file>' ;
74+ const result = await renderEntry ( renderInfo . newVersionChangelog . comments . minor ! [ 0 ] , renderInfo ) ;
75+ expect ( result ) . toMatchInlineSnapshot ( `"- Add --config \\<file> (user1@example.com)"` ) ;
76+ } ) ;
77+
78+ it ( 'does not escape < inside code blocks' , async ( ) => {
79+ const renderInfo = getRenderInfo ( ) ;
80+ renderInfo . newVersionChangelog . comments . minor ! [ 0 ] . comment = 'Add `--config <file>`' ;
81+ const result = await renderEntry ( renderInfo . newVersionChangelog . comments . minor ! [ 0 ] , renderInfo ) ;
82+ expect ( result ) . toMatchInlineSnapshot ( `"- Add \`--config <file>\` (user1@example.com)"` ) ;
7383 } ) ;
7484 } ) ;
7585
7686 describe ( 'renderEntries' , ( ) => {
7787 it ( 'has correct output' , async ( ) => {
7888 const renderInfo = getRenderInfo ( ) ;
7989 const result = await renderEntries ( 'minor' , renderInfo ) ;
80- doBasicTests ( result ) ;
90+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
91+ expect ( result ) . toMatchInlineSnapshot ( `
92+ "- Awesome change (user1@example.com)
93+ - Boring change (user2@example.com)"
94+ ` ) ;
8195 } ) ;
8296
8397 it ( 'has correct grouped output' , async ( ) => {
8498 const renderInfo = getGroupedRenderInfo ( ) ;
8599 const result = await renderEntries ( 'minor' , renderInfo ) ;
86- doBasicTests ( result ) ;
100+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
101+ expect ( result ) . toMatchInlineSnapshot ( `
102+ "- \`bar\`
103+ - Awesome change (user1@example.com)
104+ - \`foo\`
105+ - Boring change (user2@example.com)"
106+ ` ) ;
87107 } ) ;
88108 } ) ;
89109
90110 describe ( 'renderChangeTypeHeader' , ( ) => {
91111 it ( 'has correct output' , async ( ) => {
92112 const renderInfo = getRenderInfo ( ) ;
93113 const result = await renderChangeTypeHeader ( 'minor' , renderInfo ) ;
94- doBasicTests ( result ) ;
114+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
115+ expect ( result ) . toMatchInlineSnapshot ( `"### Minor changes"` ) ;
95116 } ) ;
96117
97118 it ( 'has correct grouped output' , async ( ) => {
98119 const renderInfo = getGroupedRenderInfo ( ) ;
99120 const result = await renderChangeTypeHeader ( 'minor' , renderInfo ) ;
100- doBasicTests ( result ) ;
121+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
122+ expect ( result ) . toMatchInlineSnapshot ( `"### Minor changes"` ) ;
101123 } ) ;
102124 } ) ;
103125
104126 describe ( 'renderChangeTypeSection' , ( ) => {
105127 it ( 'has correct output' , async ( ) => {
106128 const renderInfo = getRenderInfo ( ) ;
107129 const result = await renderChangeTypeSection ( 'minor' , renderInfo ) ;
108- doBasicTests ( result ) ;
130+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
131+ expect ( result ) . toMatchInlineSnapshot ( `
132+ "### Minor changes
133+
134+ - Awesome change (user1@example.com)
135+ - Boring change (user2@example.com)"
136+ ` ) ;
109137 } ) ;
110138
111139 it ( 'has correct grouped output' , async ( ) => {
112140 const renderInfo = getGroupedRenderInfo ( ) ;
113141 const result = await renderChangeTypeSection ( 'minor' , renderInfo ) ;
114- doBasicTests ( result ) ;
142+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
143+ expect ( result ) . toMatchInlineSnapshot ( `
144+ "### Minor changes
145+
146+ - \`bar\`
147+ - Awesome change (user1@example.com)
148+ - \`foo\`
149+ - Boring change (user2@example.com)"
150+ ` ) ;
115151 } ) ;
116152 } ) ;
117153
118154 describe ( 'renderHeader' , ( ) => {
119155 it ( 'has correct output' , async ( ) => {
120156 const renderInfo = getRenderInfo ( ) ;
121157 const result = await renderHeader ( renderInfo ) ;
122- doBasicTests ( result ) ;
158+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
159+ expect ( result ) . toMatchInlineSnapshot ( `
160+ "## 1.2.3
161+
162+ Thu, 22 Aug 2019 21:20:40 GMT"
163+ ` ) ;
123164 } ) ;
124165
125166 it ( 'has correct grouped output' , async ( ) => {
126167 const renderInfo = getGroupedRenderInfo ( ) ;
127168 const result = await renderHeader ( renderInfo ) ;
128- doBasicTests ( result ) ;
169+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
170+ expect ( result ) . toMatchInlineSnapshot ( `
171+ "## 1.2.3
172+
173+ Thu, 22 Aug 2019 21:20:40 GMT"
174+ ` ) ;
129175 } ) ;
130176 } ) ;
131177
132178 describe ( 'renderPackageChangelog' , ( ) => {
133179 it ( 'has correct output' , async ( ) => {
134180 const renderInfo = getRenderInfo ( ) ;
135181 const result = await renderPackageChangelog ( renderInfo ) ;
136- doBasicTests ( result ) ;
182+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
183+ // Most of the package output snapshots go in a snapshot file since they're longer,
184+ // but include one inline to help as a sanity check.
185+ expect ( result ) . toMatchInlineSnapshot ( `
186+ "## 1.2.3
187+
188+ Thu, 22 Aug 2019 21:20:40 GMT
189+
190+ ### Minor changes
191+
192+ - Awesome change (user1@example.com)
193+ - Boring change (user2@example.com)
194+
195+ ### Patches
196+
197+ - Fix (user1@example.com)
198+ - stuff (user2@example.com)"
199+ ` ) ;
137200 } ) ;
138201
139202 it ( 'includes all change types' , async ( ) => {
@@ -149,13 +212,15 @@ describe('changelog renderers -', () => {
149212 expect ( result ) . toContain ( `${ type } change` ) ;
150213 }
151214 }
152- doBasicTests ( result ) ;
215+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
216+ expect ( result ) . toMatchSnapshot ( ) ;
153217 } ) ;
154218
155219 it ( 'has correct grouped output' , async ( ) => {
156220 const renderInfo = getGroupedRenderInfo ( ) ;
157221 const result = await renderPackageChangelog ( renderInfo ) ;
158- doBasicTests ( result ) ;
222+ expect ( result ) . not . toMatch ( leadingTrailingNewlineRegex ) ;
223+ expect ( result ) . toMatchSnapshot ( ) ;
159224 } ) ;
160225
161226 it ( 'uses custom renderEntry' , async ( ) => {
0 commit comments