Skip to content

Commit

Permalink
fix(fetch): allow custom implementation of AbortSignal (#1608)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 18, 2022
1 parent 5890e16 commit d83c1e2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/fetch/request.js
Expand Up @@ -835,10 +835,6 @@ webidl.converters.RequestInfo = function (V) {
return webidl.converters.USVString(V)
}

webidl.converters.AbortSignal = webidl.interfaceConverter(
AbortSignal
)

// https://fetch.spec.whatwg.org/#requestinit
webidl.converters.RequestInit = webidl.dictionaryConverter([
{
Expand Down Expand Up @@ -913,9 +909,7 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
},
{
key: 'signal',
converter: webidl.nullableConverter(
webidl.converters.AbortSignal
)
converter: webidl.converters.any
},
{
key: 'window',
Expand Down
30 changes: 30 additions & 0 deletions test/fetch/abort.js
Expand Up @@ -7,6 +7,8 @@ const { once } = require('events')
const { ReadableStream } = require('stream/web')
const { DOMException } = require('../../lib/fetch/constants')

const { AbortController: NPMAbortController } = require('abort-controller')

/* global AbortController */

test('parallel fetch with the same AbortController works as expected', async (t) => {
Expand Down Expand Up @@ -106,3 +108,31 @@ test('Readable stream synchronously cancels with AbortError if aborted before re

t.end()
})

test('Allow the usage of custom implementation of AbortController', async (t) => {
const body = {
fixes: 1605
}

const server = createServer((req, res) => {
res.statusCode = 200
res.end(JSON.stringify(body))
})

t.teardown(server.close.bind(server))

server.listen(0)
await once(server, 'listening')

const controller = new NPMAbortController()
const signal = controller.signal
controller.abort()

try {
await fetch(`http://localhost:${server.address().port}`, {
signal
})
} catch (e) {
t.equal(e.code, DOMException.ABORT_ERR)
}
})

0 comments on commit d83c1e2

Please sign in to comment.