Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup: address comment
  • Loading branch information
BridgeAR committed Jul 27, 2018
commit 511f8a1ebdce9b8c749c81c1625adb2d27501bc3
13 changes: 10 additions & 3 deletions lib/internal/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,25 @@ function createErrDiff(actual, expected, operator) {
let i = 0;
let indicator = '';

if (actualLines.length === 1 && expectedLines.length === 1) {
// If "actual" and "expected" fit on a single line and they are not strictly
// equal, check further special handling.
if (actualLines.length === 1 && expectedLines.length === 1 &&
actualLines[0] !== expectedLines[0]) {
const inputLength = actualLines[0].length + expectedLines[0].length;
// If the character length of "actual" and "expected" together is less than
// kMaxShortLength and if neither is an object and at least one of them is
// not `zero`, use the strict equal comparison to visualize the output.
if (inputLength <= kMaxShortLength) {
if ((typeof actual !== 'object' || actual === null) &&
(typeof expected !== 'object' || expected === null) &&
(actual !== 0 || expected !== 0)) { // -0 === +0
return `${kReadableOperator[operator]}:\n\n` +
`${actualLines[0]} !== ${expectedLines[0]}\n`;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a comment explaining this block of logic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// If the stdout is a tty and the input length is lower than the current
// columns per line, add a mismatch indicator below the output.
} else if (process.stdout.isTTY &&
inputLength < process.stdout.columns &&
actualLines[0] !== expectedLines[0]) {
inputLength < process.stdout.columns) {
while (actualLines[0][i] === expectedLines[0][i]) {
i++;
}
Expand Down