From 6638a24346d9560c8ff2bc9a7368138f38fa1eb4 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Mon, 20 Apr 2020 11:32:08 +0100 Subject: [PATCH] chore: migrate `src/timeoutsettings` to typescript (#5691) --- src/DOMWorld.js | 7 ++++++- src/FrameManager.js | 5 ++++- ...{TimeoutSettings.js => TimeoutSettings.ts} | 19 ++++++++----------- src/externs.d.ts | 2 -- 4 files changed, 18 insertions(+), 15 deletions(-) rename src/{TimeoutSettings.js => TimeoutSettings.ts} (82%) diff --git a/src/DOMWorld.js b/src/DOMWorld.js index c5852cac..fd6c6942 100644 --- a/src/DOMWorld.js +++ b/src/DOMWorld.js @@ -18,6 +18,11 @@ const fs = require('fs'); const {helper, assert} = require('./helper'); const {LifecycleWatcher} = require('./LifecycleWatcher'); const {TimeoutError} = require('./Errors'); + +// Used as a TypeDef +// eslint-disable-next-line no-unused-vars +const {TimeoutSettings} = require('./TimeoutSettings'); + const readFileAsync = helper.promisify(fs.readFile); /** @@ -27,7 +32,7 @@ class DOMWorld { /** * @param {!Puppeteer.FrameManager} frameManager * @param {!Puppeteer.Frame} frame - * @param {!Puppeteer.TimeoutSettings} timeoutSettings + * @param {!TimeoutSettings} timeoutSettings */ constructor(frameManager, frame, timeoutSettings) { this._frameManager = frameManager; diff --git a/src/FrameManager.js b/src/FrameManager.js index 1dd2bbd5..d391b625 100644 --- a/src/FrameManager.js +++ b/src/FrameManager.js @@ -21,6 +21,9 @@ const {ExecutionContext, EVALUATION_SCRIPT_URL} = require('./ExecutionContext'); const {LifecycleWatcher} = require('./LifecycleWatcher'); const {DOMWorld} = require('./DOMWorld'); const {NetworkManager} = require('./NetworkManager'); +// Used as a TypeDef +// eslint-disable-next-line no-unused-vars +const {TimeoutSettings} = require('./TimeoutSettings'); const UTILITY_WORLD_NAME = '__puppeteer_utility_world__'; @@ -29,7 +32,7 @@ class FrameManager extends EventEmitter { * @param {!Puppeteer.CDPSession} client * @param {!Puppeteer.Page} page * @param {boolean} ignoreHTTPSErrors - * @param {!Puppeteer.TimeoutSettings} timeoutSettings + * @param {!TimeoutSettings} timeoutSettings */ constructor(client, page, ignoreHTTPSErrors, timeoutSettings) { super(); diff --git a/src/TimeoutSettings.js b/src/TimeoutSettings.ts similarity index 82% rename from src/TimeoutSettings.js rename to src/TimeoutSettings.ts index c6b08d39..33300b20 100644 --- a/src/TimeoutSettings.js +++ b/src/TimeoutSettings.ts @@ -17,29 +17,26 @@ const DEFAULT_TIMEOUT = 30000; class TimeoutSettings { + _defaultTimeout: number | null; + _defaultNavigationTimeout: number | null; + constructor() { this._defaultTimeout = null; this._defaultNavigationTimeout = null; } - /** - * @param {number} timeout - */ - setDefaultTimeout(timeout) { + setDefaultTimeout(timeout: number): void { this._defaultTimeout = timeout; } /** * @param {number} timeout */ - setDefaultNavigationTimeout(timeout) { + setDefaultNavigationTimeout(timeout: number): void { this._defaultNavigationTimeout = timeout; } - /** - * @return {number} - */ - navigationTimeout() { + navigationTimeout(): number { if (this._defaultNavigationTimeout !== null) return this._defaultNavigationTimeout; if (this._defaultTimeout !== null) @@ -47,11 +44,11 @@ class TimeoutSettings { return DEFAULT_TIMEOUT; } - timeout() { + timeout(): number { if (this._defaultTimeout !== null) return this._defaultTimeout; return DEFAULT_TIMEOUT; } } -module.exports = {TimeoutSettings}; +export = {TimeoutSettings}; diff --git a/src/externs.d.ts b/src/externs.d.ts index 7c0a2c56..97efb4e0 100644 --- a/src/externs.d.ts +++ b/src/externs.d.ts @@ -6,7 +6,6 @@ import {Mouse as RealMouse, Keyboard as RealKeyboard, Touchscreen as RealTouchsc import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js'; import {JSHandle as RealJSHandle, ElementHandle as RealElementHandle} from './JSHandle.js'; import {DOMWorld as RealDOMWorld} from './DOMWorld.js'; -import {TimeoutSettings as RealTimeoutSettings} from './TimeoutSettings.js'; import {ExecutionContext as RealExecutionContext} from './ExecutionContext.js'; import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js'; import * as child_process from 'child_process'; @@ -29,7 +28,6 @@ declare global { export class ElementHandle extends RealElementHandle {} export class JSHandle extends RealJSHandle {} export class DOMWorld extends RealDOMWorld {} - export class TimeoutSettings extends RealTimeoutSettings {} export class ExecutionContext extends RealExecutionContext {} export class Page extends RealPage { } export class Response extends RealResponse { }