1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const cp = require('child_process'); 5 6if (process.argv[2] === 'child') { 7 process.emitWarning('foo'); 8} else { 9 function test(newEnv) { 10 const env = { ...process.env, ...newEnv }; 11 const cmd = `"${process.execPath}" "${__filename}" child`; 12 13 cp.exec(cmd, { env }, common.mustCall((err, stdout, stderr) => { 14 assert.strictEqual(err, null); 15 assert.strictEqual(stdout, ''); 16 17 if (env.NODE_NO_WARNINGS === '1') 18 assert.strictEqual(stderr, ''); 19 else 20 assert.match(stderr.trim(), /Warning: foo\n/); 21 })); 22 } 23 24 test({}); 25 test(process.env); 26 test({ NODE_NO_WARNINGS: undefined }); 27 test({ NODE_NO_WARNINGS: null }); 28 test({ NODE_NO_WARNINGS: 'foo' }); 29 test({ NODE_NO_WARNINGS: true }); 30 test({ NODE_NO_WARNINGS: false }); 31 test({ NODE_NO_WARNINGS: {} }); 32 test({ NODE_NO_WARNINGS: [] }); 33 test({ NODE_NO_WARNINGS: function() {} }); 34 test({ NODE_NO_WARNINGS: 0 }); 35 test({ NODE_NO_WARNINGS: -1 }); 36 test({ NODE_NO_WARNINGS: '0' }); 37 test({ NODE_NO_WARNINGS: '01' }); 38 test({ NODE_NO_WARNINGS: '2' }); 39 // Don't test the number 1 because it will come through as a string in the 40 // child process environment. 41 test({ NODE_NO_WARNINGS: '1' }); 42} 43