Skip to content

Commit 077d903

Browse files
committed
Don't freeze signal when freezing Options (sindresorhus#2099)
1 parent e032b60 commit 077d903

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

source/core/options.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,5 @@ export default class Options {
25212521
Object.freeze(options.retry.methods);
25222522
Object.freeze(options.retry.statusCodes);
25232523
Object.freeze(options.context);
2524-
Object.freeze(options.signal);
25252524
}
25262525
}

test/abort.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,17 @@ if (globalThis.AbortController !== undefined) {
271271
message: 'This operation was aborted.',
272272
});
273273
});
274+
275+
test('support setting the signal as a default option', async t => {
276+
const controller = new AbortController();
277+
278+
const got2 = got.extend({signal: controller.signal});
279+
const p = got2('http://example.com', {signal: controller.signal});
280+
controller.abort();
281+
282+
await t.throwsAsync(p, {
283+
code: 'ERR_ABORTED',
284+
message: 'This operation was aborted.',
285+
});
286+
});
274287
}

test/normalize-arguments.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {URL, URLSearchParams} from 'url';
2+
import {EventEmitter} from 'events';
23
import test from 'ava';
34
import got, {Options} from '../source/index.js';
45

@@ -167,3 +168,18 @@ test('searchParams - multiple values for one key', t => {
167168
['100', '200', '300'],
168169
);
169170
});
171+
172+
if (globalThis.AbortSignal !== undefined) {
173+
test('signal does not get frozen', t => {
174+
const controller = new AbortController();
175+
const {signal} = controller;
176+
177+
const options = new Options({
178+
url: new URL('http://localhost'),
179+
signal,
180+
});
181+
options.freeze();
182+
183+
t.is(Object.isFrozen(options.signal), false);
184+
});
185+
}

0 commit comments

Comments
 (0)