File tree 2 files changed +60
-6
lines changed
2 files changed +60
-6
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,19 @@ function getErrMessage(call) {
193
193
if ( EOL === '\r\n' ) {
194
194
message = message . replace ( / \r \n / g, '\n' ) ;
195
195
}
196
+ // Always normalize indentation, otherwise the message could look weird.
197
+ if ( message . indexOf ( '\n' ) !== - 1 ) {
198
+ const tmp = message . split ( '\n' ) ;
199
+ message = tmp [ 0 ] ;
200
+ for ( var i = 1 ; i < tmp . length ; i ++ ) {
201
+ let pos = 0 ;
202
+ while ( pos < column &&
203
+ ( tmp [ i ] [ pos ] === ' ' || tmp [ i ] [ pos ] === '\t' ) ) {
204
+ pos ++ ;
205
+ }
206
+ message += `\n ${ tmp [ i ] . slice ( pos ) } ` ;
207
+ }
208
+ }
196
209
message = 'The expression evaluated to a falsy value:' +
197
210
`\n\n assert${ ok } (${ message } )\n` ;
198
211
}
Original file line number Diff line number Diff line change @@ -694,14 +694,55 @@ common.expectsError(
694
694
{
695
695
code : 'ERR_ASSERTION' ,
696
696
type : assert . AssertionError ,
697
- message : 'The expression evaluated to a falsy value:\n\n ' +
698
- "assert((() => 'string')()\n" +
699
- ' // eslint-disable-next-line\n' +
700
- ' ===\n' +
701
- ' 123 instanceof\n' +
702
- ' Buffer)\n'
697
+ message : 'The expression evaluated to a falsy value:\n\n' +
698
+ ' assert((() => \'string\')()\n' +
699
+ ' // eslint-disable-next-line\n' +
700
+ ' ===\n' +
701
+ ' 123 instanceof\n' +
702
+ ' Buffer)\n'
703
+ }
704
+ ) ;
705
+
706
+ common . expectsError (
707
+ ( ) => {
708
+ a (
709
+ ( ( ) => 'string' ) ( )
710
+ // eslint-disable-next-line
711
+ ===
712
+ 123 instanceof
713
+ Buffer
714
+ ) ;
715
+ } ,
716
+ {
717
+ code : 'ERR_ASSERTION' ,
718
+ type : assert . AssertionError ,
719
+ message : 'The expression evaluated to a falsy value:\n\n' +
720
+ ' assert((() => \'string\')()\n' +
721
+ ' // eslint-disable-next-line\n' +
722
+ ' ===\n' +
723
+ ' 123 instanceof\n' +
724
+ ' Buffer)\n'
725
+ }
726
+ ) ;
727
+
728
+ /* eslint-disable indent */
729
+ common . expectsError ( ( ) => {
730
+ a ( (
731
+ ( ) => 'string' ) ( ) ===
732
+ 123 instanceof
733
+ Buffer
734
+ ) ;
735
+ } , {
736
+ code : 'ERR_ASSERTION' ,
737
+ type : assert . AssertionError ,
738
+ message : 'The expression evaluated to a falsy value:\n\n' +
739
+ ' assert((\n' +
740
+ ' () => \'string\')() ===\n' +
741
+ ' 123 instanceof\n' +
742
+ ' Buffer)\n'
703
743
}
704
744
) ;
745
+ /* eslint-enable indent */
705
746
706
747
common . expectsError (
707
748
( ) => assert ( null , undefined ) ,
You can’t perform that action at this time.
0 commit comments