mirror of https://github.com/lukechilds/node.git
Browse Source
The --redirect-warnings command line argument allows process warnings to be written to a specified file rather than printed to stderr. Also adds an equivalent NODE_REDIRECT_WARNINGS environment variable. If the specified file cannot be opened or written to for any reason, the argument is ignored and the warning is printed to stderr. If the file already exists, it will be appended to. Backport-PR-URL: https://github.com/nodejs/node/pull/12677 PR-URL: https://github.com/nodejs/node/pull/10116 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Michal Zasso <targos@protonmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>v6.x-staging
James M Snell
8 years ago
committed by
Myles Borins
8 changed files with 182 additions and 2 deletions
@ -0,0 +1,25 @@ |
|||
'use strict'; |
|||
|
|||
// Tests the NODE_REDIRECT_WARNINGS environment variable 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'); |
|||
const fs = require('fs'); |
|||
const fork = require('child_process').fork; |
|||
const path = require('path'); |
|||
const assert = require('assert'); |
|||
|
|||
common.refreshTmpDir(); |
|||
|
|||
const warnmod = require.resolve(common.fixturesDir + '/warnings.js'); |
|||
const warnpath = path.join(common.tmpDir, 'warnings.txt'); |
|||
|
|||
fork(warnmod, {env: {NODE_REDIRECT_WARNINGS: warnpath}}) |
|||
.on('exit', common.mustCall(() => { |
|||
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => { |
|||
assert.ifError(err); |
|||
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); |
|||
})); |
|||
})); |
@ -0,0 +1,25 @@ |
|||
'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'); |
|||
const fs = require('fs'); |
|||
const fork = require('child_process').fork; |
|||
const path = require('path'); |
|||
const assert = require('assert'); |
|||
|
|||
common.refreshTmpDir(); |
|||
|
|||
const warnmod = require.resolve(common.fixturesDir + '/warnings.js'); |
|||
const warnpath = path.join(common.tmpDir, 'warnings.txt'); |
|||
|
|||
fork(warnmod, {execArgv: [`--redirect-warnings=${warnpath}`]}) |
|||
.on('exit', common.mustCall(() => { |
|||
fs.readFile(warnpath, 'utf8', common.mustCall((err, data) => { |
|||
assert.ifError(err); |
|||
assert(/\(node:\d+\) Warning: a bad practice warning/.test(data)); |
|||
})); |
|||
})); |
Loading…
Reference in new issue