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