chore: use AbortSignal instead of AbortController (#10048)

This commit is contained in:
jrandolf 2023-04-20 08:18:48 +02:00 committed by GitHub
parent 5547e43829
commit bbf2c0a8ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 20 deletions

View File

@ -13,8 +13,8 @@ export interface WaitForSelectorOptions
## Properties
| Property | Modifiers | Type | Description | Default |
| --------------- | --------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
| abortController | <code>optional</code> | AbortController | Provide an abort controller to cancel a waitForSelector call. | |
| -------- | --------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------- |
| hidden | <code>optional</code> | boolean | Wait for the selected element to not be found in the DOM or to be hidden, i.e. have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |
| signal | <code>optional</code> | AbortSignal | A signal object that allows you to cancel a waitForSelector call. | |
| timeout | <code>optional</code> | number | <p>Maximum time to wait in milliseconds. Pass <code>0</code> to disable timeout.</p><p>The default value can be changed by using [Page.setDefaultTimeout()](./puppeteer.page.setdefaulttimeout.md)</p> | <code>30_000</code> (30 seconds) |
| visible | <code>optional</code> | boolean | Wait for the selected element to be present in DOM and to be visible, i.e. to not have <code>display: none</code> or <code>visibility: hidden</code> CSS properties. | <code>false</code> |

View File

@ -73,9 +73,9 @@ export interface WaitForSelectorOptions {
*/
timeout?: number;
/**
* Provide an abort controller to cancel a waitForSelector call.
* A signal object that allows you to cancel a waitForSelector call.
*/
abortController?: AbortController;
signal?: AbortSignal;
}
/**
@ -435,7 +435,7 @@ export class IsolatedWorld {
polling?: 'raf' | 'mutation' | number;
timeout?: number;
root?: ElementHandle<Node>;
abortController?: AbortController;
signal?: AbortSignal;
} = {},
...args: Params
): Promise<HandleFor<Awaited<ReturnType<Func>>>> {
@ -443,7 +443,7 @@ export class IsolatedWorld {
polling = 'raf',
timeout = this.#timeoutSettings.timeout(),
root,
abortController,
signal,
} = options;
if (typeof polling === 'number' && polling < 0) {
throw new Error('Cannot poll with non-positive interval');
@ -454,7 +454,7 @@ export class IsolatedWorld {
polling,
root,
timeout,
abortController,
signal,
},
pageFunction as unknown as
| ((...args: unknown[]) => Promise<Awaited<ReturnType<Func>>>)

View File

@ -167,10 +167,10 @@ export class QueryHandler {
element = await frame.worlds[PUPPETEER_WORLD].adoptHandle(elementOrFrame);
}
const {visible = false, hidden = false, timeout, abortController} = options;
const {visible = false, hidden = false, timeout, signal} = options;
try {
if (options.abortController?.signal.aborted) {
if (signal?.aborted) {
throw new AbortError('QueryHander.waitFor has been aborted.');
}
@ -190,7 +190,7 @@ export class QueryHandler {
polling: visible || hidden ? 'raf' : 'mutation',
root: element,
timeout,
abortController,
signal,
},
LazyArg.create(context => {
return context.puppeteerUtil;
@ -201,7 +201,7 @@ export class QueryHandler {
visible ? true : hidden ? false : undefined
);
if (options.abortController?.signal.aborted) {
if (signal?.aborted) {
await handle.dispose();
throw new AbortError('QueryHander.waitFor has been aborted.');
}

View File

@ -32,7 +32,7 @@ export interface WaitTaskOptions {
polling: 'raf' | 'mutation' | number;
root?: ElementHandle<Node>;
timeout: number;
abortController?: AbortController;
signal?: AbortSignal;
}
/**
@ -51,7 +51,7 @@ export class WaitTask<T = unknown> {
#result = createDeferredPromise<HandleFor<T>>();
#poller?: JSHandle<Poller<T>>;
#abortController?: AbortController;
#signal?: AbortSignal;
constructor(
world: IsolatedWorld,
@ -62,8 +62,8 @@ export class WaitTask<T = unknown> {
this.#world = world;
this.#polling = options.polling;
this.#root = options.root;
this.#abortController = options.abortController;
this.#abortController?.signal?.addEventListener(
this.#signal = options.signal;
this.#signal?.addEventListener(
'abort',
() => {
this.terminate(new AbortError('WaitTask has been aborted.'));

View File

@ -386,7 +386,7 @@ describe('waittask specs', function () {
await page.goto(server.EMPTY_PAGE);
const abortController = new AbortController();
const task = page.waitForSelector('wrong', {
abortController,
signal: abortController.signal,
});
abortController.abort();
expect(task).rejects.toThrow(/aborted/);