1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const { promisify } = require('util');
6const execFile = require('child_process').execFile;
7const fixtures = require('../common/fixtures');
8
9const echoFixture = fixtures.path('echo.js');
10const promisified = promisify(execFile);
11const invalidArgTypeError = {
12  code: 'ERR_INVALID_ARG_TYPE',
13  name: 'TypeError'
14};
15
16{
17  // Verify that the signal option works properly
18  const ac = new AbortController();
19  const signal = ac.signal;
20  const promise = promisified(process.execPath, [echoFixture, 0], { signal });
21
22  ac.abort();
23
24  assert.rejects(
25    promise,
26    { name: 'AbortError' }
27  ).then(common.mustCall());
28}
29
30{
31  // Verify that the signal option works properly when already aborted
32  const signal = AbortSignal.abort();
33
34  assert.rejects(
35    promisified(process.execPath, [echoFixture, 0], { signal }),
36    { name: 'AbortError' }
37  ).then(common.mustCall());
38}
39
40{
41  // Verify that if something different than Abortcontroller.signal
42  // is passed, ERR_INVALID_ARG_TYPE is thrown
43  const signal = {};
44  assert.throws(() => {
45    promisified(process.execPath, [echoFixture, 0], { signal });
46  }, invalidArgTypeError);
47}
48
49{
50  // Verify that if something different than Abortcontroller.signal
51  // is passed, ERR_INVALID_ARG_TYPE is thrown
52  const signal = 'world!';
53  assert.throws(() => {
54    promisified(process.execPath, [echoFixture, 0], { signal });
55  }, invalidArgTypeError);
56}
57