From 1358b45fcaf93538c2f613f5cd22501e08650034 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Mon, 27 Apr 2020 10:03:33 +0100 Subject: [PATCH] chore: migrate src/LifecycleWatcher (#5734) --- docs/api.md | 18 +-- src/DOMWorld.js | 2 +- src/FrameManager.js | 10 +- ...ifecycleWatcher.js => LifecycleWatcher.ts} | 120 ++++++++---------- src/Page.js | 14 +- src/externs.d.ts | 6 + utils/doclint/check_public_api/index.js | 36 ++++++ utils/doclint/generate_types/index.js | 17 +++ 8 files changed, 137 insertions(+), 86 deletions(-) rename src/{LifecycleWatcher.js => LifecycleWatcher.ts} (68%) diff --git a/docs/api.md b/docs/api.md index 572a36eb..b22a4d9d 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1554,7 +1554,7 @@ Shortcut for [page.mainFrame().focus(selector)](#framefocusselector). #### page.goBack([options]) - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -1567,7 +1567,7 @@ Navigate to the previous page in history. #### page.goForward([options]) - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -1581,7 +1581,7 @@ Navigate to the next page in history. - `url` <[string]> URL to navigate page to. The url should include scheme, e.g. `https://`. - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -1742,7 +1742,7 @@ Shortcut for [page.mainFrame().executionContext().queryObjects(prototypeHandle)] #### page.reload([options]) - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -1800,7 +1800,7 @@ Toggles ignoring cache for each request based on the enabled state. By default, - `html` <[string]> HTML markup to assign to the page. - `options` <[Object]> Parameters which might have the following properties: - `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `load` - consider setting content to be finished when the `load` event is fired. - `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms. @@ -2101,7 +2101,7 @@ Shortcut for [page.mainFrame().waitForFunction(pageFunction[, options[, ...args] #### page.waitForNavigation([options]) - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -2804,7 +2804,7 @@ If there's no element matching `selector`, the method throws an error. - `url` <[string]> URL to navigate frame to. The url should include scheme, e.g. `https://`. - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. @@ -2867,7 +2867,7 @@ frame.select('select#colors', 'red', 'green', 'blue'); // multiple selections - `html` <[string]> HTML markup to assign to the page. - `options` <[Object]> Parameters which might have the following properties: - `timeout` <[number]> Maximum time in milliseconds for resources to load, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider setting markup succeeded, defaults to `load`. Given an array of event strings, setting content is considered to be successful after all events have been fired. Events can be either: - `load` - consider setting content to be finished when the `load` event is fired. - `domcontentloaded` - consider setting content to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider setting content to be finished when there are no more than 0 network connections for at least `500` ms. @@ -2968,7 +2968,7 @@ await page.waitForFunction(selector => !!document.querySelector(selector), {}, s #### frame.waitForNavigation([options]) - `options` <[Object]> Navigation parameters which might have the following properties: - `timeout` <[number]> Maximum navigation time in milliseconds, defaults to 30 seconds, pass `0` to disable timeout. The default value can be changed by using the [page.setDefaultNavigationTimeout(timeout)](#pagesetdefaultnavigationtimeouttimeout) or [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout) methods. - - `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: + - `waitUntil` <"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either: - `load` - consider navigation to be finished when the `load` event is fired. - `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired. - `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms. diff --git a/src/DOMWorld.js b/src/DOMWorld.js index 33c093d2..40580546 100644 --- a/src/DOMWorld.js +++ b/src/DOMWorld.js @@ -205,7 +205,7 @@ class DOMWorld { /** * @param {string} html - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options */ async setContent(html, options = {}) { const { diff --git a/src/FrameManager.js b/src/FrameManager.js index dd9ae1db..35ebbda0 100644 --- a/src/FrameManager.js +++ b/src/FrameManager.js @@ -89,7 +89,7 @@ class FrameManager extends EventEmitter { /** * @param {!Puppeteer.Frame} frame * @param {string} url - * @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async navigateFrame(frame, url, options = {}) { @@ -137,7 +137,7 @@ class FrameManager extends EventEmitter { /** * @param {!Puppeteer.Frame} frame - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async waitForFrameNavigation(frame, options = {}) { @@ -410,7 +410,7 @@ class Frame { /** * @param {string} url - * @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async goto(url, options) { @@ -418,7 +418,7 @@ class Frame { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async waitForNavigation(options) { @@ -503,7 +503,7 @@ class Frame { /** * @param {string} html - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options */ async setContent(html, options = {}) { return this._secondaryWorld.setContent(html, options); diff --git a/src/LifecycleWatcher.js b/src/LifecycleWatcher.ts similarity index 68% rename from src/LifecycleWatcher.js rename to src/LifecycleWatcher.ts index ab997e59..d830ba1b 100644 --- a/src/LifecycleWatcher.js +++ b/src/LifecycleWatcher.ts @@ -14,18 +14,49 @@ * limitations under the License. */ -const {helper, assert} = require('./helper'); -const {Events} = require('./Events'); -const {TimeoutError} = require('./Errors'); +import {helper, assert, PuppeteerEventListener} from './helper'; +import {Events} from './Events'; +import {TimeoutError} from './Errors'; -class LifecycleWatcher { - /** - * @param {!Puppeteer.FrameManager} frameManager - * @param {!Puppeteer.Frame} frame - * @param {string|!Array} waitUntil - * @param {number} timeout - */ - constructor(frameManager, frame, waitUntil, timeout) { +type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; +type ProtocolLifeCycleEvent = 'load' | 'DOMContentLoaded' | 'networkIdle' | 'networkAlmostIdle'; + +const puppeteerToProtocolLifecycle = new Map([ + ['load', 'load'], + ['domcontentloaded', 'DOMContentLoaded'], + ['networkidle0', 'networkIdle'], + ['networkidle2', 'networkAlmostIdle'], +]); + + +export class LifecycleWatcher { + _expectedLifecycle: ProtocolLifeCycleEvent[]; + _frameManager: Puppeteer.FrameManager; + _frame: Puppeteer.Frame; + _timeout: number; + _navigationRequest?: Puppeteer.Request; + _eventListeners: PuppeteerEventListener[]; + _initialLoaderId: string; + + + _sameDocumentNavigationPromise: Promise; + _sameDocumentNavigationCompleteCallback: (x?: Error) => void; + + _lifecyclePromise: Promise; + _lifecycleCallback: () => void; + + _newDocumentNavigationPromise: Promise; + _newDocumentNavigationCompleteCallback: (x?: Error) => void; + + _terminationPromise: Promise; + _terminationCallback: (x?: Error) => void; + + _timeoutPromise: Promise; + + _maximumTimer?: NodeJS.Timeout; + _hasSameDocumentNavigation?: boolean; + + constructor(frameManager: Puppeteer.FrameManager, frame: Puppeteer.Frame, waitUntil: PuppeteerLifeCycleEvent|PuppeteerLifeCycleEvent[], timeout: number) { if (Array.isArray(waitUntil)) waitUntil = waitUntil.slice(); else if (typeof waitUntil === 'string') @@ -50,7 +81,7 @@ class LifecycleWatcher { helper.addEventListener(this._frameManager.networkManager(), Events.NetworkManager.Request, this._onRequest.bind(this)), ]; - this._sameDocumentNavigationPromise = new Promise(fulfill => { + this._sameDocumentNavigationPromise = new Promise(fulfill => { this._sameDocumentNavigationCompleteCallback = fulfill; }); @@ -69,19 +100,13 @@ class LifecycleWatcher { this._checkLifecycleComplete(); } - /** - * @param {!Puppeteer.Request} request - */ - _onRequest(request) { + _onRequest(request: Puppeteer.Request): void { if (request.frame() !== this._frame || !request.isNavigationRequest()) return; this._navigationRequest = request; } - /** - * @param {!Puppeteer.Frame} frame - */ - _onFrameDetached(frame) { + _onFrameDetached(frame: Puppeteer.Frame): void { if (this._frame === frame) { this._terminationCallback.call(null, new Error('Navigating frame was detached')); return; @@ -89,52 +114,31 @@ class LifecycleWatcher { this._checkLifecycleComplete(); } - /** - * @return {?Puppeteer.Response} - */ - navigationResponse() { + navigationResponse(): Puppeteer.Response | null { return this._navigationRequest ? this._navigationRequest.response() : null; } - /** - * @param {!Error} error - */ - _terminate(error) { + _terminate(error: Error): void { this._terminationCallback.call(null, error); } - /** - * @return {!Promise} - */ - sameDocumentNavigationPromise() { + sameDocumentNavigationPromise(): Promise { return this._sameDocumentNavigationPromise; } - /** - * @return {!Promise} - */ - newDocumentNavigationPromise() { + newDocumentNavigationPromise(): Promise { return this._newDocumentNavigationPromise; } - /** - * @return {!Promise} - */ - lifecyclePromise() { + lifecyclePromise(): Promise { return this._lifecyclePromise; } - /** - * @return {!Promise} - */ - timeoutOrTerminationPromise() { + timeoutOrTerminationPromise(): Promise { return Promise.race([this._timeoutPromise, this._terminationPromise]); } - /** - * @return {!Promise} - */ - _createTimeoutPromise() { + _createTimeoutPromise(): Promise { if (!this._timeout) return new Promise(() => {}); const errorMessage = 'Navigation timeout of ' + this._timeout + ' ms exceeded'; @@ -142,17 +146,14 @@ class LifecycleWatcher { .then(() => new TimeoutError(errorMessage)); } - /** - * @param {!Puppeteer.Frame} frame - */ - _navigatedWithinDocument(frame) { + _navigatedWithinDocument(frame: Puppeteer.Frame): void { if (frame !== this._frame) return; this._hasSameDocumentNavigation = true; this._checkLifecycleComplete(); } - _checkLifecycleComplete() { + _checkLifecycleComplete(): void { // We expect navigation to commit. if (!checkLifecycle(this._frame, this._expectedLifecycle)) return; @@ -169,7 +170,7 @@ class LifecycleWatcher { * @param {!Array} expectedLifecycle * @return {boolean} */ - function checkLifecycle(frame, expectedLifecycle) { + function checkLifecycle(frame: Puppeteer.Frame, expectedLifecycle: ProtocolLifeCycleEvent[]): boolean { for (const event of expectedLifecycle) { if (!frame._lifecycleEvents.has(event)) return false; @@ -182,17 +183,8 @@ class LifecycleWatcher { } } - dispose() { + dispose(): void { helper.removeEventListeners(this._eventListeners); clearTimeout(this._maximumTimer); } } - -const puppeteerToProtocolLifecycle = new Map([ - ['load', 'load'], - ['domcontentloaded', 'DOMContentLoaded'], - ['networkidle0', 'networkIdle'], - ['networkidle2', 'networkAlmostIdle'], -]); - -module.exports = {LifecycleWatcher}; diff --git a/src/Page.js b/src/Page.js index 77e0e564..f1382a5b 100644 --- a/src/Page.js +++ b/src/Page.js @@ -675,7 +675,7 @@ class Page extends EventEmitter { /** * @param {string} html - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options */ async setContent(html, options) { await this._frameManager.mainFrame().setContent(html, options); @@ -683,7 +683,7 @@ class Page extends EventEmitter { /** * @param {string} url - * @param {!{referer?: string, timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{referer?: string, timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async goto(url, options) { @@ -691,7 +691,7 @@ class Page extends EventEmitter { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async reload(options) { @@ -705,7 +705,7 @@ class Page extends EventEmitter { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async waitForNavigation(options = {}) { @@ -755,7 +755,7 @@ class Page extends EventEmitter { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async goBack(options) { @@ -763,7 +763,7 @@ class Page extends EventEmitter { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async goForward(options) { @@ -771,7 +771,7 @@ class Page extends EventEmitter { } /** - * @param {!{timeout?: number, waitUntil?: string|!Array}=} options + * @param {!{timeout?: number, waitUntil?: !Puppeteer.PuppeteerLifeCycleEvent|!Array}=} options * @return {!Promise} */ async _go(delta, options) { diff --git a/src/externs.d.ts b/src/externs.d.ts index 78ee12ea..0fa4f3c5 100644 --- a/src/externs.d.ts +++ b/src/externs.d.ts @@ -18,6 +18,12 @@ declare global { export class Response extends RealResponse { } export class Request extends RealRequest { } + + /* TODO(jacktfranklin@): once DOMWorld, Page, and FrameManager are in TS + * we can remove this and instead use the type defined in LifeCycleWatcher + */ + export type PuppeteerLifeCycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; + export interface ConnectionTransport { send(string); close(); diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index b7e7a76c..ef1de7c4 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -299,6 +299,42 @@ function compareDocumentations(actual, expected) { actualName: 'Object', expectedName: 'TracingOptions' }], + ['Method Frame.goto() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Frame.waitForNavigation() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Frame.setContent() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.goBack() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.goForward() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.goto() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.reload() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.setContent() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], + ['Method Page.waitForNavigation() options.waitUntil', { + actualName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + expectedName: '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array' + }], ]); const expectedForSource = expectedNamingMismatches.get(source); diff --git a/utils/doclint/generate_types/index.js b/utils/doclint/generate_types/index.js index 1aa04a2f..2786b4fc 100644 --- a/utils/doclint/generate_types/index.js +++ b/utils/doclint/generate_types/index.js @@ -80,8 +80,25 @@ function classToString(classDesc) { * @param {import('./check_public_api/Documentation').Type} type */ function typeToString(type, ...namespace) { + + /* A hack to special case TypeScript types that this type generator + * does not understand / parse correctly. + * Because the goal is to generate these types from the TypeScript + * source, this parser won't be around for much longer so investing in + * improving the parser's ability is not worth it. + */ + const specialCaseTypeMaps = new Map([ + ['"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array', + '"load"|"domcontentloaded"|"networkidle0"|"networkidle2"|Array'] + ]); + + if (!type) return 'void'; + + if (specialCaseTypeMaps.has(type.name)) + return specialCaseTypeMaps.get(type.name); + let typeString = stringifyType(parseType(type.name)); for (let i = 0; i < type.properties.length; i++) typeString = typeString.replace('arg' + i, type.properties[i].name);