1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const { spawn } = require('child_process'); 6 7if (process.argv[2] !== 'child') { 8 // Expected error not emitted. 9 { 10 const child = spawn( 11 process.execPath, [__filename, 'child', 0], { encoding: 'utf8' } 12 ); 13 child.on('exit', common.mustCall((status) => { 14 assert.notStrictEqual(status, 0); 15 })); 16 } 17 18 // Expected error emitted. 19 { 20 const child = spawn( 21 process.execPath, [__filename, 'child', 1], { encoding: 'utf8' } 22 ); 23 child.on('exit', common.mustCall((status) => { 24 assert.strictEqual(status, 0); 25 })); 26 } 27 28 // Expected error emitted too many times. 29 { 30 const child = spawn( 31 process.execPath, [__filename, 'child', 2], { encoding: 'utf8' } 32 ); 33 child.stderr.setEncoding('utf8'); 34 35 let stderr = ''; 36 child.stderr.on('data', (data) => { 37 stderr += data; 38 }); 39 child.stderr.on('end', common.mustCall(() => { 40 assert.match(stderr, /Unexpected extra warning received/); 41 })); 42 child.on('exit', common.mustCall((status) => { 43 assert.notStrictEqual(status, 0); 44 })); 45 } 46} else { 47 const iterations = +process.argv[3]; 48 common.expectWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads'); 49 for (let i = 0; i < iterations; i++) { 50 process.emitWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads'); 51 } 52} 53