Skip to content

Commit d8074d6

Browse files
authored
feat: add signal opt (#280)
Pass opts.signal to fetch ## References Closes #276
1 parent a50fb07 commit d8074d6

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) {
130130
},
131131
strictSSL: opts.strictSSL,
132132
timeout: opts.timeout || 30 * 1000,
133+
signal: opts.signal,
133134
}).then(res => checkResponse({
134135
method,
135136
uri,

test/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,21 @@ t.test('miscellaneous headers not being set if not present in options', async t
450450
})
451451
t.equal(res.status, 200, 'got successful response')
452452
})
453+
454+
t.test('opts.signal', async t => {
455+
const controller = new AbortController()
456+
const { signal } = controller
457+
458+
controller.abort()
459+
460+
try {
461+
await fetch('/hello', {
462+
...OPTS,
463+
signal,
464+
})
465+
} catch (err) {
466+
t.equal(err.name, 'AbortError')
467+
return true
468+
}
469+
t.fail('should have thrown AbortError')
470+
})

0 commit comments

Comments
 (0)