test: add already-aborted-controller test for spawn()

PR-URL: https://github.com/nodejs/node/pull/36644
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
This commit is contained in:
Rich Trott 2020-12-28 18:29:30 -08:00
parent 36394b6782
commit 37acaf668d

View File

@ -4,18 +4,38 @@ const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
// Verify that passing an AbortSignal works
const controller = new AbortController();
const { signal } = controller;
{
// Verify that passing an AbortSignal works
const controller = new AbortController();
const { signal } = controller;
const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});
const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});
echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));
echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));
controller.abort();
controller.abort();
}
{
// Verify that passing an already-aborted signal works.
const controller = new AbortController();
const { signal } = controller;
controller.abort();
const echo = cp.spawn('echo', ['fun'], {
encoding: 'utf8',
shell: true,
signal
});
echo.on('error', common.mustCall((e) => {
assert.strictEqual(e.name, 'AbortError');
}));
}