@@ -10,6 +10,7 @@ import {
1010 roundDecimals ,
1111 slugify ,
1212 transformLines ,
13+ truncateMultilineText ,
1314 truncateText ,
1415} from './formatting.js' ;
1516
@@ -135,7 +136,7 @@ describe('formatDate', () => {
135136describe ( 'truncateText' , ( ) => {
136137 it ( 'should replace overflowing text with ellipsis at the end' , ( ) => {
137138 expect ( truncateText ( 'All work and no play makes Jack a dull boy' , 32 ) ) . toBe (
138- 'All work and no play makes Ja... ' ,
139+ 'All work and no play makes Jack… ' ,
139140 ) ;
140141 } ) ;
141142
@@ -161,31 +162,50 @@ describe('truncateText', () => {
161162 maxChars : 10 ,
162163 position : 'start' ,
163164 } ) ,
164- ) . toBe ( '...dy day.' ) ;
165+ ) . toBe ( '…oudy day.' ) ;
165166 } ) ;
166167
167168 it ( 'should produce truncated text with ellipsis at the middle' , ( ) => {
168169 expect (
169170 truncateText ( 'Horrendous amounts of lint issues are present Tony!' , {
170- maxChars : 10 ,
171+ maxChars : 8 ,
171172 position : 'middle' ,
172173 } ) ,
173- ) . toBe ( 'Hor... ny!' ) ;
174+ ) . toBe ( 'Hor… ny!' ) ;
174175 } ) ;
175176
176177 it ( 'should produce truncated text with ellipsis at the end' , ( ) => {
177178 expect ( truncateText ( "I'm Johnny!" , { maxChars : 10 , position : 'end' } ) ) . toBe (
178- "I'm Joh... " ,
179+ "I'm Johnn… " ,
179180 ) ;
180181 } ) ;
181182
182183 it ( 'should produce truncated text with custom ellipsis' , ( ) => {
183- expect ( truncateText ( "I'm Johnny!" , { maxChars : 10 , ellipsis : '* ' } ) ) . toBe (
184- "I'm Johnn* " ,
184+ expect ( truncateText ( "I'm Johnny!" , { maxChars : 10 , ellipsis : '... ' } ) ) . toBe (
185+ "I'm Joh... " ,
185186 ) ;
186187 } ) ;
187188} ) ;
188189
190+ describe ( 'transformMultilineText' , ( ) => {
191+ it ( 'should replace additional lines with an ellipsis' , ( ) => {
192+ const error = `SchemaValidationError: Invalid CoreConfig in code-pushup.config.ts file
193+ ✖ Invalid input: expected array, received undefined
194+ → at plugins` ;
195+ expect ( truncateMultilineText ( error ) ) . toBe (
196+ 'SchemaValidationError: Invalid CoreConfig in code-pushup.config.ts file […]' ,
197+ ) ;
198+ } ) ;
199+
200+ it ( 'should leave one-liner texts unchanged' , ( ) => {
201+ expect ( truncateMultilineText ( 'Hello, world!' ) ) . toBe ( 'Hello, world!' ) ;
202+ } ) ;
203+
204+ it ( 'should omit ellipsis if additional lines have no non-whitespace characters' , ( ) => {
205+ expect ( truncateMultilineText ( '- item 1\n \n\n' ) ) . toBe ( '- item 1' ) ;
206+ } ) ;
207+ } ) ;
208+
189209describe ( 'transformLines' , ( ) => {
190210 it ( 'should apply custom transformation to each line' , ( ) => {
191211 let count = 0 ;
0 commit comments