@@ -11,10 +11,10 @@ let red = '';
11
11
let white = '' ;
12
12
13
13
const kReadableOperator = {
14
- deepStrictEqual : 'Expected inputs to be strictly deep-equal' ,
15
- notDeepStrictEqual : 'Expected "actual" not to be strictly deep-equal' ,
16
- strictEqual : 'Expected inputs to be strictly equal' ,
17
- notStrictEqual : 'Expected "actual" to be strictly unequal' ,
14
+ deepStrictEqual : 'Expected inputs to be strictly deep-equal: ' ,
15
+ notDeepStrictEqual : 'Expected "actual" not to be strictly deep-equal to: ' ,
16
+ strictEqual : 'Expected inputs to be strictly equal: ' ,
17
+ notStrictEqual : 'Expected "actual" to be strictly unequal to: ' ,
18
18
notIdentical : 'Inputs identical but not reference equal:' ,
19
19
} ;
20
20
@@ -62,7 +62,7 @@ function createErrDiff(actual, expected, operator) {
62
62
const actualLines = inspectValue ( actual ) ;
63
63
const expectedLines = inspectValue ( expected ) ;
64
64
const msg = kReadableOperator [ operator ] +
65
- `: \n${ green } + actual${ white } ${ red } - expected${ white } ` ;
65
+ `\n${ green } + actual${ white } ${ red } - expected${ white } ` ;
66
66
const skippedMsg = ` ${ blue } ...${ white } Lines skipped` ;
67
67
68
68
let i = 0 ;
@@ -80,20 +80,25 @@ function createErrDiff(actual, expected, operator) {
80
80
if ( ( typeof actual !== 'object' || actual === null ) &&
81
81
( typeof expected !== 'object' || expected === null ) &&
82
82
( actual !== 0 || expected !== 0 ) ) { // -0 === +0
83
- return `${ kReadableOperator [ operator ] } : \n\n` +
83
+ return `${ kReadableOperator [ operator ] } \n\n` +
84
84
`${ actualLines [ 0 ] } !== ${ expectedLines [ 0 ] } \n` ;
85
85
}
86
- // If the stdout is a tty and the input length is lower than the current
87
- // columns per line, add a mismatch indicator below the output.
88
- } else if ( process . stdout . isTTY &&
89
- inputLength < process . stdout . columns ) {
90
- while ( actualLines [ 0 ] [ i ] === expectedLines [ 0 ] [ i ] ) {
91
- i ++ ;
86
+ } else {
87
+ // If the stdout is a tty and the input length is lower than the current
88
+ // columns per line, add a mismatch indicator below the output. If it is
89
+ // not a tty, use a default value of 80 characters.
90
+ const maxLength = process . stdout . isTTY ? process . stdout . columns : 80 ;
91
+ if ( inputLength < maxLength ) {
92
+ while ( actualLines [ 0 ] [ i ] === expectedLines [ 0 ] [ i ] ) {
93
+ i ++ ;
94
+ }
95
+ if ( i !== 0 ) {
96
+ // Add position indicator for the first mismatch in case it is a
97
+ // single line and the input length is less than the column length.
98
+ indicator = `\n ${ ' ' . repeat ( i ) } ^` ;
99
+ i = 0 ;
100
+ }
92
101
}
93
- // Add position indicator for the first mismatch in case it is a single
94
- // line and the input length is less than the column length.
95
- indicator = `\n ${ ' ' . repeat ( i ) } ^` ;
96
- i = 0 ;
97
102
}
98
103
}
99
104
@@ -114,6 +119,26 @@ function createErrDiff(actual, expected, operator) {
114
119
a = actualLines [ actualLines . length - 1 ] ;
115
120
b = expectedLines [ expectedLines . length - 1 ] ;
116
121
}
122
+
123
+ const maxLines = Math . max ( actualLines . length , expectedLines . length ) ;
124
+ // Strict equal with identical objects that are not identical by reference.
125
+ // E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() })
126
+ if ( maxLines === 0 ) {
127
+ // We have to get the result again. The lines were all removed before.
128
+ const actualLines = inspectValue ( actual ) ;
129
+
130
+ // Only remove lines in case it makes sense to collapse those.
131
+ // TODO: Accept env to always show the full error.
132
+ if ( actualLines . length > 30 ) {
133
+ actualLines [ 26 ] = `${ blue } ...${ white } ` ;
134
+ while ( actualLines . length > 27 ) {
135
+ actualLines . pop ( ) ;
136
+ }
137
+ }
138
+
139
+ return `${ kReadableOperator . notIdentical } \n\n${ actualLines . join ( '\n' ) } \n` ;
140
+ }
141
+
117
142
if ( i > 3 ) {
118
143
end = `\n${ blue } ...${ white } ${ end } ` ;
119
144
skipped = true ;
@@ -123,9 +148,7 @@ function createErrDiff(actual, expected, operator) {
123
148
other = '' ;
124
149
}
125
150
126
- const maxLines = Math . max ( actualLines . length , expectedLines . length ) ;
127
151
let printedLines = 0 ;
128
- let identical = 0 ;
129
152
for ( i = 0 ; i < maxLines ; i ++ ) {
130
153
// Only extra expected lines exist
131
154
const cur = i - lastPos ;
@@ -185,7 +208,6 @@ function createErrDiff(actual, expected, operator) {
185
208
res += `\n ${ actualLines [ i ] } ` ;
186
209
printedLines ++ ;
187
210
}
188
- identical ++ ;
189
211
}
190
212
// Inspected object to big (Show ~20 rows max)
191
213
if ( printedLines > 20 && i < maxLines - 2 ) {
@@ -194,24 +216,6 @@ function createErrDiff(actual, expected, operator) {
194
216
}
195
217
}
196
218
197
- // Strict equal with identical objects that are not identical by reference.
198
- // E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() })
199
- if ( identical === maxLines ) {
200
- // We have to get the result again. The lines were all removed before.
201
- const actualLines = inspectValue ( actual ) ;
202
-
203
- // Only remove lines in case it makes sense to collapse those.
204
- // TODO: Accept env to always show the full error.
205
- if ( actualLines . length > 30 ) {
206
- actualLines [ 26 ] = `${ blue } ...${ white } ` ;
207
- while ( actualLines . length > 27 ) {
208
- actualLines . pop ( ) ;
209
- }
210
- }
211
-
212
- return `${ kReadableOperator . notIdentical } \n\n${ actualLines . join ( '\n' ) } \n` ;
213
- }
214
-
215
219
return `${ msg } ${ skipped ? skippedMsg : '' } \n${ res } ${ other } ${ end } ${ indicator } ` ;
216
220
}
217
221
0 commit comments