nodejs/test/parallel/test-debug-usage.js
Rich Trott 66e32ff64a 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>
2020-03-09 19:46:12 -07:00

30 lines
858 B
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const spawn = require('child_process').spawn;
const child = spawn(process.execPath, ['debug']);
child.stderr.setEncoding('utf8');
const expectedLines = [
/^\(node:\d+\) \[DEP0068\] DeprecationWarning:/,
/Usage: .*node.* debug script\.js\r?\n .*node.* debug <host>:<port>\r?\n .*node.* debug -p <pid>\r?\n$/,
];
let actualUsageMessage = '';
child.stderr.on('data', function(data) {
actualUsageMessage += data.toString();
});
child.on('exit', common.mustCall(function(code) {
assert.strictEqual(code, 1);
for (let i = 0; i < expectedLines.length; i++)
assert.ok(
expectedLines[i].test(actualUsageMessage),
`${actualUsageMessage} did not match ${expectedLines[i]}`
);
}));