11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst { spawn } = require('child_process'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciif (process.argv[2] !== 'child') { 81cb0ef41Sopenharmony_ci // Expected error not emitted. 91cb0ef41Sopenharmony_ci { 101cb0ef41Sopenharmony_ci const child = spawn( 111cb0ef41Sopenharmony_ci process.execPath, [__filename, 'child', 0], { encoding: 'utf8' } 121cb0ef41Sopenharmony_ci ); 131cb0ef41Sopenharmony_ci child.on('exit', common.mustCall((status) => { 141cb0ef41Sopenharmony_ci assert.notStrictEqual(status, 0); 151cb0ef41Sopenharmony_ci })); 161cb0ef41Sopenharmony_ci } 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci // Expected error emitted. 191cb0ef41Sopenharmony_ci { 201cb0ef41Sopenharmony_ci const child = spawn( 211cb0ef41Sopenharmony_ci process.execPath, [__filename, 'child', 1], { encoding: 'utf8' } 221cb0ef41Sopenharmony_ci ); 231cb0ef41Sopenharmony_ci child.on('exit', common.mustCall((status) => { 241cb0ef41Sopenharmony_ci assert.strictEqual(status, 0); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci // Expected error emitted too many times. 291cb0ef41Sopenharmony_ci { 301cb0ef41Sopenharmony_ci const child = spawn( 311cb0ef41Sopenharmony_ci process.execPath, [__filename, 'child', 2], { encoding: 'utf8' } 321cb0ef41Sopenharmony_ci ); 331cb0ef41Sopenharmony_ci child.stderr.setEncoding('utf8'); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ci let stderr = ''; 361cb0ef41Sopenharmony_ci child.stderr.on('data', (data) => { 371cb0ef41Sopenharmony_ci stderr += data; 381cb0ef41Sopenharmony_ci }); 391cb0ef41Sopenharmony_ci child.stderr.on('end', common.mustCall(() => { 401cb0ef41Sopenharmony_ci assert.match(stderr, /Unexpected extra warning received/); 411cb0ef41Sopenharmony_ci })); 421cb0ef41Sopenharmony_ci child.on('exit', common.mustCall((status) => { 431cb0ef41Sopenharmony_ci assert.notStrictEqual(status, 0); 441cb0ef41Sopenharmony_ci })); 451cb0ef41Sopenharmony_ci } 461cb0ef41Sopenharmony_ci} else { 471cb0ef41Sopenharmony_ci const iterations = +process.argv[3]; 481cb0ef41Sopenharmony_ci common.expectWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads'); 491cb0ef41Sopenharmony_ci for (let i = 0; i < iterations; i++) { 501cb0ef41Sopenharmony_ci process.emitWarning('fhqwhgads', 'fhqwhgads', 'fhqwhgads'); 511cb0ef41Sopenharmony_ci } 521cb0ef41Sopenharmony_ci} 53