mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00

This change removes `common.noop` from the Node.js internal testing common module. Over the last few weeks, I've grown to dislike the `common.noop` abstraction. First, new (and experienced) contributors are unaware of it and so it results in a large number of low-value nits on PRs. It also increases the number of things newcomers and infrequent contributors have to be aware of to be effective on the project. Second, it is confusing. Is it a singleton/property or a getter? Which should be expected? This can lead to subtle and hard-to-find bugs. (To my knowledge, none have landed on master. But I also think it's only a matter of time.) Third, the abstraction is low-value in my opinion. What does it really get us? A case could me made that it is without value at all. Lastly, and this is minor, but the abstraction is wordier than not using the abstraction. `common.noop` doesn't save anything over `() => {}`. So, I propose removing it. PR-URL: https://github.com/nodejs/node/pull/12822 Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com>
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
'use strict';
|
|
// Flags: --expose_internals
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cp = require('child_process');
|
|
|
|
if (process.argv[2] === 'child') {
|
|
setTimeout(() => {}, common.platformTimeout(100));
|
|
return;
|
|
}
|
|
|
|
// Monkey patch spawn() to create a child process normally, but destroy the
|
|
// stdout and stderr streams. This replicates the conditions where the streams
|
|
// cannot be properly created.
|
|
const ChildProcess = require('internal/child_process').ChildProcess;
|
|
const original = ChildProcess.prototype.spawn;
|
|
|
|
ChildProcess.prototype.spawn = function() {
|
|
const err = original.apply(this, arguments);
|
|
|
|
this.stdout.destroy();
|
|
this.stderr.destroy();
|
|
this.stdout = null;
|
|
this.stderr = null;
|
|
|
|
return err;
|
|
};
|
|
|
|
function createChild(options, callback) {
|
|
const cmd = `"${process.execPath}" "${__filename}" child`;
|
|
|
|
return cp.exec(cmd, options, common.mustCall(callback));
|
|
}
|
|
|
|
// Verify that normal execution of a child process is handled.
|
|
{
|
|
createChild({}, (err, stdout, stderr) => {
|
|
assert.strictEqual(err, null);
|
|
assert.strictEqual(stdout, '');
|
|
assert.strictEqual(stderr, '');
|
|
});
|
|
}
|
|
|
|
// Verify that execution with an error event is handled.
|
|
{
|
|
const error = new Error('foo');
|
|
const child = createChild({}, (err, stdout, stderr) => {
|
|
assert.strictEqual(err, error);
|
|
assert.strictEqual(stdout, '');
|
|
assert.strictEqual(stderr, '');
|
|
});
|
|
|
|
child.emit('error', error);
|
|
}
|
|
|
|
// Verify that execution with a killed process is handled.
|
|
{
|
|
createChild({ timeout: 1 }, (err, stdout, stderr) => {
|
|
assert.strictEqual(err.killed, true);
|
|
assert.strictEqual(stdout, '');
|
|
assert.strictEqual(stderr, '');
|
|
});
|
|
}
|