mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
04b4d15b39
Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
22 lines
676 B
JavaScript
22 lines
676 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const spawn = require('child_process').spawn;
|
|
|
|
if (process.argv[2] === 'child') {
|
|
process.stdin.resume();
|
|
process.stdin._handle.close();
|
|
process.stdin._handle.unref(); // Should not segfault.
|
|
process.stdin.on('error', common.mustCall(function(err) {}));
|
|
return;
|
|
}
|
|
|
|
// Use spawn so that we can be sure that stdin has a _handle property.
|
|
// Refs: https://github.com/nodejs/node/pull/5916
|
|
const proc = spawn(process.execPath, [__filename, 'child'], { stdio: 'pipe' });
|
|
|
|
proc.stderr.pipe(process.stderr);
|
|
proc.on('exit', common.mustCall(function(exitCode) {
|
|
if (exitCode !== 0)
|
|
process.exitCode = exitCode;
|
|
}));
|