test: improve test-debug-usage

test-debug-usage fails if run with `--trace-warnings` because the
regular expression checking does not allow for the resulting stack trace
from the deprecation warning.

The test also only tests two parts of the three-part usage message.

Improve the test so that it passes with `--trace-warnings` and verifies
all three parts of the usage message.

Signed-off-by: Rich Trott <rtrott@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/32141
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Rich Trott 2020-03-07 17:04:15 -08:00
parent 192cb7288a
commit 66e32ff64a

View File

@ -11,8 +11,7 @@ child.stderr.setEncoding('utf8');
const expectedLines = [
/^\(node:\d+\) \[DEP0068\] DeprecationWarning:/,
/^Usage: .*node.* debug script\.js$/,
/^ .*node.* debug <host>:<port>$/
/Usage: .*node.* debug script\.js\r?\n .*node.* debug <host>:<port>\r?\n .*node.* debug -p <pid>\r?\n$/,
];
let actualUsageMessage = '';
@ -21,11 +20,10 @@ child.stderr.on('data', function(data) {
});
child.on('exit', common.mustCall(function(code) {
const outputLines = actualUsageMessage.split('\n');
assert.strictEqual(code, 1);
for (let i = 0; i < expectedLines.length; i++)
assert.ok(
expectedLines[i].test(outputLines[i]),
`${outputLines[i]} did not match ${expectedLines[i]}`
expectedLines[i].test(actualUsageMessage),
`${actualUsageMessage} did not match ${expectedLines[i]}`
);
}));