Skip to content

Commit 43b1467

Browse files
authoredAug 5, 2022
Don't freeze signal when freezing Options (#2100)
1 parent f21632d commit 43b1467

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed
 

‎source/core/options.ts

-1
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

+13
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

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

0 commit comments

Comments
 (0)
Please sign in to comment.