Skip to content

Commit c9bb91a

Browse files
BridgeARjasnell
authored andcommitted
assert: remove errorDiff property
The property is not necessary as it is possible to check for the operator instead. PR-URL: #19467 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent eb427ca commit c9bb91a

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

lib/assert.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ const meta = [
5454

5555
const escapeFn = (str) => meta[str.charCodeAt(0)];
5656

57-
const ERR_DIFF_NOT_EQUAL = 1;
58-
const ERR_DIFF_EQUAL = 2;
59-
6057
let warned = false;
6158

6259
// The assert module provides functions that throw
@@ -321,8 +318,7 @@ assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) {
321318
expected,
322319
message,
323320
operator: 'deepStrictEqual',
324-
stackStartFn: deepStrictEqual,
325-
errorDiff: ERR_DIFF_EQUAL
321+
stackStartFn: deepStrictEqual
326322
});
327323
}
328324
};
@@ -335,8 +331,7 @@ function notDeepStrictEqual(actual, expected, message) {
335331
expected,
336332
message,
337333
operator: 'notDeepStrictEqual',
338-
stackStartFn: notDeepStrictEqual,
339-
errorDiff: ERR_DIFF_NOT_EQUAL
334+
stackStartFn: notDeepStrictEqual
340335
});
341336
}
342337
}
@@ -348,8 +343,7 @@ assert.strictEqual = function strictEqual(actual, expected, message) {
348343
expected,
349344
message,
350345
operator: 'strictEqual',
351-
stackStartFn: strictEqual,
352-
errorDiff: ERR_DIFF_EQUAL
346+
stackStartFn: strictEqual
353347
});
354348
}
355349
};
@@ -361,8 +355,7 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
361355
expected,
362356
message,
363357
operator: 'notStrictEqual',
364-
stackStartFn: notStrictEqual,
365-
errorDiff: ERR_DIFF_NOT_EQUAL
358+
stackStartFn: notStrictEqual
366359
});
367360
}
368361
};
@@ -389,8 +382,7 @@ function compareExceptionKey(actual, expected, key, message, keys) {
389382
actual: a,
390383
expected: b,
391384
operator: 'deepStrictEqual',
392-
stackStartFn: assert.throws,
393-
errorDiff: ERR_DIFF_EQUAL
385+
stackStartFn: assert.throws
394386
});
395387
Error.stackTraceLimit = tmpLimit;
396388
message = err.message;

lib/internal/errors.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ class AssertionError extends Error {
395395
expected,
396396
message,
397397
operator,
398-
stackStartFn,
399-
errorDiff = 0
398+
stackStartFn
400399
} = options;
401400

402401
if (message != null) {
@@ -427,15 +426,10 @@ class AssertionError extends Error {
427426
expected = copyError(expected);
428427
}
429428

430-
if (errorDiff === 0) {
431-
let res = util.inspect(actual);
432-
let other = util.inspect(expected);
433-
if (res.length > 128)
434-
res = `${res.slice(0, 125)}...`;
435-
if (other.length > 128)
436-
other = `${other.slice(0, 125)}...`;
437-
super(`${res} ${operator} ${other}`);
438-
} else if (errorDiff === 1) {
429+
if (operator === 'deepStrictEqual' || operator === 'strictEqual') {
430+
super(createErrDiff(actual, expected, operator));
431+
} else if (operator === 'notDeepStrictEqual' ||
432+
operator === 'notStrictEqual') {
439433
// In case the objects are equal but the operator requires unequal, show
440434
// the first object and say A equals B
441435
const res = inspectValue(actual);
@@ -457,7 +451,13 @@ class AssertionError extends Error {
457451
super(`${base}\n\n ${res.join('\n ')}\n`);
458452
}
459453
} else {
460-
super(createErrDiff(actual, expected, operator));
454+
let res = util.inspect(actual);
455+
let other = util.inspect(expected);
456+
if (res.length > 128)
457+
res = `${res.slice(0, 125)}...`;
458+
if (other.length > 128)
459+
other = `${other.slice(0, 125)}...`;
460+
super(`${res} ${operator} ${other}`);
461461
}
462462
}
463463

0 commit comments

Comments
 (0)