mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
cli: add --watch
PR-URL: https://github.com/nodejs/node/pull/44366 Fixes: https://github.com/nodejs/node/issues/40429 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
1 parent
50a413183e
commit
beb0520af7
29 files changed
+954
-42
No files matched your search
@@ -21,15 +21,12 @@ const { inspect } = require('internal/util/inspect');
|
||||
const {
|
||||
removeColors,
|
||||
} = require('internal/util');
|
||||
const colors = require('internal/util/colors');
|
||||
const {
|
||||
validateObject,
|
||||
} = require('internal/validators');
|
||||
const { isErrorStackTraceLimitWritable } = require('internal/errors');
|
||||
|
||||
let blue = '';
|
||||
let green = '';
|
||||
let red = '';
|
||||
let white = '';
|
||||
|
||||
const kReadableOperator = {
|
||||
deepStrictEqual: 'Expected values to be strictly deep-equal:',
|
||||
@@ -169,7 +166,7 @@ function createErrDiff(actual, expected, operator) {
|
||||
// Only remove lines in case it makes sense to collapse those.
|
||||
// TODO: Accept env to always show the full error.
|
||||
if (actualLines.length > 50) {
|
||||
actualLines[46] = `${blue}...${white}`;
|
||||
actualLines[46] = `${colors.blue}...${colors.white}`;
|
||||
while (actualLines.length > 47) {
|
||||
ArrayPrototypePop(actualLines);
|
||||
}
|
||||
@@ -182,7 +179,7 @@ function createErrDiff(actual, expected, operator) {
|
||||
// There were at least five identical lines at the end. Mark a couple of
|
||||
// skipped.
|
||||
if (i >= 5) {
|
||||
end = `\n${blue}...${white}${end}`;
|
||||
end = `\n${colors.blue}...${colors.white}${end}`;
|
||||
skipped = true;
|
||||
}
|
||||
if (other !== '') {
|
||||
@@ -193,15 +190,15 @@ function createErrDiff(actual, expected, operator) {
|
||||
let printedLines = 0;
|
||||
let identical = 0;
|
||||
const msg = kReadableOperator[operator] +
|
||||
`\n${green}+ actual${white} ${red}- expected${white}`;
|
||||
const skippedMsg = ` ${blue}...${white} Lines skipped`;
|
||||
`\n${colors.green}+ actual${colors.white} ${colors.red}- expected${colors.white}`;
|
||||
const skippedMsg = ` ${colors.blue}...${colors.white} Lines skipped`;
|
||||
|
||||
let lines = actualLines;
|
||||
let plusMinus = `${green}+${white}`;
|
||||
let plusMinus = `${colors.green}+${colors.white}`;
|
||||
let maxLength = expectedLines.length;
|
||||
if (actualLines.length < maxLines) {
|
||||
lines = expectedLines;
|
||||
plusMinus = `${red}-${white}`;
|
||||
plusMinus = `${colors.red}-${colors.white}`;
|
||||
maxLength = actualLines.length;
|
||||
}
|
||||
|
||||
@@ -216,7 +213,7 @@ function createErrDiff(actual, expected, operator) {
|
||||
res += `\n ${lines[i - 3]}`;
|
||||
printedLines++;
|
||||
} else {
|
||||
res += `\n${blue}...${white}`;
|
||||
res += `\n${colors.blue}...${colors.white}`;
|
||||
skipped = true;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +269,7 @@ function createErrDiff(actual, expected, operator) {
|
||||
res += `\n ${actualLines[i - 3]}`;
|
||||
printedLines++;
|
||||
} else {
|
||||
res += `\n${blue}...${white}`;
|
||||
res += `\n${colors.blue}...${colors.white}`;
|
||||
skipped = true;
|
||||
}
|
||||
}
|
||||
@@ -286,8 +283,8 @@ function createErrDiff(actual, expected, operator) {
|
||||
identical = 0;
|
||||
// Add the actual line to the result and cache the expected diverging
|
||||
// line so consecutive diverging lines show up as +++--- and not +-+-+-.
|
||||
res += `\n${green}+${white} ${actualLine}`;
|
||||
other += `\n${red}-${white} ${expectedLine}`;
|
||||
res += `\n${colors.green}+${colors.white} ${actualLine}`;
|
||||
other += `\n${colors.red}-${colors.white} ${expectedLine}`;
|
||||
printedLines += 2;
|
||||
// Lines are identical
|
||||
} else {
|
||||
@@ -306,8 +303,8 @@ function createErrDiff(actual, expected, operator) {
|
||||
}
|
||||
// Inspected object to big (Show ~50 rows max)
|
||||
if (printedLines > 50 && i < maxLines - 2) {
|
||||
return `${msg}${skippedMsg}\n${res}\n${blue}...${white}${other}\n` +
|
||||
`${blue}...${white}`;
|
||||
return `${msg}${skippedMsg}\n${res}\n${colors.blue}...${colors.white}${other}\n` +
|
||||
`${colors.blue}...${colors.white}`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,21 +344,9 @@ class AssertionError extends Error {
|
||||
if (message != null) {
|
||||
super(String(message));
|
||||
} else {
|
||||
if (process.stderr.isTTY) {
|
||||
// Reset on each call to make sure we handle dynamically set environment
|
||||
// variables correct.
|
||||
if (process.stderr.hasColors()) {
|
||||
blue = '\u001b[34m';
|
||||
green = '\u001b[32m';
|
||||
white = '\u001b[39m';
|
||||
red = '\u001b[31m';
|
||||
} else {
|
||||
blue = '';
|
||||
green = '';
|
||||
white = '';
|
||||
red = '';
|
||||
}
|
||||
}
|
||||
// Reset colors on each call to make sure we handle dynamically set environment
|
||||
// variables correct.
|
||||
colors.refresh();
|
||||
// Prevent the error stack from being visible by duplicating the error
|
||||
// in a very close way to the original in case both sides are actually
|
||||
// instances of Error.
|
||||
@@ -393,7 +378,7 @@ class AssertionError extends Error {
|
||||
// Only remove lines in case it makes sense to collapse those.
|
||||
// TODO: Accept env to always show the full error.
|
||||
if (res.length > 50) {
|
||||
res[46] = `${blue}...${white}`;
|
||||
res[46] = `${colors.blue}...${colors.white}`;
|
||||
while (res.length > 47) {
|
||||
ArrayPrototypePop(res);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user