node/test/sequential/test-process-warnings.js
Michaël Zasso 508890d795
test: use assert.match instead of regexp.test
PR-URL: https://github.com/nodejs/node/pull/39928
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
2021-08-31 18:50:16 +02:00

37 lines
1.1 KiB
JavaScript

'use strict';
require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
const execFile = require('child_process').execFile;
const warnmod = require.resolve(fixtures.path('warnings.js'));
const node = process.execPath;
const normal = [warnmod];
const noWarn = ['--no-warnings', warnmod];
const traceWarn = ['--trace-warnings', warnmod];
const warningMessage = /^\(.+\)\sWarning: a bad practice warning/;
execFile(node, normal, function(er, stdout, stderr) {
// Show Process Warnings
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.match(stderr, warningMessage);
});
execFile(node, noWarn, function(er, stdout, stderr) {
// Hide Process Warnings
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.doesNotMatch(stderr, warningMessage);
});
execFile(node, traceWarn, function(er, stdout, stderr) {
// Show Warning Trace
assert.strictEqual(er, null);
assert.strictEqual(stdout, '');
assert.match(stderr, warningMessage);
assert.match(stderr, /at Object\.<anonymous>\s\(.+warnings\.js:3:9\)/);
});