From baed55dea16f204af44e26a139637d21f7969df6 Mon Sep 17 00:00:00 2001 From: cgombauld Date: Tue, 21 Oct 2025 16:02:47 +0200 Subject: [PATCH] feat: add signal opt --- lib/index.js | 1 + test/index.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/index.js b/lib/index.js index 898c8125..91d450f2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -130,6 +130,7 @@ function regFetch (uri, /* istanbul ignore next */ opts_ = {}) { }, strictSSL: opts.strictSSL, timeout: opts.timeout || 30 * 1000, + signal: opts.signal, }).then(res => checkResponse({ method, uri, diff --git a/test/index.js b/test/index.js index f989ea4a..9747c642 100644 --- a/test/index.js +++ b/test/index.js @@ -450,3 +450,21 @@ t.test('miscellaneous headers not being set if not present in options', async t }) t.equal(res.status, 200, 'got successful response') }) + +t.test('opts.signal', async t => { + const controller = new AbortController() + const { signal } = controller + + controller.abort() + + try { + await fetch('/hello', { + ...OPTS, + signal, + }) + } catch (err) { + t.equal(err.name, 'AbortError') + return true + } + t.fail('should have thrown AbortError') +})