diff --git a/src/Browser.ts b/src/Browser.ts index 5ac2fec581d..10f7e7279a9 100644 --- a/src/Browser.ts +++ b/src/Browser.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { helper, assert } from './helper'; +import { assert } from './assert'; +import { helper } from './helper'; import { Target } from './Target'; import { EventEmitter } from './EventEmitter'; import { Events } from './Events'; diff --git a/src/BrowserFetcher.ts b/src/BrowserFetcher.ts index 4eacc6e7eef..3fd2d72dc9a 100644 --- a/src/BrowserFetcher.ts +++ b/src/BrowserFetcher.ts @@ -28,8 +28,8 @@ import removeRecursive from 'rimraf'; import * as URL from 'url'; import ProxyAgent from 'https-proxy-agent'; import { getProxyForUrl } from 'proxy-from-env'; - -import { helper, assert } from './helper'; +import { assert } from './assert'; +import { helper } from './helper'; const debugFetcher = debug(`puppeteer:fetcher`); const downloadURLs = { diff --git a/src/Connection.ts b/src/Connection.ts index 2ff5a75476f..a2b28fa97fe 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { assert } from './helper'; +import { assert } from './assert'; import { Events } from './Events'; import debug from 'debug'; const debugProtocolSend = debug('puppeteer:protocol:SEND ►'); diff --git a/src/Coverage.ts b/src/Coverage.ts index 0d90c5e7c3d..5f8bff84630 100644 --- a/src/Coverage.ts +++ b/src/Coverage.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { helper, debugError, assert, PuppeteerEventListener } from './helper'; +import { assert } from './assert'; +import { helper, debugError, PuppeteerEventListener } from './helper'; import Protocol from './protocol'; import { CDPSession } from './Connection'; diff --git a/src/DOMWorld.ts b/src/DOMWorld.ts index cc30a458b08..678ddc4300d 100644 --- a/src/DOMWorld.ts +++ b/src/DOMWorld.ts @@ -15,7 +15,8 @@ */ import * as fs from 'fs'; -import { helper, assert } from './helper'; +import { assert } from './assert'; +import { helper } from './helper'; import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher'; import { TimeoutError } from './Errors'; import { JSHandle, ElementHandle } from './JSHandle'; diff --git a/src/Dialog.ts b/src/Dialog.ts index 716c467c2e8..775d10dbb1c 100644 --- a/src/Dialog.ts +++ b/src/Dialog.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { assert } from './helper'; +import { assert } from './assert'; import { CDPSession } from './Connection'; import Protocol from './protocol'; diff --git a/src/ExecutionContext.ts b/src/ExecutionContext.ts index c82ad8443d7..32db1a0c906 100644 --- a/src/ExecutionContext.ts +++ b/src/ExecutionContext.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { helper, assert } from './helper'; +import { assert } from './assert'; +import { helper } from './helper'; import { createJSHandle, JSHandle, ElementHandle } from './JSHandle'; import { CDPSession } from './Connection'; import { DOMWorld } from './DOMWorld'; diff --git a/src/FileChooser.ts b/src/FileChooser.ts index ed6303451c4..99a2b142812 100644 --- a/src/FileChooser.ts +++ b/src/FileChooser.ts @@ -16,7 +16,7 @@ import { ElementHandle } from './JSHandle'; import Protocol from './protocol'; -import { assert } from './helper'; +import { assert } from './assert'; export class FileChooser { private _element: ElementHandle; diff --git a/src/FrameManager.ts b/src/FrameManager.ts index d16ab3698ac..3ac37085ba7 100644 --- a/src/FrameManager.ts +++ b/src/FrameManager.ts @@ -15,7 +15,8 @@ */ import { EventEmitter } from './EventEmitter'; -import { helper, assert, debugError } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import { Events } from './Events'; import { ExecutionContext, EVALUATION_SCRIPT_URL } from './ExecutionContext'; import { LifecycleWatcher, PuppeteerLifeCycleEvent } from './LifecycleWatcher'; diff --git a/src/HTTPRequest.ts b/src/HTTPRequest.ts index b8ed5057800..7df17ee24ee 100644 --- a/src/HTTPRequest.ts +++ b/src/HTTPRequest.ts @@ -16,7 +16,8 @@ import { CDPSession } from './Connection'; import { Frame } from './FrameManager'; import { HTTPResponse } from './HTTPResponse'; -import { helper, assert, debugError } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import Protocol from './protocol'; export class HTTPRequest { diff --git a/src/Input.ts b/src/Input.ts index 0fef07d2933..7a49b224b12 100644 --- a/src/Input.ts +++ b/src/Input.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { assert } from './helper'; +import { assert } from './assert'; import { CDPSession } from './Connection'; import { keyDefinitions, KeyDefinition, KeyInput } from './USKeyboardLayout'; diff --git a/src/JSHandle.ts b/src/JSHandle.ts index d8be11c637f..38e814eea84 100644 --- a/src/JSHandle.ts +++ b/src/JSHandle.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { helper, assert, debugError } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import { ExecutionContext } from './ExecutionContext'; import { Page } from './Page'; import { CDPSession } from './Connection'; diff --git a/src/Launcher.ts b/src/Launcher.ts index 0a0e9f7cf14..60e977cdc3a 100644 --- a/src/Launcher.ts +++ b/src/Launcher.ts @@ -23,7 +23,8 @@ import * as fs from 'fs'; import { BrowserFetcher } from './BrowserFetcher'; import { Connection } from './Connection'; import { Browser } from './Browser'; -import { helper, assert, debugError } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import { ConnectionTransport } from './ConnectionTransport'; import { WebSocketTransport } from './WebSocketTransport'; import { BrowserRunner } from './launcher/BrowserRunner'; diff --git a/src/LifecycleWatcher.ts b/src/LifecycleWatcher.ts index 775453374c7..7f400911f1e 100644 --- a/src/LifecycleWatcher.ts +++ b/src/LifecycleWatcher.ts @@ -14,7 +14,8 @@ * limitations under the License. */ -import { helper, assert, PuppeteerEventListener } from './helper'; +import { assert } from './assert'; +import { helper, PuppeteerEventListener } from './helper'; import { Events } from './Events'; import { TimeoutError } from './Errors'; import { FrameManager, Frame } from './FrameManager'; diff --git a/src/NetworkManager.ts b/src/NetworkManager.ts index 8043744f611..46ed595ba81 100644 --- a/src/NetworkManager.ts +++ b/src/NetworkManager.ts @@ -14,7 +14,8 @@ * limitations under the License. */ import { EventEmitter } from './EventEmitter'; -import { helper, assert, debugError } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import Protocol from './protocol'; import { Events } from './Events'; import { CDPSession } from './Connection'; diff --git a/src/Page.ts b/src/Page.ts index be1a593df63..c5f51179e80 100644 --- a/src/Page.ts +++ b/src/Page.ts @@ -24,7 +24,8 @@ import { EmulationManager } from './EmulationManager'; import { Frame, FrameManager } from './FrameManager'; import { Keyboard, Mouse, Touchscreen, MouseButtonInput } from './Input'; import { Tracing } from './Tracing'; -import { helper, debugError, assert } from './helper'; +import { assert } from './assert'; +import { helper, debugError } from './helper'; import { Coverage } from './Coverage'; import { WebWorker } from './WebWorker'; import { Browser, BrowserContext } from './Browser'; diff --git a/src/Tracing.ts b/src/Tracing.ts index 8f19840a54a..5f2c4a4880a 100644 --- a/src/Tracing.ts +++ b/src/Tracing.ts @@ -13,7 +13,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { helper, assert } from './helper'; +import { assert } from './assert'; +import { helper } from './helper'; import { CDPSession } from './Connection'; interface TracingOptions { diff --git a/src/assert.ts b/src/assert.ts new file mode 100644 index 00000000000..6ba090ce26e --- /dev/null +++ b/src/assert.ts @@ -0,0 +1,24 @@ +/** + * Copyright 2020 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Asserts that the given value is truthy. + * @param value + * @param message - the error message to throw if the value is not truthy. + */ +export const assert = (value: unknown, message?: string): void => { + if (!value) throw new Error(message); +}; diff --git a/src/helper.ts b/src/helper.ts index c1103e9104f..03b4a8c6343 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -20,6 +20,7 @@ import { CDPSession } from './Connection'; import { promisify } from 'util'; import Protocol from './protocol'; import { CommonEventEmitter } from './EventEmitter'; +import { assert } from './assert'; const openAsync = promisify(fs.open); const writeAsync = promisify(fs.write); @@ -27,10 +28,6 @@ const closeAsync = promisify(fs.close); export const debugError = debug('puppeteer:error'); -export function assert(value: unknown, message?: string): void { - if (!value) throw new Error(message); -} - interface AnyClass { prototype: object; } diff --git a/src/launcher/BrowserRunner.ts b/src/launcher/BrowserRunner.ts index 7b571cabb26..03ea2becbc7 100644 --- a/src/launcher/BrowserRunner.ts +++ b/src/launcher/BrowserRunner.ts @@ -18,7 +18,8 @@ import debug from 'debug'; import removeFolder from 'rimraf'; import * as childProcess from 'child_process'; -import { helper, assert, debugError } from '../helper'; +import { assert } from '../assert'; +import { helper, debugError } from '../helper'; import { LaunchOptions } from './LaunchOptions'; import { Connection } from '../Connection'; import { WebSocketTransport } from '../WebSocketTransport';