Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(fetch): allow custom implementation of AbortSignal #1608

Merged
merged 1 commit into from Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}
})