Skip to content

Commit

Permalink
Don't freeze signal when freezing Options (#2100)
Browse files Browse the repository at this point in the history
  • Loading branch information
svvac committed Aug 5, 2022
1 parent f21632d commit 43b1467
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 0 additions & 1 deletion source/core/options.ts
Expand Up @@ -2521,6 +2521,5 @@ export default class Options {
Object.freeze(options.retry.methods);
Object.freeze(options.retry.statusCodes);
Object.freeze(options.context);
Object.freeze(options.signal);
}
}
13 changes: 13 additions & 0 deletions test/abort.ts
Expand Up @@ -271,4 +271,17 @@ if (globalThis.AbortController !== undefined) {
message: 'This operation was aborted.',
});
});

test('support setting the signal as a default option', async t => {
const controller = new AbortController();

const got2 = got.extend({signal: controller.signal});
const p = got2('http://example.com', {signal: controller.signal});
controller.abort();

await t.throwsAsync(p, {
code: 'ERR_ABORTED',
message: 'This operation was aborted.',
});
});
}
15 changes: 15 additions & 0 deletions test/normalize-arguments.ts
Expand Up @@ -167,3 +167,18 @@ test('searchParams - multiple values for one key', t => {
['100', '200', '300'],
);
});

if (globalThis.AbortSignal !== undefined) {
test('signal does not get frozen', t => {
const controller = new AbortController();
const {signal} = controller;

const options = new Options({
url: new URL('http://localhost'),
signal,
});
options.freeze();

t.is(Object.isFrozen(options.signal), false);
});
}

0 comments on commit 43b1467

Please sign in to comment.