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: use stderr instead of stdout
  • Loading branch information
BridgeAR committed Jul 27, 2018
commit 4587e5d6161be8c5a2967f5acf46bca4c9b4331d
11 changes: 6 additions & 5 deletions lib/internal/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ function createErrDiff(actual, expected, operator) {
`${actualLines[0]} !== ${expectedLines[0]}\n`;
}
Copy link
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done.

} else {
// If the stdout is a tty and the input length is lower than the current
// If the stderr is a tty and the input length is lower than the current
// columns per line, add a mismatch indicator below the output. If it is
// not a tty, use a default value of 80 characters.
const maxLength = process.stdout.isTTY ? process.stdout.columns : 80;
const maxLength = process.stderr.isTTY ? process.stderr.columns : 80;
if (inputLength < maxLength) {
while (actualLines[0][i] === expectedLines[0][i]) {
i++;
}
if (i !== 0) {
// Ignore the first characters.
if (i > 2) {
// Add position indicator for the first mismatch in case it is a
// single line and the input length is less than the column length.
indicator = `\n ${' '.repeat(i)}^`;
Expand Down Expand Up @@ -235,10 +236,10 @@ class AssertionError extends Error {
if (message != null) {
super(String(message));
} else {
if (process.stdout.isTTY) {
if (process.stderr.isTTY) {
// Reset on each call to make sure we handle dynamically set environment
// variables correct.
if (process.stdout.getColorDepth() !== 1) {
if (process.stderr.getColorDepth() !== 1) {
blue = '\u001b[34m';
green = '\u001b[32m';
white = '\u001b[39m';
Expand Down