2016-12-04 18:38:35 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Tests the --redirect-warnings command line flag by spawning
|
|
|
|
// a new child node process that emits a warning into a temporary
|
|
|
|
// warnings file. Once the process completes, the warning file is
|
|
|
|
// opened and the contents are validated
|
|
|
|
|
|
|
|
const common = require('../common');
|
2017-10-06 17:17:00 +00:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-12-04 18:38:35 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const fork = require('child_process').fork;
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2017-12-25 06:38:11 +00:00
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
tmpdir.refresh();
|
2016-12-04 18:38:35 +00:00
|
|
|
|
2017-10-06 17:17:00 +00:00
|
|
|
const warnmod = fixtures.path('warnings.js');
|
2023-08-15 13:45:44 +00:00
|
|
|
const warnpath = tmpdir.resolve('warnings.txt');
|
2016-12-04 18:38:35 +00:00
|
|
|
|
2017-07-11 00:55:21 +00:00
|
|
|
fork(warnmod, { execArgv: [`--redirect-warnings=${warnpath}`] })
|
2016-12-04 18:38:35 +00:00
|
|
|
.on('exit', common.mustCall(() => {
|
2020-09-06 20:27:07 +00:00
|
|
|
fs.readFile(warnpath, 'utf8', common.mustSucceed((data) => {
|
2021-08-29 08:14:22 +00:00
|
|
|
assert.match(data, /\(node:\d+\) Warning: a bad practice warning/);
|
2016-12-04 18:38:35 +00:00
|
|
|
}));
|
|
|
|
}));
|