0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-child-process-execFile-promisified-abortController.js
Wassim Chegham eaadc4bd30 test: refactor code to use AbortSignal.abort()
PR-URL: https://github.com/nodejs/node/pull/37798
Refs: https://github.com/whatwg/dom/pull/960
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2021-03-20 19:21:13 +01:00

57 lines
1.4 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { promisify } = require('util');
const execFile = require('child_process').execFile;
const fixtures = require('../common/fixtures');
const echoFixture = fixtures.path('echo.js');
const promisified = promisify(execFile);
const invalidArgTypeError = {
code: 'ERR_INVALID_ARG_TYPE',
name: 'TypeError'
};
{
// Verify that the signal option works properly
const ac = new AbortController();
const signal = ac.signal;
const promise = promisified(process.execPath, [echoFixture, 0], { signal });
ac.abort();
assert.rejects(
promise,
{ name: 'AbortError' }
).then(common.mustCall());
}
{
// Verify that the signal option works properly when already aborted
const signal = AbortSignal.abort();
assert.rejects(
promisified(process.execPath, [echoFixture, 0], { signal }),
{ name: 'AbortError' }
).then(common.mustCall());
}
{
// Verify that if something different than Abortcontroller.signal
// is passed, ERR_INVALID_ARG_TYPE is thrown
const signal = {};
assert.throws(() => {
promisified(process.execPath, [echoFixture, 0], { signal });
}, invalidArgTypeError);
}
{
// Verify that if something different than Abortcontroller.signal
// is passed, ERR_INVALID_ARG_TYPE is thrown
const signal = 'world!';
assert.throws(() => {
promisified(process.execPath, [echoFixture, 0], { signal });
}, invalidArgTypeError);
}