Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't freeze signal when freezing Options #2100

Merged
merged 2 commits into from Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.',
});
});
}
16 changes: 16 additions & 0 deletions test/normalize-arguments.ts
@@ -1,4 +1,5 @@
import {URL, URLSearchParams} from 'url';
import {EventEmitter} from 'events';
svvac marked this conversation as resolved.
Show resolved Hide resolved
import test from 'ava';
import got, {Options} from '../source/index.js';

Expand Down Expand Up @@ -167,3 +168,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);
});
}