From e3922ea1f311374649a4cfed149f40e0dd61175a Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Tue, 21 Apr 2020 10:40:04 +0100 Subject: [PATCH] chore: enforce consistent spacing around object curlys (#5700) The codebase was incredibly inconsistent with the use of spacing around curly braces, e.g.: ``` // this? const a = {b: 1} // or? const a = { b: 1 } ``` This extended into import statements also. Google's styleguide is no spacing, so we're going with that. --- .eslintrc.js | 1 + install.js | 2 +- package.json | 3 +- src/Browser.js | 2 +- src/Coverage.js | 4 +- src/EmulationManager.js | 4 +- src/Events.js | 2 +- src/ExecutionContext.js | 20 +- src/FrameManager.js | 2 +- src/Input.js | 4 +- src/JSHandle.js | 18 +- src/Launcher.js | 10 +- src/NetworkManager.js | 6 +- src/Page.js | 38 +-- src/Target.js | 2 +- src/TaskQueue.ts | 2 +- src/helper.ts | 2 +- test/CDPSession.spec.js | 12 +- test/accessibility.spec.js | 50 ++-- test/browser.spec.js | 12 +- test/browsercontext.spec.js | 18 +- test/chromiumonly.spec.js | 2 +- test/click.spec.js | 50 ++-- test/cookies.spec.js | 28 +- test/coverage.spec.js | 48 ++-- test/defaultbrowsercontext.spec.js | 6 +- test/dialog.spec.js | 6 +- test/elementhandle.spec.js | 44 ++-- test/emulation.spec.js | 46 ++-- test/evaluation.spec.js | 94 +++---- test/fixtures.spec.js | 8 +- test/frame.spec.js | 28 +- test/golden-utils.js | 8 +- test/headful.spec.js | 6 +- test/ignorehttpserrors.spec.js | 12 +- test/input.spec.js | 36 +-- test/jshandle.spec.js | 42 +-- test/keyboard.spec.js | 36 +-- test/launcher.spec.js | 40 +-- test/mouse.spec.js | 16 +- test/navigation.spec.js | 98 +++---- test/network.spec.js | 78 +++--- test/oopif.spec.js | 4 +- test/page.spec.js | 274 ++++++++++---------- test/queryselector.spec.js | 48 ++-- test/requestinterception.spec.js | 96 +++---- test/screenshot.spec.js | 46 ++-- test/target.spec.js | 30 +-- test/tracing.spec.js | 10 +- test/waittask.spec.js | 104 ++++---- test/worker.spec.js | 12 +- utils/doclint/check_public_api/MDBuilder.js | 2 +- utils/doclint/check_public_api/index.js | 2 +- utils/fetch_devices.js | 2 +- utils/testserver/index.js | 4 +- 55 files changed, 791 insertions(+), 789 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index ccf940586e9ae..80cd46bab3db5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -33,6 +33,7 @@ module.exports = { }], "brace-style": [2, "1tbs", {"allowSingleLine": true}], "curly": [2, "multi-or-nest", "consistent"], + "object-curly-spacing": [2, "never"], "new-parens": 2, "func-call-spacing": 2, "arrow-parens": [2, "as-needed"], diff --git a/install.js b/install.js index 8555af326dc0a..5bc0a7b98568c 100644 --- a/install.js +++ b/install.js @@ -37,7 +37,7 @@ async function download() { const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host || process.env.npm_package_config_puppeteer_download_host; const puppeteer = require('./index'); const product = process.env.PUPPETEER_PRODUCT || process.env.npm_config_puppeteer_product || process.env.npm_package_config_puppeteer_product || 'chrome'; - const browserFetcher = puppeteer.createBrowserFetcher({ product, host: downloadHost }); + const browserFetcher = puppeteer.createBrowserFetcher({product, host: downloadHost}); const revision = await getRevision(); await fetchBinary(revision); diff --git a/package.json b/package.json index 9ac6b80161931..b5b3fb71b3a92 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "prepublishOnly": "npm run tsc", "dev-install": "npm run tsc && node install.js", "install": "node install.js", - "lint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .) && npm run tsc && npm run doc", + "eslint": "([ \"$CI\" = true ] && eslint --ext js --ext ts --quiet -f codeframe . || eslint --ext js --ext ts .)", + "lint": "npm run eslint && npm run tsc && npm run doc", "doc": "node utils/doclint/cli.js", "tsc": "tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/", "apply-next-version": "node utils/apply_next_version.js", diff --git a/src/Browser.js b/src/Browser.js index 0592ee76164d1..e6bef4ec87e99 100644 --- a/src/Browser.js +++ b/src/Browser.js @@ -14,7 +14,7 @@ * limitations under the License. */ -const { helper, assert } = require('./helper'); +const {helper, assert} = require('./helper'); const {Target} = require('./Target'); const EventEmitter = require('events'); const {TaskQueue} = require('./TaskQueue'); diff --git a/src/Coverage.js b/src/Coverage.js index daa5c43e8c5d1..437469bb074cc 100644 --- a/src/Coverage.js +++ b/src/Coverage.js @@ -273,8 +273,8 @@ class CSSCoverage { function convertToDisjointRanges(nestedRanges) { const points = []; for (const range of nestedRanges) { - points.push({ offset: range.startOffset, type: 0, range }); - points.push({ offset: range.endOffset, type: 1, range }); + points.push({offset: range.startOffset, type: 0, range}); + points.push({offset: range.endOffset, type: 1, range}); } // Sort points to form a valid parenthesis sequence. points.sort((a, b) => { diff --git a/src/EmulationManager.js b/src/EmulationManager.js index a29ea7016eb7c..d3e1f15dde6a8 100644 --- a/src/EmulationManager.js +++ b/src/EmulationManager.js @@ -38,11 +38,11 @@ class EmulationManager { const height = viewport.height; const deviceScaleFactor = viewport.deviceScaleFactor || 1; /** @type {Protocol.Emulation.ScreenOrientation} */ - const screenOrientation = viewport.isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' }; + const screenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'}; const hasTouch = viewport.hasTouch || false; await Promise.all([ - this._client.send('Emulation.setDeviceMetricsOverride', { mobile, width, height, deviceScaleFactor, screenOrientation }), + this._client.send('Emulation.setDeviceMetricsOverride', {mobile, width, height, deviceScaleFactor, screenOrientation}), this._client.send('Emulation.setTouchEmulationEnabled', { enabled: hasTouch }) diff --git a/src/Events.js b/src/Events.js index c994de5a4c47e..8050cba93eff9 100644 --- a/src/Events.js +++ b/src/Events.js @@ -77,4 +77,4 @@ const Events = { }, }; -module.exports = { Events }; +module.exports = {Events}; diff --git a/src/ExecutionContext.js b/src/ExecutionContext.js index 3283d9f5cad62..88056ef356758 100644 --- a/src/ExecutionContext.js +++ b/src/ExecutionContext.js @@ -120,7 +120,7 @@ class ExecutionContext { err.message += ' Are you passing a nested JSHandle?'; throw err; } - const { exceptionDetails, result: remoteObject } = await callFunctionOnPromise.catch(rewriteError); + const {exceptionDetails, result: remoteObject} = await callFunctionOnPromise.catch(rewriteError); if (exceptionDetails) throw new Error('Evaluation failed: ' + helper.getExceptionMessage(exceptionDetails)); return returnByValue ? helper.valueFromRemoteObject(remoteObject) : createJSHandle(this, remoteObject); @@ -132,15 +132,15 @@ class ExecutionContext { */ function convertArgument(arg) { if (typeof arg === 'bigint') // eslint-disable-line valid-typeof - return { unserializableValue: `${arg.toString()}n` }; + return {unserializableValue: `${arg.toString()}n`}; if (Object.is(arg, -0)) - return { unserializableValue: '-0' }; + return {unserializableValue: '-0'}; if (Object.is(arg, Infinity)) - return { unserializableValue: 'Infinity' }; + return {unserializableValue: 'Infinity'}; if (Object.is(arg, -Infinity)) - return { unserializableValue: '-Infinity' }; + return {unserializableValue: '-Infinity'}; if (Object.is(arg, NaN)) - return { unserializableValue: 'NaN' }; + return {unserializableValue: 'NaN'}; const objectHandle = arg && (arg instanceof JSHandle) ? arg : null; if (objectHandle) { if (objectHandle._context !== this) @@ -148,12 +148,12 @@ class ExecutionContext { if (objectHandle._disposed) throw new Error('JSHandle is disposed!'); if (objectHandle._remoteObject.unserializableValue) - return { unserializableValue: objectHandle._remoteObject.unserializableValue }; + return {unserializableValue: objectHandle._remoteObject.unserializableValue}; if (!objectHandle._remoteObject.objectId) - return { value: objectHandle._remoteObject.value }; - return { objectId: objectHandle._remoteObject.objectId }; + return {value: objectHandle._remoteObject.value}; + return {objectId: objectHandle._remoteObject.objectId}; } - return { value: arg }; + return {value: arg}; } /** diff --git a/src/FrameManager.js b/src/FrameManager.js index 30849c703ac15..b972cd0e4e765 100644 --- a/src/FrameManager.js +++ b/src/FrameManager.js @@ -70,7 +70,7 @@ class FrameManager extends EventEmitter { const {frameTree} = /** @type Protocol.Page.getFrameTreeReturnValue*/ (result[1]); this._handleFrameTree(frameTree); await Promise.all([ - this._client.send('Page.setLifecycleEventsEnabled', { enabled: true }), + this._client.send('Page.setLifecycleEventsEnabled', {enabled: true}), this._client.send('Runtime.enable', {}).then(() => this._ensureIsolatedWorld(UTILITY_WORLD_NAME)), this._networkManager.initialize(), ]); diff --git a/src/Input.js b/src/Input.js index 93b774a25c624..19777a4f356ae 100644 --- a/src/Input.js +++ b/src/Input.js @@ -43,7 +43,7 @@ class Keyboard { * @param {string} key * @param {{text?: string}=} options */ - async down(key, options = { text: undefined }) { + async down(key, options = {text: undefined}) { const description = this._keyDescriptionForString(key); const autoRepeat = this._pressedKeys.has(description.code); @@ -312,4 +312,4 @@ class Touchscreen { } } -module.exports = { Keyboard, Mouse, Touchscreen}; +module.exports = {Keyboard, Mouse, Touchscreen}; diff --git a/src/JSHandle.js b/src/JSHandle.js index d6fcd1edcec39..958f069e18245 100644 --- a/src/JSHandle.js +++ b/src/JSHandle.js @@ -304,8 +304,8 @@ class ElementHandle extends JSHandle { if (option.selected && !element.multiple) break; } - element.dispatchEvent(new Event('input', { bubbles: true })); - element.dispatchEvent(new Event('change', { bubbles: true })); + element.dispatchEvent(new Event('input', {bubbles: true})); + element.dispatchEvent(new Event('change', {bubbles: true})); return options.filter(option => option.selected).map(option => option.value); }, values); } @@ -321,9 +321,9 @@ class ElementHandle extends JSHandle { // the cost unnecessarily. const path = require('path'); const files = filePaths.map(filePath => path.resolve(filePath)); - const { objectId } = this._remoteObject; - const { node } = await this._client.send('DOM.describeNode', { objectId }); - const { backendNodeId } = node; + const {objectId} = this._remoteObject; + const {node} = await this._client.send('DOM.describeNode', {objectId}); + const {backendNodeId} = node; // The zero-length array is a special case, it seems that DOM.setFileInputFiles does // not actually update the files in that case, so the solution is to eval the element @@ -333,11 +333,11 @@ class ElementHandle extends JSHandle { element.files = new DataTransfer().files; // Dispatch events for this case because it should behave akin to a user action. - element.dispatchEvent(new Event('input', { bubbles: true })); - element.dispatchEvent(new Event('change', { bubbles: true })); + element.dispatchEvent(new Event('input', {bubbles: true})); + element.dispatchEvent(new Event('change', {bubbles: true})); }); } else { - await this._client.send('DOM.setFileInputFiles', { objectId, files, backendNodeId }); + await this._client.send('DOM.setFileInputFiles', {objectId, files, backendNodeId}); } } @@ -437,7 +437,7 @@ class ElementHandle extends JSHandle { assert(boundingBox.width !== 0, 'Node has 0 width.'); assert(boundingBox.height !== 0, 'Node has 0 height.'); - const { layoutViewport: { pageX, pageY } } = await this._client.send('Page.getLayoutMetrics'); + const {layoutViewport: {pageX, pageY}} = await this._client.send('Page.getLayoutMetrics'); const clip = Object.assign({}, boundingBox); clip.x += pageX; diff --git a/src/Launcher.js b/src/Launcher.js index c63ac5ceb713d..4fd050ee27611 100644 --- a/src/Launcher.js +++ b/src/Launcher.js @@ -169,7 +169,7 @@ class BrowserRunner { this.connection = new Connection(browserWSEndpoint, transport, slowMo); } else { // stdio was assigned during start(), and the 'pipe' option there adds the 4th and 5th items to stdio array - const { 3: pipeWrite, 4: pipeRead } = /** @type {!Array} */ (this.proc.stdio); + const {3: pipeWrite, 4: pipeRead} = /** @type {!Array} */ (this.proc.stdio); const transport = new PipeTransport(/** @type {!NodeJS.WritableStream} */ pipeWrite, /** @type {!NodeJS.ReadableStream} */ pipeRead); this.connection = new Connection('', transport, slowMo); } @@ -476,7 +476,7 @@ class FirefoxLauncher { async _updateRevision() { // replace 'latest' placeholder with actual downloaded revision if (this._preferredRevision === 'latest') { - const browserFetcher = new BrowserFetcher(this._projectRoot, { product: this.product }); + const browserFetcher = new BrowserFetcher(this._projectRoot, {product: this.product}); const localRevisions = await browserFetcher.localRevisions(); if (localRevisions[0]) this._preferredRevision = localRevisions[0]; @@ -743,7 +743,7 @@ class FirefoxLauncher { */ function waitForWSEndpoint(browserProcess, timeout, preferredRevision) { return new Promise((resolve, reject) => { - const rl = readline.createInterface({ input: browserProcess.stderr }); + const rl = readline.createInterface({input: browserProcess.stderr}); let stderr = ''; const listeners = [ helper.addEventListener(rl, 'line', onLine), @@ -802,7 +802,7 @@ function getWSEndpoint(browserURL) { const endpointURL = URL.resolve(browserURL, '/json/version'); const protocol = endpointURL.startsWith('https') ? https : http; - const requestOptions = Object.assign(URL.parse(endpointURL), { method: 'GET' }); + const requestOptions = Object.assign(URL.parse(endpointURL), {method: 'GET'}); const request = protocol.request(requestOptions, res => { let data = ''; if (res.statusCode !== 200) { @@ -836,7 +836,7 @@ function resolveExecutablePath(launcher) { const executablePath = process.env.PUPPETEER_EXECUTABLE_PATH || process.env.npm_config_puppeteer_executable_path || process.env.npm_package_config_puppeteer_executable_path; if (executablePath) { const missingText = !fs.existsSync(executablePath) ? 'Tried to use PUPPETEER_EXECUTABLE_PATH env variable to launch browser but did not find any executable at: ' + executablePath : null; - return { executablePath, missingText }; + return {executablePath, missingText}; } } const browserFetcher = new BrowserFetcher(launcher._projectRoot, {product: launcher.product}); diff --git a/src/NetworkManager.js b/src/NetworkManager.js index c68cb7fc03f7f..2766543a9de55 100644 --- a/src/NetworkManager.js +++ b/src/NetworkManager.js @@ -82,7 +82,7 @@ class NetworkManager extends EventEmitter { assert(helper.isString(value), `Expected value of header "${key}" to be String, but "${typeof value}" is found.`); this._extraHTTPHeaders[key.toLowerCase()] = value; } - await this._client.send('Network.setExtraHTTPHeaders', { headers: this._extraHTTPHeaders }); + await this._client.send('Network.setExtraHTTPHeaders', {headers: this._extraHTTPHeaders}); } /** @@ -112,7 +112,7 @@ class NetworkManager extends EventEmitter { * @param {string} userAgent */ async setUserAgent(userAgent) { - await this._client.send('Network.setUserAgentOverride', { userAgent }); + await this._client.send('Network.setUserAgentOverride', {userAgent}); } /** @@ -192,7 +192,7 @@ class NetworkManager extends EventEmitter { const {username, password} = this._credentials || {username: undefined, password: undefined}; this._client.send('Fetch.continueWithAuth', { requestId: event.requestId, - authChallengeResponse: { response, username, password }, + authChallengeResponse: {response, username, password}, }).catch(debugError); } diff --git a/src/Page.js b/src/Page.js index 10046313ffeb5..bc8cb63211212 100644 --- a/src/Page.js +++ b/src/Page.js @@ -184,7 +184,7 @@ class Page extends EventEmitter { * @param {!{longitude: number, latitude: number, accuracy: (number|undefined)}} options */ async setGeolocation(options) { - const { longitude, latitude, accuracy = 0} = options; + const {longitude, latitude, accuracy = 0} = options; if (longitude < -180 || longitude > 180) throw new Error(`Invalid longitude "${longitude}": precondition -180 <= LONGITUDE <= 180 failed.`); if (latitude < -90 || latitude > 90) @@ -424,7 +424,7 @@ class Page extends EventEmitter { }); await this.deleteCookie(...items); if (items.length) - await this._client.send('Network.setCookies', { cookies: items }); + await this._client.send('Network.setCookies', {cookies: items}); } /** @@ -579,7 +579,7 @@ class Page extends EventEmitter { else expression = helper.evaluationString(deliverErrorValue, name, seq, error); } - this._client.send('Runtime.evaluate', { expression, contextId: event.executionContextId }).catch(debugError); + this._client.send('Runtime.evaluate', {expression, contextId: event.executionContextId}).catch(debugError); /** * @param {string} name @@ -806,14 +806,14 @@ class Page extends EventEmitter { if (this._javascriptEnabled === enabled) return; this._javascriptEnabled = enabled; - await this._client.send('Emulation.setScriptExecutionDisabled', { value: !enabled }); + await this._client.send('Emulation.setScriptExecutionDisabled', {value: !enabled}); } /** * @param {boolean} enabled */ async setBypassCSP(enabled) { - await this._client.send('Page.setBypassCSP', { enabled }); + await this._client.send('Page.setBypassCSP', {enabled}); } /** @@ -885,7 +885,7 @@ class Page extends EventEmitter { */ async evaluateOnNewDocument(pageFunction, ...args) { const source = helper.evaluationString(pageFunction, ...args); - await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source }); + await this._client.send('Page.addScriptToEvaluateOnNewDocument', {source}); } /** @@ -951,20 +951,20 @@ class Page extends EventEmitter { const height = Math.ceil(metrics.contentSize.height); // Overwrite clip for full page at all times. - clip = { x: 0, y: 0, width, height, scale: 1 }; + clip = {x: 0, y: 0, width, height, scale: 1}; const { isMobile = false, deviceScaleFactor = 1, isLandscape = false } = this._viewport || {}; /** @type {!Protocol.Emulation.ScreenOrientation} */ - const screenOrientation = isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' }; - await this._client.send('Emulation.setDeviceMetricsOverride', { mobile: isMobile, width, height, deviceScaleFactor, screenOrientation }); + const screenOrientation = isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'}; + await this._client.send('Emulation.setDeviceMetricsOverride', {mobile: isMobile, width, height, deviceScaleFactor, screenOrientation}); } const shouldSetDefaultBackground = options.omitBackground && format === 'png'; if (shouldSetDefaultBackground) - await this._client.send('Emulation.setDefaultBackgroundColorOverride', { color: { r: 0, g: 0, b: 0, a: 0 } }); - const result = await this._client.send('Page.captureScreenshot', { format, quality: options.quality, clip }); + await this._client.send('Emulation.setDefaultBackgroundColorOverride', {color: {r: 0, g: 0, b: 0, a: 0}}); + const result = await this._client.send('Page.captureScreenshot', {format, quality: options.quality, clip}); if (shouldSetDefaultBackground) await this._client.send('Emulation.setDefaultBackgroundColorOverride'); @@ -1056,7 +1056,7 @@ class Page extends EventEmitter { if (runBeforeUnload) { await this._client.send('Page.close'); } else { - await this._client._connection.send('Target.closeTarget', { targetId: this._target._targetId }); + await this._client._connection.send('Target.closeTarget', {targetId: this._target._targetId}); await this._target._isClosedPromise; } } @@ -1235,13 +1235,13 @@ Page.PaperFormats = { legal: {width: 8.5, height: 14}, tabloid: {width: 11, height: 17}, ledger: {width: 17, height: 11}, - a0: {width: 33.1, height: 46.8 }, - a1: {width: 23.4, height: 33.1 }, - a2: {width: 16.54, height: 23.4 }, - a3: {width: 11.7, height: 16.54 }, - a4: {width: 8.27, height: 11.7 }, - a5: {width: 5.83, height: 8.27 }, - a6: {width: 4.13, height: 5.83 }, + a0: {width: 33.1, height: 46.8}, + a1: {width: 23.4, height: 33.1}, + a2: {width: 16.54, height: 23.4}, + a3: {width: 11.7, height: 16.54}, + a4: {width: 8.27, height: 11.7}, + a5: {width: 5.83, height: 8.27}, + a6: {width: 4.13, height: 5.83}, }; const unitToPixels = { diff --git a/src/Target.js b/src/Target.js index 540e701d25faf..54825c2c5aca4 100644 --- a/src/Target.js +++ b/src/Target.js @@ -132,7 +132,7 @@ class Target { * @return {?Puppeteer.Target} */ opener() { - const { openerId } = this._targetInfo; + const {openerId} = this._targetInfo; if (!openerId) return null; return this.browser()._targets.get(openerId); diff --git a/src/TaskQueue.ts b/src/TaskQueue.ts index e7ac6ba1fade7..d459d0550f5b5 100644 --- a/src/TaskQueue.ts +++ b/src/TaskQueue.ts @@ -33,4 +33,4 @@ class TaskQueue { } } -export = { TaskQueue }; +export = {TaskQueue}; diff --git a/src/helper.ts b/src/helper.ts index fb9fa265b3c26..5d4ff998721ce 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -112,7 +112,7 @@ export interface PuppeteerEventListener { function addEventListener(emitter: NodeJS.EventEmitter, eventName: string|symbol, handler: (...args: any[]) => void): PuppeteerEventListener { emitter.on(eventName, handler); - return { emitter, eventName, handler }; + return {emitter, eventName, handler}; } function removeEventListeners(listeners: Array<{emitter: NodeJS.EventEmitter; eventName: string|symbol; handler: (...args: any[]) => void}>): void { diff --git a/test/CDPSession.spec.js b/test/CDPSession.spec.js index 5f16d0566ab74..ad3b2cfbd6691 100644 --- a/test/CDPSession.spec.js +++ b/test/CDPSession.spec.js @@ -23,19 +23,19 @@ describeChromeOnly('Target.createCDPSession', function() { setupTestPageAndContextHooks(); it('should work', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const client = await page.target().createCDPSession(); await Promise.all([ client.send('Runtime.enable'), - client.send('Runtime.evaluate', { expression: 'window.foo = "bar"' }) + client.send('Runtime.evaluate', {expression: 'window.foo = "bar"'}) ]); const foo = await page.evaluate(() => window.foo); expect(foo).toBe('bar'); }); it('should send events', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); const client = await page.target().createCDPSession(); await client.send('Network.enable'); @@ -45,7 +45,7 @@ describeChromeOnly('Target.createCDPSession', function() { expect(events.length).toBe(1); }); it('should enable and disable domains independently', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const client = await page.target().createCDPSession(); await client.send('Runtime.enable'); @@ -62,7 +62,7 @@ describeChromeOnly('Target.createCDPSession', function() { expect(event.url).toBe('foo.js'); }); it('should be able to detach session', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const client = await page.target().createCDPSession(); await client.send('Runtime.enable'); @@ -78,7 +78,7 @@ describeChromeOnly('Target.createCDPSession', function() { expect(error.message).toContain('Session closed.'); }); it('should throw nice errors', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const client = await page.target().createCDPSession(); const error = await theSourceOfTheProblems().catch(error => error); diff --git a/test/accessibility.spec.js b/test/accessibility.spec.js index 68022c7807cdd..a62a624efc281 100644 --- a/test/accessibility.spec.js +++ b/test/accessibility.spec.js @@ -22,7 +22,7 @@ describeFailsFirefox('Accessibility', function() { setupTestPageAndContextHooks(); it('should work', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(` @@ -84,7 +84,7 @@ describeFailsFirefox('Accessibility', function() { expect(await page.accessibility.snapshot()).toEqual(golden); }); it('should report uninteresting nodes', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(``); await page.focus('textarea'); @@ -115,35 +115,35 @@ describeFailsFirefox('Accessibility', function() { expect(findFocusedNode(await page.accessibility.snapshot({interestingOnly: false}))).toEqual(golden); }); it('roledescription', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
Hi
'); const snapshot = await page.accessibility.snapshot(); expect(snapshot.children[0].roledescription).toEqual('foo'); }); it('orientation', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('11'); const snapshot = await page.accessibility.snapshot(); expect(snapshot.children[0].orientation).toEqual('vertical'); }); it('autocomplete', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(''); const snapshot = await page.accessibility.snapshot(); expect(snapshot.children[0].autocomplete).toEqual('list'); }); it('multiselectable', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
hey
'); const snapshot = await page.accessibility.snapshot(); expect(snapshot.children[0].multiselectable).toEqual(true); }); it('keyshortcuts', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
hey
'); const snapshot = await page.accessibility.snapshot(); @@ -151,7 +151,7 @@ describeFailsFirefox('Accessibility', function() { }); describe('filtering children of leaf nodes', function() { it('should not report text nodes inside controls', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -184,7 +184,7 @@ describeFailsFirefox('Accessibility', function() { expect(await page.accessibility.snapshot()).toEqual(golden); }); it('rich text editable fields should have children', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -216,7 +216,7 @@ describeFailsFirefox('Accessibility', function() { expect(snapshot.children[0]).toEqual(golden); }); it('rich text editable fields with role should have children', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -249,7 +249,7 @@ describeFailsFirefox('Accessibility', function() { // Firefox does not support contenteditable="plaintext-only". describeFailsFirefox('plaintext contenteditable', function() { it('plain text field with role should not have children', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
Edit this image:my fake image
`); @@ -261,7 +261,7 @@ describeFailsFirefox('Accessibility', function() { }); }); it('plain text field without role should not have content', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
Edit this image:my fake image
`); @@ -272,7 +272,7 @@ describeFailsFirefox('Accessibility', function() { }); }); it('plain text field with tabindex and without role should not have content', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
Edit this image:my fake image
`); @@ -284,7 +284,7 @@ describeFailsFirefox('Accessibility', function() { }); }); it('non editable textbox with role and tabIndex and label should not have children', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -304,7 +304,7 @@ describeFailsFirefox('Accessibility', function() { expect(snapshot.children[0]).toEqual(golden); }); it('checkbox with and tabIndex and label should not have children', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -324,7 +324,7 @@ describeFailsFirefox('Accessibility', function() { expect(snapshot.children[0]).toEqual(golden); }); it('checkbox without label should not have children', async() => { - const { page, isFirefox } = getTestState(); + const {page, isFirefox} = getTestState(); await page.setContent(`
@@ -346,7 +346,7 @@ describeFailsFirefox('Accessibility', function() { describe('root option', function() { it('should work a button', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(``); @@ -357,7 +357,7 @@ describeFailsFirefox('Accessibility', function() { }); }); it('should work an input', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(``); @@ -369,7 +369,7 @@ describeFailsFirefox('Accessibility', function() { }); }); it('should work a menu', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
@@ -384,13 +384,13 @@ describeFailsFirefox('Accessibility', function() { role: 'menu', name: 'My Menu', children: - [ { role: 'menuitem', name: 'First Item' }, - { role: 'menuitem', name: 'Second Item' }, - { role: 'menuitem', name: 'Third Item' } ] + [ {role: 'menuitem', name: 'First Item'}, + {role: 'menuitem', name: 'Second Item'}, + {role: 'menuitem', name: 'Third Item'} ] }); }); it('should return null when the element is no longer in DOM', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(``); const button = await page.$('button'); @@ -398,7 +398,7 @@ describeFailsFirefox('Accessibility', function() { expect(await page.accessibility.snapshot({root: button})).toEqual(null); }); it('should support the interestingOnly option', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
`); const div = await page.$('div'); @@ -411,7 +411,7 @@ describeFailsFirefox('Accessibility', function() { role: 'button', name: 'My Button', children: [ - { role: 'text', name: 'My Button' }, + {role: 'text', name: 'My Button'}, ], }, ], diff --git a/test/browser.spec.js b/test/browser.spec.js index 38f4188bb45a4..17ebc31894678 100644 --- a/test/browser.spec.js +++ b/test/browser.spec.js @@ -22,7 +22,7 @@ describe('Browser specs', function() { describe('Browser.version', function() { it('should return whether we are in headless', async() => { - const { browser, isHeadless } = getTestState(); + const {browser, isHeadless} = getTestState(); const version = await browser.version(); expect(version.length).toBeGreaterThan(0); @@ -32,7 +32,7 @@ describe('Browser specs', function() { describe('Browser.userAgent', function() { it('should include WebKit', async() => { - const { browser, isChrome } = getTestState(); + const {browser, isChrome} = getTestState(); const userAgent = await browser.userAgent(); expect(userAgent.length).toBeGreaterThan(0); @@ -45,7 +45,7 @@ describe('Browser specs', function() { describe('Browser.target', function() { it('should return browser target', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); const target = browser.target(); expect(target.type()).toBe('browser'); @@ -54,13 +54,13 @@ describe('Browser specs', function() { describe('Browser.process', function() { it('should return child_process instance', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); const process = await browser.process(); expect(process.pid).toBeGreaterThan(0); }); it('should not return child_process for remote browser', async() => { - const { browser, puppeteer } = getTestState(); + const {browser, puppeteer} = getTestState(); const browserWSEndpoint = browser.wsEndpoint(); const remoteBrowser = await puppeteer.connect({browserWSEndpoint}); @@ -71,7 +71,7 @@ describe('Browser specs', function() { describe('Browser.isConnected', () => { it('should set the browser connected state', async() => { - const { browser, puppeteer } = getTestState(); + const {browser, puppeteer} = getTestState(); const browserWSEndpoint = browser.wsEndpoint(); const newBrowser = await puppeteer.connect({browserWSEndpoint}); diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.js index af243e377eea5..fbaa8d09de129 100644 --- a/test/browsercontext.spec.js +++ b/test/browsercontext.spec.js @@ -21,7 +21,7 @@ const utils = require('./utils'); describe('BrowserContext', function() { setupTestBrowserHooks(); itFailsFirefox('should have default context', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); expect(browser.browserContexts().length).toEqual(1); const defaultContext = browser.browserContexts()[0]; expect(defaultContext.isIncognito()).toBe(false); @@ -31,7 +31,7 @@ describe('BrowserContext', function() { expect(error.message).toContain('cannot be closed'); }); itFailsFirefox('should create new incognito context', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); expect(browser.browserContexts().length).toBe(1); const context = await browser.createIncognitoBrowserContext(); @@ -42,7 +42,7 @@ describe('BrowserContext', function() { expect(browser.browserContexts().length).toBe(1); }); itFailsFirefox('should close all belonging targets once closing context', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); expect((await browser.pages()).length).toBe(1); @@ -55,7 +55,7 @@ describe('BrowserContext', function() { expect((await browser.pages()).length).toBe(1); }); itFailsFirefox('window.open should use parent tab context', async() => { - const { browser, server } = getTestState(); + const {browser, server} = getTestState(); const context = await browser.createIncognitoBrowserContext(); const page = await context.newPage(); @@ -68,7 +68,7 @@ describe('BrowserContext', function() { await context.close(); }); itFailsFirefox('should fire target events', async() => { - const { browser, server } = getTestState(); + const {browser, server} = getTestState(); const context = await browser.createIncognitoBrowserContext(); const events = []; @@ -86,7 +86,7 @@ describe('BrowserContext', function() { await context.close(); }); itFailsFirefox('should wait for a target', async() => { - const { browser, server } = getTestState(); + const {browser, server} = getTestState(); const context = await browser.createIncognitoBrowserContext(); let resolved = false; @@ -101,7 +101,7 @@ describe('BrowserContext', function() { }); it('should timeout waiting for a non-existent target', async() => { - const { browser, server, puppeteer } = getTestState(); + const {browser, server, puppeteer} = getTestState(); const context = await browser.createIncognitoBrowserContext(); const error = await context.waitForTarget(target => target.url() === server.EMPTY_PAGE, {timeout: 1}).catch(e => e); @@ -110,7 +110,7 @@ describe('BrowserContext', function() { }); itFailsFirefox('should isolate localStorage and cookies', async() => { - const { browser, server } = getTestState(); + const {browser, server} = getTestState(); // Create two incognito contexts. const context1 = await browser.createIncognitoBrowserContext(); @@ -157,7 +157,7 @@ describe('BrowserContext', function() { }); itFailsFirefox('should work across sessions', async() => { - const { browser, puppeteer} = getTestState(); + const {browser, puppeteer} = getTestState(); expect(browser.browserContexts().length).toBe(1); const context = await browser.createIncognitoBrowserContext(); diff --git a/test/chromiumonly.spec.js b/test/chromiumonly.spec.js index 0aed71b26cbcc..0d8d60a985c9c 100644 --- a/test/chromiumonly.spec.js +++ b/test/chromiumonly.spec.js @@ -106,7 +106,7 @@ describeChromeOnly('Chromium-Specific Page Tests', function() { setupTestBrowserHooks(); setupTestPageAndContextHooks(); it('Page.setRequestInterception should work with intervention headers', async() => { - const { server, page } = getTestState(); + const {server, page} = getTestState(); server.setRoute('/intervention', (req, res) => res.end(` '); @@ -1211,7 +1211,7 @@ describe('Page', function() { describe('Page.setCacheEnabled', function() { it('should enable or disable the cache based on the state passed', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/cached/one-style.html'); const [cachedRequest] = await Promise.all([ @@ -1229,7 +1229,7 @@ describe('Page', function() { expect(nonCachedRequest.headers['if-modified-since']).toBe(undefined); }); itFailsFirefox('should stay disabled when toggling request interception on/off', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setCacheEnabled(false); await page.setRequestInterception(true); @@ -1260,7 +1260,7 @@ describe('Page', function() { describe('Page.title', function() { it('should return the page title', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/title.html'); expect(await page.title()).toBe('Woof-Woof'); @@ -1269,7 +1269,7 @@ describe('Page', function() { describe('Page.select', function() { it('should select single option', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.select('select', 'blue'); @@ -1277,7 +1277,7 @@ describe('Page', function() { expect(await page.evaluate(() => result.onChange)).toEqual(['blue']); }); it('should select only first option', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.select('select', 'blue', 'green', 'red'); @@ -1285,7 +1285,7 @@ describe('Page', function() { expect(await page.evaluate(() => result.onChange)).toEqual(['blue']); }); it('should not throw when select causes navigation', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.$eval('select', select => select.addEventListener('input', () => window.location = '/empty.html')); @@ -1296,7 +1296,7 @@ describe('Page', function() { expect(page.url()).toContain('empty.html'); }); it('should select multiple options', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.evaluate(() => makeMultiple()); @@ -1305,7 +1305,7 @@ describe('Page', function() { expect(await page.evaluate(() => result.onChange)).toEqual(['blue', 'green', 'red']); }); it('should respect event bubbling', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.select('select', 'blue'); @@ -1313,7 +1313,7 @@ describe('Page', function() { expect(await page.evaluate(() => result.onBubblingChange)).toEqual(['blue']); }); it('should throw when element is not a element.'); }); it('should return [] on no matched values', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); const result = await page.select('select','42','abc'); expect(result).toEqual([]); }); it('should return an array of matched values', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.evaluate(() => makeMultiple()); @@ -1336,21 +1336,21 @@ describe('Page', function() { expect(result.reduce((accumulator,current) => ['blue', 'black', 'magenta'].includes(current) && accumulator, true)).toEqual(true); }); it('should return an array of one element when multiple is not set', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); const result = await page.select('select','42','blue','black','magenta'); expect(result.length).toEqual(1); }); it('should return [] on no values',async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); const result = await page.select('select'); expect(result).toEqual([]); }); it('should deselect all options when passed no values for a multiple select',async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.evaluate(() => makeMultiple()); @@ -1359,7 +1359,7 @@ describe('Page', function() { expect(await page.$eval('select', select => Array.from(select.options).every(option => !option.selected))).toEqual(true); }); it('should deselect all options when passed no values for a select without multiple',async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.select('select','blue','black','magenta'); @@ -1367,7 +1367,7 @@ describe('Page', function() { expect(await page.$eval('select', select => Array.from(select.options).every(option => !option.selected))).toEqual(true); }); itFailsFirefox('should throw if passed in non-strings', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(''); let error = null; @@ -1380,7 +1380,7 @@ describe('Page', function() { }); // @see https://github.com/puppeteer/puppeteer/issues/3327 itFailsFirefox('should work when re-defining top-level Event class', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/input/select.html'); await page.evaluate(() => window.Event = null); @@ -1392,7 +1392,7 @@ describe('Page', function() { describe('Page.Events.Close', function() { itFailsFirefox('should work with window.close', async() => { - const { page, context } = getTestState(); + const {page, context} = getTestState(); const newPagePromise = new Promise(fulfill => context.once('targetcreated', target => fulfill(target.page()))); await page.evaluate(() => window['newPage'] = window.open('about:blank')); @@ -1402,7 +1402,7 @@ describe('Page', function() { await closedPromise; }); it('should work with page.close', async() => { - const { context } = getTestState(); + const {context} = getTestState(); const newPage = await context.newPage(); const closedPromise = new Promise(x => newPage.on('close', x)); @@ -1413,7 +1413,7 @@ describe('Page', function() { describe('Page.browser', function() { it('should return the correct browser instance', async() => { - const { page, browser } = getTestState(); + const {page, browser} = getTestState(); expect(page.browser()).toBe(browser); }); @@ -1421,7 +1421,7 @@ describe('Page', function() { describe('Page.browserContext', function() { it('should return the correct browser instance', async() => { - const { page, context } = getTestState(); + const {page, context} = getTestState(); expect(page.browserContext()).toBe(context); }); diff --git a/test/queryselector.spec.js b/test/queryselector.spec.js index 38d6823866369..75506e0901800 100644 --- a/test/queryselector.spec.js +++ b/test/queryselector.spec.js @@ -21,21 +21,21 @@ describe('querySelector', function() { setupTestPageAndContextHooks(); describeFailsFirefox('Page.$eval', function() { it('should work', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
43543
'); const idAttribute = await page.$eval('section', e => e.id); expect(idAttribute).toBe('testAttribute'); }); it('should accept arguments', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
hello
'); const text = await page.$eval('section', (e, suffix) => e.textContent + suffix, ' world!'); expect(text).toBe('hello world!'); }); it('should accept ElementHandles as arguments', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
hello
world
'); const divHandle = await page.$('div'); @@ -43,7 +43,7 @@ describe('querySelector', function() { expect(text).toBe('hello world'); }); it('should throw error if no element is found', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let error = null; await page.$eval('section', e => e.id).catch(e => error = e); @@ -53,7 +53,7 @@ describe('querySelector', function() { describeFailsFirefox('Page.$$eval', function() { it('should work', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
hello
beautiful
world!
'); const divsCount = await page.$$eval('div', divs => divs.length); @@ -63,14 +63,14 @@ describe('querySelector', function() { describeFailsFirefox('Page.$', function() { it('should query existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
test
'); const element = await page.$('section'); expect(element).toBeTruthy(); }); it('should return null for non-existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const element = await page.$('non-existing-element'); expect(element).toBe(null); @@ -79,7 +79,7 @@ describe('querySelector', function() { describe('Page.$$', function() { itFailsFirefox('should query existing elements', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
A

B
'); const elements = await page.$$('div'); @@ -88,7 +88,7 @@ describe('querySelector', function() { expect(await Promise.all(promises)).toEqual(['A', 'B']); }); it('should return empty array if nothing is found', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); const elements = await page.$$('div'); @@ -98,7 +98,7 @@ describe('querySelector', function() { describeFailsFirefox('Path.$x', function() { it('should query existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
test
'); const elements = await page.$x('/html/body/section'); @@ -106,13 +106,13 @@ describe('querySelector', function() { expect(elements.length).toBe(1); }); it('should return empty array for non-existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const element = await page.$x('/html/body/non-existing-element'); expect(element).toEqual([]); }); it('should return multiple elements', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
'); const elements = await page.$x('/html/body/div'); @@ -123,7 +123,7 @@ describe('querySelector', function() { describe('ElementHandle.$', function() { it('should query existing element', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/playground.html'); await page.setContent('
A
'); @@ -135,7 +135,7 @@ describe('querySelector', function() { }); itFailsFirefox('should return null for non-existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
B
'); const html = await page.$('html'); @@ -145,7 +145,7 @@ describe('querySelector', function() { }); describeFailsFirefox('ElementHandle.$eval', function() { it('should work', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
10
'); const tweet = await page.$('.tweet'); @@ -154,7 +154,7 @@ describe('querySelector', function() { }); it('should retrieve content from subtree', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const htmlContent = '
not-a-child-div
a-child-div
'; await page.setContent(htmlContent); @@ -164,7 +164,7 @@ describe('querySelector', function() { }); it('should throw in case of missing selector', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const htmlContent = '
not-a-child-div
'; await page.setContent(htmlContent); @@ -175,7 +175,7 @@ describe('querySelector', function() { }); describeFailsFirefox('ElementHandle.$$eval', function() { it('should work', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
'); const tweet = await page.$('.tweet'); @@ -184,7 +184,7 @@ describe('querySelector', function() { }); it('should retrieve content from subtree', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const htmlContent = '
not-a-child-div
a1-child-div
a2-child-div
'; await page.setContent(htmlContent); @@ -194,7 +194,7 @@ describe('querySelector', function() { }); it('should not throw in case of missing selector', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const htmlContent = '
not-a-child-div
'; await page.setContent(htmlContent); @@ -207,7 +207,7 @@ describe('querySelector', function() { describeFailsFirefox('ElementHandle.$$', function() { it('should query existing elements', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
A

B
'); const html = await page.$('html'); @@ -218,7 +218,7 @@ describe('querySelector', function() { }); it('should return empty array for non-existing elements', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('A
B'); const html = await page.$('html'); @@ -230,7 +230,7 @@ describe('querySelector', function() { describe('ElementHandle.$x', function() { it('should query existing element', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.PREFIX + '/playground.html'); await page.setContent('
A
'); @@ -242,7 +242,7 @@ describe('querySelector', function() { }); itFailsFirefox('should return null for non-existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
B
'); const html = await page.$('html'); diff --git a/test/requestinterception.spec.js b/test/requestinterception.spec.js index a1bf336453653..4e66656f26502 100644 --- a/test/requestinterception.spec.js +++ b/test/requestinterception.spec.js @@ -25,7 +25,7 @@ describe('request interception', function() { setupTestPageAndContextHooks(); describeFailsFirefox('Page.setRequestInterception', function() { it('should intercept', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -48,7 +48,7 @@ describe('request interception', function() { expect(response.remoteAddress().port).toBe(server.PORT); }); it('should work when POST is redirected with 302', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); server.setRedirect('/rredirect', '/empty.html'); await page.goto(server.EMPTY_PAGE); @@ -66,7 +66,7 @@ describe('request interception', function() { }); // @see https://github.com/puppeteer/puppeteer/issues/3973 it('should work when header manipulation headers with redirect', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); server.setRedirect('/rrredirect', '/empty.html'); await page.setRequestInterception(true); @@ -74,13 +74,13 @@ describe('request interception', function() { const headers = Object.assign({}, request.headers(), { foo: 'bar' }); - request.continue({ headers }); + request.continue({headers}); }); await page.goto(server.PREFIX + '/rrredirect'); }); // @see https://github.com/puppeteer/puppeteer/issues/4743 it('should be able to remove headers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -88,7 +88,7 @@ describe('request interception', function() { foo: 'bar', origin: undefined, // remove "origin" header }); - request.continue({ headers }); + request.continue({headers}); }); const [serverRequest] = await Promise.all([ @@ -99,7 +99,7 @@ describe('request interception', function() { expect(serverRequest.headers.origin).toBe(undefined); }); it('should contain referer header', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); const requests = []; @@ -113,11 +113,11 @@ describe('request interception', function() { expect(requests[1].headers().referer).toContain('/one-style.html'); }); it('should properly return navigation response when URL has cookies', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); // Setup cookie. await page.goto(server.EMPTY_PAGE); - await page.setCookie({ name: 'foo', value: 'bar'}); + await page.setCookie({name: 'foo', value: 'bar'}); // Setup request interception. await page.setRequestInterception(true); @@ -126,7 +126,7 @@ describe('request interception', function() { expect(response.status()).toBe(200); }); it('should stop intercepting', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.once('request', request => request.continue()); @@ -135,7 +135,7 @@ describe('request interception', function() { await page.goto(server.EMPTY_PAGE); }); it('should show custom HTTP headers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setExtraHTTPHeaders({ foo: 'bar' @@ -150,7 +150,7 @@ describe('request interception', function() { }); // @see https://github.com/puppeteer/puppeteer/issues/4337 it('should work with redirect inside sync XHR', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); server.setRedirect('/logo.png', '/pptr.png'); @@ -165,9 +165,9 @@ describe('request interception', function() { expect(status).toBe(200); }); it('should work with custom referer headers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); - await page.setExtraHTTPHeaders({ 'referer': server.EMPTY_PAGE }); + await page.setExtraHTTPHeaders({'referer': server.EMPTY_PAGE}); await page.setRequestInterception(true); page.on('request', request => { expect(request.headers()['referer']).toBe(server.EMPTY_PAGE); @@ -177,7 +177,7 @@ describe('request interception', function() { expect(response.ok()).toBe(true); }); it('should be abortable', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -194,7 +194,7 @@ describe('request interception', function() { expect(failedRequests).toBe(1); }); it('should be abortable with custom error codes', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -207,7 +207,7 @@ describe('request interception', function() { expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED'); }); it('should send referer', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setExtraHTTPHeaders({ referer: 'http://google.com/' @@ -221,7 +221,7 @@ describe('request interception', function() { expect(request.headers['referer']).toBe('http://google.com/'); }); it('should fail navigation when aborting main resource', async() => { - const { page, server, isChrome } = getTestState(); + const {page, server, isChrome} = getTestState(); await page.setRequestInterception(true); page.on('request', request => request.abort()); @@ -234,7 +234,7 @@ describe('request interception', function() { expect(error.message).toContain('NS_ERROR_FAILURE'); }); it('should work with redirects', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); const requests = []; @@ -263,7 +263,7 @@ describe('request interception', function() { } }); it('should work with redirects for subresources', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); const requests = []; @@ -290,7 +290,7 @@ describe('request interception', function() { expect(redirectChain[2].url()).toContain('/three-style.css'); }); it('should be able to abort redirects', async() => { - const { page, server, isChrome } = getTestState(); + const {page, server, isChrome} = getTestState(); await page.setRequestInterception(true); server.setRedirect('/non-existing.json', '/non-existing-2.json'); @@ -315,7 +315,7 @@ describe('request interception', function() { expect(result).toContain('NetworkError'); }); it('should work with equal requests', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); let responseCount = 1; @@ -340,7 +340,7 @@ describe('request interception', function() { expect(results).toEqual(['11', 'FAILED', '22']); }); it('should navigate to dataURL and fire dataURL requests', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setRequestInterception(true); const requests = []; @@ -355,7 +355,7 @@ describe('request interception', function() { expect(requests[0].url()).toBe(dataURL); }); it('should be able to fetch dataURL and fire dataURL requests', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); await page.setRequestInterception(true); @@ -371,7 +371,7 @@ describe('request interception', function() { expect(requests[0].url()).toBe(dataURL); }); it('should navigate to URL with hash and and fire requests without hash', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); const requests = []; @@ -386,7 +386,7 @@ describe('request interception', function() { expect(requests[0].url()).toBe(server.EMPTY_PAGE); }); it('should work with encoded server', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); // The requestWillBeSent will report encoded URL, whereas interception will // report URL as-is. @see crbug.com/759388 @@ -396,7 +396,7 @@ describe('request interception', function() { expect(response.status()).toBe(404); }); it('should work with badly encoded server', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); server.setRoute('/malformed?rnd=%911', (req, res) => res.end()); @@ -405,7 +405,7 @@ describe('request interception', function() { expect(response.status()).toBe(200); }); it('should work with encoded server - 2', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); // The requestWillBeSent will report URL as-is, whereas interception will // report encoded URL for stylesheet. @see crbug.com/759388 @@ -421,7 +421,7 @@ describe('request interception', function() { expect(requests[1].response().status()).toBe(404); }); it('should not throw "Invalid Interception Id" if the request was cancelled', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setContent(''); await page.setRequestInterception(true); @@ -437,7 +437,7 @@ describe('request interception', function() { expect(error).toBe(null); }); it('should throw if interception is not enabled', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); let error = null; page.on('request', async request => { @@ -451,7 +451,7 @@ describe('request interception', function() { expect(error.message).toContain('Request Interception is not enabled'); }); it('should work with file URLs', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setRequestInterception(true); const urls = new Set(); @@ -468,20 +468,20 @@ describe('request interception', function() { describeFailsFirefox('Request.continue', function() { it('should work', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => request.continue()); await page.goto(server.EMPTY_PAGE); }); it('should amend HTTP headers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { const headers = Object.assign({}, request.headers()); headers['FOO'] = 'bar'; - request.continue({ headers }); + request.continue({headers}); }); await page.goto(server.EMPTY_PAGE); const [request] = await Promise.all([ @@ -491,12 +491,12 @@ describe('request interception', function() { expect(request.headers['foo']).toBe('bar'); }); it('should redirect in a way non-observable to page', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { const redirectURL = request.url().includes('/empty.html') ? server.PREFIX + '/consolelog.html' : undefined; - request.continue({ url: redirectURL }); + request.continue({url: redirectURL}); }); let consoleMessage = null; page.on('console', msg => consoleMessage = msg); @@ -505,13 +505,13 @@ describe('request interception', function() { expect(consoleMessage.text()).toBe('yellow'); }); it('should amend method', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); await page.setRequestInterception(true); page.on('request', request => { - request.continue({ method: 'POST' }); + request.continue({method: 'POST'}); }); const [request] = await Promise.all([ server.waitForRequest('/sleep.zzz'), @@ -520,26 +520,26 @@ describe('request interception', function() { expect(request.method).toBe('POST'); }); it('should amend post data', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); await page.setRequestInterception(true); page.on('request', request => { - request.continue({ postData: 'doggo' }); + request.continue({postData: 'doggo'}); }); const [serverRequest] = await Promise.all([ server.waitForRequest('/sleep.zzz'), - page.evaluate(() => fetch('/sleep.zzz', { method: 'POST', body: 'birdy' })) + page.evaluate(() => fetch('/sleep.zzz', {method: 'POST', body: 'birdy'})) ]); expect(await serverRequest.postBody).toBe('doggo'); }); it('should amend both post data and method on navigation', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { - request.continue({ method: 'POST', postData: 'doggo' }); + request.continue({method: 'POST', postData: 'doggo'}); }); const [serverRequest] = await Promise.all([ server.waitForRequest('/empty.html'), @@ -552,7 +552,7 @@ describe('request interception', function() { describeFailsFirefox('Request.respond', function() { it('should work', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -570,7 +570,7 @@ describe('request interception', function() { expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!'); }); it('should work with status code 422', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -585,7 +585,7 @@ describe('request interception', function() { expect(await page.evaluate(() => document.body.textContent)).toBe('Yo, page!'); }); it('should redirect', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -606,7 +606,7 @@ describe('request interception', function() { expect(response.url()).toBe(server.EMPTY_PAGE); }); it('should allow mocking binary responses', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { @@ -626,7 +626,7 @@ describe('request interception', function() { expect(await img.screenshot()).toBeGolden('mock-binary-response.png'); }); it('should stringify intercepted request response headers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setRequestInterception(true); page.on('request', request => { diff --git a/test/screenshot.spec.js b/test/screenshot.spec.js index 30aea51918590..f41da94022c8b 100644 --- a/test/screenshot.spec.js +++ b/test/screenshot.spec.js @@ -23,7 +23,7 @@ describe('Screenshots', function() { describe('Page.screenshot', function() { itFailsFirefox('should work', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -31,7 +31,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-sanity.png'); }); itFailsFirefox('should clip rect', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -46,7 +46,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-clip-rect.png'); }); itFailsFirefox('should clip elements to the viewport', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -61,7 +61,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-offscreen-clip.png'); }); it('should run in parallel', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -80,7 +80,7 @@ describe('Screenshots', function() { expect(screenshots[1]).toBeGolden('grid-cell-1.png'); }); itFailsFirefox('should take fullPage screenshots', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -90,7 +90,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-grid-fullpage.png'); }); it('should run in parallel in multiple pages', async() => { - const { server, context } = getTestState(); + const {server, context} = getTestState(); const N = 2; const pages = await Promise.all(Array(N).fill(0).map(async() => { @@ -100,30 +100,30 @@ describe('Screenshots', function() { })); const promises = []; for (let i = 0; i < N; ++i) - promises.push(pages[i].screenshot({ clip: { x: 50 * i, y: 0, width: 50, height: 50 } })); + promises.push(pages[i].screenshot({clip: {x: 50 * i, y: 0, width: 50, height: 50}})); const screenshots = await Promise.all(promises); for (let i = 0; i < N; ++i) expect(screenshots[i]).toBeGolden(`grid-cell-${i}.png`); await Promise.all(pages.map(page => page.close())); }); itFailsFirefox('should allow transparency', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); - await page.setViewport({ width: 100, height: 100 }); + await page.setViewport({width: 100, height: 100}); await page.goto(server.EMPTY_PAGE); const screenshot = await page.screenshot({omitBackground: true}); expect(screenshot).toBeGolden('transparent.png'); }); itFailsFirefox('should render white background on jpeg file', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); - await page.setViewport({ width: 100, height: 100 }); + await page.setViewport({width: 100, height: 100}); await page.goto(server.EMPTY_PAGE); const screenshot = await page.screenshot({omitBackground: true, type: 'jpeg'}); expect(screenshot).toBeGolden('white.jpg'); }); it('should work with odd clip size on Retina displays', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const screenshot = await page.screenshot({ clip: { @@ -136,7 +136,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-clip-odd-size.png'); }); itFailsFirefox('should return base64', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -149,7 +149,7 @@ describe('Screenshots', function() { describe('ElementHandle.screenshot', function() { it('should work', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.goto(server.PREFIX + '/grid.html'); @@ -159,7 +159,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-element-bounding-box.png'); }); itFailsFirefox('should take into account padding and border', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.setContent(` @@ -178,7 +178,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-element-padding-border.png'); }); itFailsFirefox('should capture full element when larger than viewport', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setViewport({width: 500, height: 500}); @@ -201,10 +201,10 @@ describe('Screenshots', function() { const screenshot = await elementHandle.screenshot(); expect(screenshot).toBeGolden('screenshot-element-larger-than-viewport.png'); - expect(await page.evaluate(() => ({ w: window.innerWidth, h: window.innerHeight }))).toEqual({ w: 500, h: 500 }); + expect(await page.evaluate(() => ({w: window.innerWidth, h: window.innerHeight}))).toEqual({w: 500, h: 500}); }); itFailsFirefox('should scroll element into view', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.setContent(` @@ -229,7 +229,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-element-scrolled-into-view.png'); }); itFailsFirefox('should work with a rotated element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setViewport({width: 500, height: 500}); await page.setContent(`
'); const div = await page.$('div'); @@ -261,7 +261,7 @@ describe('Screenshots', function() { expect(error.message).toBe('Node has 0 height.'); }); itFailsFirefox('should work for an element with fractional dimensions', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
'); const elementHandle = await page.$('div'); @@ -269,7 +269,7 @@ describe('Screenshots', function() { expect(screenshot).toBeGolden('screenshot-element-fractional.png'); }); itFailsFirefox('should work for an element with an offset', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
'); const elementHandle = await page.$('div'); diff --git a/test/target.spec.js b/test/target.spec.js index b31b0f14d0292..81f8ce4629d54 100644 --- a/test/target.spec.js +++ b/test/target.spec.js @@ -24,7 +24,7 @@ describe('Target', function() { setupTestPageAndContextHooks(); it('Browser.targets should return all of the targets', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); // The pages will be the testing page and the original newtab page const targets = browser.targets(); @@ -33,7 +33,7 @@ describe('Target', function() { expect(targets.some(target => target.type() === 'browser')).toBeTruthy(); }); it('Browser.pages should return all of the pages', async() => { - const { page, context } = getTestState(); + const {page, context} = getTestState(); // The pages will be the testing page const allPages = await context.pages(); @@ -42,14 +42,14 @@ describe('Target', function() { expect(allPages[0]).not.toBe(allPages[1]); }); it('should contain browser target', async() => { - const { browser } = getTestState(); + const {browser} = getTestState(); const targets = browser.targets(); const browserTarget = targets.find(target => target.type() === 'browser'); expect(browserTarget).toBeTruthy(); }); it('should be able to use the default page in the browser', async() => { - const { page, browser } = getTestState(); + const {page, browser} = getTestState(); // The pages will be the testing page and the original newtab page const allPages = await browser.pages(); @@ -58,7 +58,7 @@ describe('Target', function() { expect(await originalPage.$('body')).toBeTruthy(); }); itFailsFirefox('should report when a new page is created and closed', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); const [otherPage] = await Promise.all([ context.waitForTarget(target => target.url() === server.CROSS_PROCESS_PREFIX + '/empty.html').then(target => target.page()), @@ -81,7 +81,7 @@ describe('Target', function() { expect(allPages).not.toContain(otherPage); }); itFailsFirefox('should report when a service worker is created and destroyed', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); await page.goto(server.EMPTY_PAGE); const createdTarget = new Promise(fulfill => context.once('targetcreated', target => fulfill(target))); @@ -96,7 +96,7 @@ describe('Target', function() { expect(await destroyedTarget).toBe(await createdTarget); }); itFailsFirefox('should create a worker from a service worker', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); await page.goto(server.PREFIX + '/serviceworkers/empty/sw.html'); @@ -105,7 +105,7 @@ describe('Target', function() { expect(await worker.evaluate(() => self.toString())).toBe('[object ServiceWorkerGlobalScope]'); }); itFailsFirefox('should create a worker from a shared worker', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); await page.goto(server.EMPTY_PAGE); await page.evaluate(() => { @@ -116,7 +116,7 @@ describe('Target', function() { expect(await worker.evaluate(() => self.toString())).toBe('[object SharedWorkerGlobalScope]'); }); itFailsFirefox('should report when a target url changes', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); await page.goto(server.EMPTY_PAGE); let changedTarget = new Promise(fulfill => context.once('targetchanged', target => fulfill(target))); @@ -128,7 +128,7 @@ describe('Target', function() { expect((await changedTarget).url()).toBe(server.EMPTY_PAGE); }); itFailsFirefox('should not report uninitialized pages', async() => { - const { context } = getTestState(); + const {context} = getTestState(); let targetChanged = false; const listener = () => targetChanged = true; @@ -149,7 +149,7 @@ describe('Target', function() { context.removeListener('targetchanged', listener); }); itFailsFirefox('should not crash while redirecting if original request was missed', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); let serverResponse = null; server.setRoute('/one-style.css', (req, res) => serverResponse = res); @@ -162,7 +162,7 @@ describe('Target', function() { const target = await context.waitForTarget(target => target.url().includes('one-style.html')); const newPage = await target.page(); // Issue a redirect. - serverResponse.writeHead(302, { location: '/injectedstyle.css' }); + serverResponse.writeHead(302, {location: '/injectedstyle.css'}); serverResponse.end(); // Wait for the new page to load. await waitEvent(newPage, 'load'); @@ -170,7 +170,7 @@ describe('Target', function() { await newPage.close(); }); itFailsFirefox('should have an opener', async() => { - const { page, server, context } = getTestState(); + const {page, server, context} = getTestState(); await page.goto(server.EMPTY_PAGE); const [createdTarget] = await Promise.all([ @@ -184,7 +184,7 @@ describe('Target', function() { describe('Browser.waitForTarget', () => { itFailsFirefox('should wait for a target', async() => { - const { browser, server } = getTestState(); + const {browser, server} = getTestState(); let resolved = false; const targetPromise = browser.waitForTarget(target => target.url() === server.EMPTY_PAGE); @@ -197,7 +197,7 @@ describe('Target', function() { await page.close(); }); it('should timeout waiting for a non-existent target', async() => { - const { browser, server, puppeteer } = getTestState(); + const {browser, server, puppeteer} = getTestState(); let error = null; await browser.waitForTarget(target => target.url() === server.EMPTY_PAGE, { diff --git a/test/tracing.spec.js b/test/tracing.spec.js index 7b514098de15f..53aa574c4a2e7 100644 --- a/test/tracing.spec.js +++ b/test/tracing.spec.js @@ -45,7 +45,7 @@ describeChromeOnly('Tracing', function() { } }); it('should output a trace', async() => { - const { server} = getTestState(); + const {server} = getTestState(); await page.tracing.start({screenshots: true, path: outputFile}); await page.goto(server.PREFIX + '/grid.html'); @@ -70,7 +70,7 @@ describeChromeOnly('Tracing', function() { await page.tracing.stop(); }); it('should return a buffer', async() => { - const { server } = getTestState(); + const {server} = getTestState(); await page.tracing.start({screenshots: true, path: outputFile}); await page.goto(server.PREFIX + '/grid.html'); @@ -79,7 +79,7 @@ describeChromeOnly('Tracing', function() { expect(trace.toString()).toEqual(buf.toString()); }); it('should work without options', async() => { - const { server } = getTestState(); + const {server} = getTestState(); await page.tracing.start(); await page.goto(server.PREFIX + '/grid.html'); @@ -88,7 +88,7 @@ describeChromeOnly('Tracing', function() { }); it('should return null in case of Buffer error', async() => { - const { server } = getTestState(); + const {server} = getTestState(); await page.tracing.start({screenshots: true}); await page.goto(server.PREFIX + '/grid.html'); @@ -102,7 +102,7 @@ describeChromeOnly('Tracing', function() { }); it('should support a buffer without a path', async() => { - const { server } = getTestState(); + const {server} = getTestState(); await page.tracing.start({screenshots: true}); await page.goto(server.PREFIX + '/grid.html'); diff --git a/test/waittask.spec.js b/test/waittask.spec.js index fdbc687e8a6c5..9dc32755f9e68 100644 --- a/test/waittask.spec.js +++ b/test/waittask.spec.js @@ -24,7 +24,7 @@ describe('waittask specs', function() { describe('Page.waitFor', function() { itFailsFirefox('should wait for selector', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); let found = false; const waitFor = page.waitFor('div').then(() => found = true); @@ -36,7 +36,7 @@ describe('waittask specs', function() { }); itFailsFirefox('should wait for an xpath', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); let found = false; const waitFor = page.waitFor('//div').then(() => found = true); @@ -47,7 +47,7 @@ describe('waittask specs', function() { expect(found).toBe(true); }); itFailsFirefox('should not allow you to select an element with single slash xpath', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
some text
`); let error = null; @@ -55,7 +55,7 @@ describe('waittask specs', function() { expect(error).toBeTruthy(); }); it('should timeout', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const startTime = Date.now(); const timeout = 42; @@ -63,7 +63,7 @@ describe('waittask specs', function() { expect(Date.now() - startTime).not.toBeLessThan(timeout / 2); }); it('should work with multiline body', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const result = await page.waitForFunction(` (() => true)() @@ -71,7 +71,7 @@ describe('waittask specs', function() { expect(await result.jsonValue()).toBe(true); }); it('should wait for predicate', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await Promise.all([ page.waitFor(() => window.innerWidth < 100), @@ -79,14 +79,14 @@ describe('waittask specs', function() { ]); }); it('should throw when unknown type', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let error = null; await page.waitFor({foo: 'bar'}).catch(e => error = e); expect(error.message).toContain('Unsupported target type'); }); it('should wait for predicate with arguments', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.waitFor((arg1, arg2) => arg1 !== arg2, {}, 1, 2); }); @@ -94,14 +94,14 @@ describe('waittask specs', function() { describe('Frame.waitForFunction', function() { it('should accept a string', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const watchdog = page.waitForFunction('window.__FOO === 1'); await page.evaluate(() => window.__FOO = 1); await watchdog; }); itFailsFirefox('should work when resolved right before execution context disposal', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.evaluateOnNewDocument(() => window.__RELOADED = true); await page.waitForFunction(() => { @@ -111,7 +111,7 @@ describe('waittask specs', function() { }); }); it('should poll on interval', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let success = false; const startTime = Date.now(); @@ -125,7 +125,7 @@ describe('waittask specs', function() { expect(Date.now() - startTime).not.toBeLessThan(polling / 2); }); it('should poll on mutation', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let success = false; const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {polling: 'mutation'}) @@ -136,14 +136,14 @@ describe('waittask specs', function() { await watchdog; }); it('should poll on raf', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const watchdog = page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}); await page.evaluate(() => window.__FOO = 'hit'); await watchdog; }); itFailsFirefox('should work with strict CSP policy', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); server.setCSP('/empty.html', 'script-src ' + server.PREFIX); await page.goto(server.EMPTY_PAGE); @@ -155,7 +155,7 @@ describe('waittask specs', function() { expect(error).toBe(null); }); it('should throw on bad polling value', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let error = null; try { @@ -167,7 +167,7 @@ describe('waittask specs', function() { expect(error.message).toContain('polling'); }); it('should throw negative polling interval', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let error = null; try { @@ -179,17 +179,17 @@ describe('waittask specs', function() { expect(error.message).toContain('Cannot poll with non-positive interval'); }); it('should return the success value as a JSHandle', async() => { - const { page } = getTestState(); + const {page} = getTestState(); expect(await (await page.waitForFunction(() => 5)).jsonValue()).toBe(5); }); it('should return the window as a success value', async() => { - const { page } = getTestState(); + const {page} = getTestState(); expect(await page.waitForFunction(() => window)).toBeTruthy(); }); itFailsFirefox('should accept ElementHandle arguments', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent('
'); const div = await page.$('div'); @@ -200,7 +200,7 @@ describe('waittask specs', function() { await waitForFunction; }); it('should respect timeout', async() => { - const { page, puppeteer } = getTestState(); + const {page, puppeteer} = getTestState(); let error = null; await page.waitForFunction('false', {timeout: 10}).catch(e => error = e); @@ -209,7 +209,7 @@ describe('waittask specs', function() { expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); }); it('should respect default timeout', async() => { - const { page, puppeteer } = getTestState(); + const {page, puppeteer} = getTestState(); page.setDefaultTimeout(1); let error = null; @@ -218,7 +218,7 @@ describe('waittask specs', function() { expect(error.message).toContain('waiting for function failed: timeout'); }); it('should disable timeout when its set to 0', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const watchdog = page.waitForFunction(() => { window.__counter = (window.__counter || 0) + 1; @@ -229,7 +229,7 @@ describe('waittask specs', function() { await watchdog; }); it('should survive cross-process navigation', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); let fooFound = false; const waitForFunction = page.waitForFunction('window.__FOO === 1').then(() => fooFound = true); @@ -244,7 +244,7 @@ describe('waittask specs', function() { expect(fooFound).toBe(true); }); it('should survive navigations', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); const watchdog = page.waitForFunction(() => window.__done); await page.goto(server.EMPTY_PAGE); @@ -258,7 +258,7 @@ describe('waittask specs', function() { const addElement = tag => document.body.appendChild(document.createElement(tag)); it('should immediately resolve promise if node exists', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); const frame = page.mainFrame(); @@ -268,7 +268,7 @@ describe('waittask specs', function() { }); it('should work with removed MutationObserver', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.evaluate(() => delete window.MutationObserver); const [handle] = await Promise.all([ @@ -279,7 +279,7 @@ describe('waittask specs', function() { }); it('should resolve promise when node is added', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); const frame = page.mainFrame(); @@ -292,7 +292,7 @@ describe('waittask specs', function() { }); it('should work when node is added through innerHTML', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); const watchdog = page.waitForSelector('h3 div'); @@ -302,7 +302,7 @@ describe('waittask specs', function() { }); it('Page.waitForSelector is shortcut for main frame', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await page.goto(server.EMPTY_PAGE); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); @@ -315,7 +315,7 @@ describe('waittask specs', function() { }); it('should run in specified frame', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); await utils.attachFrame(page, 'frame2', server.EMPTY_PAGE); @@ -329,7 +329,7 @@ describe('waittask specs', function() { }); it('should throw when frame is detached', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); const frame = page.frames()[1]; @@ -341,7 +341,7 @@ describe('waittask specs', function() { expect(waitError.message).toContain('waitForFunction failed: frame got detached.'); }); it('should survive cross-process navigation', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); let boxFound = false; const waitForSelector = page.waitForSelector('.box').then(() => boxFound = true); @@ -354,7 +354,7 @@ describe('waittask specs', function() { expect(boxFound).toBe(true); }); it('should wait for visible', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divFound = false; const waitForSelector = page.waitForSelector('div', {visible: true}).then(() => divFound = true); @@ -367,7 +367,7 @@ describe('waittask specs', function() { expect(divFound).toBe(true); }); it('should wait for visible recursively', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divVisible = false; const waitForSelector = page.waitForSelector('div#inner', {visible: true}).then(() => divVisible = true); @@ -380,7 +380,7 @@ describe('waittask specs', function() { expect(divVisible).toBe(true); }); it('hidden should wait for visibility: hidden', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divHidden = false; await page.setContent(`
`); @@ -392,7 +392,7 @@ describe('waittask specs', function() { expect(divHidden).toBe(true); }); it('hidden should wait for display: none', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divHidden = false; await page.setContent(`
`); @@ -404,7 +404,7 @@ describe('waittask specs', function() { expect(divHidden).toBe(true); }); it('hidden should wait for removal', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
`); let divRemoved = false; @@ -416,13 +416,13 @@ describe('waittask specs', function() { expect(divRemoved).toBe(true); }); it('should return null if waiting to hide non-existing element', async() => { - const { page } = getTestState(); + const {page} = getTestState(); - const handle = await page.waitForSelector('non-existing', { hidden: true }); + const handle = await page.waitForSelector('non-existing', {hidden: true}); expect(handle).toBe(null); }); it('should respect timeout', async() => { - const { page, puppeteer } = getTestState(); + const {page, puppeteer} = getTestState(); let error = null; await page.waitForSelector('div', {timeout: 10}).catch(e => error = e); @@ -431,7 +431,7 @@ describe('waittask specs', function() { expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); }); it('should have an error message specifically for awaiting an element to be hidden', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
`); let error = null; @@ -441,7 +441,7 @@ describe('waittask specs', function() { }); it('should respond to node attribute mutation', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divFound = false; const waitForSelector = page.waitForSelector('.zombo').then(() => divFound = true); @@ -451,14 +451,14 @@ describe('waittask specs', function() { expect(await waitForSelector).toBe(true); }); itFailsFirefox('should return the element handle', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const waitForSelector = page.waitForSelector('.zombo'); await page.setContent(`
anything
`); expect(await page.evaluate(x => x.textContent, await waitForSelector)).toBe('anything'); }); it('should have correct stack trace for timeout', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let error; await page.waitForSelector('.zombo', {timeout: 10}).catch(e => error = e); @@ -470,14 +470,14 @@ describe('waittask specs', function() { const addElement = tag => document.body.appendChild(document.createElement(tag)); it('should support some fancy xpath', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`

red herring

hello world

`); const waitForXPath = page.waitForXPath('//p[normalize-space(.)="hello world"]'); expect(await page.evaluate(x => x.textContent, await waitForXPath)).toBe('hello world '); }); it('should respect timeout', async() => { - const { page, puppeteer } = getTestState(); + const {page, puppeteer} = getTestState(); let error = null; await page.waitForXPath('//div', {timeout: 10}).catch(e => error = e); @@ -486,7 +486,7 @@ describe('waittask specs', function() { expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); }); it('should run in specified frame', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); await utils.attachFrame(page, 'frame2', server.EMPTY_PAGE); @@ -499,7 +499,7 @@ describe('waittask specs', function() { expect(eHandle.executionContext().frame()).toBe(frame2); }); it('should throw when frame is detached', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); const frame = page.frames()[1]; @@ -511,7 +511,7 @@ describe('waittask specs', function() { expect(waitError.message).toContain('waitForFunction failed: frame got detached.'); }); it('hidden should wait for display: none', async() => { - const { page } = getTestState(); + const {page} = getTestState(); let divHidden = false; await page.setContent(`
`); @@ -523,21 +523,21 @@ describe('waittask specs', function() { expect(divHidden).toBe(true); }); it('should return the element handle', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const waitForXPath = page.waitForXPath('//*[@class="zombo"]'); await page.setContent(`
anything
`); expect(await page.evaluate(x => x.textContent, await waitForXPath)).toBe('anything'); }); it('should allow you to select a text node', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
some text
`); const text = await page.waitForXPath('//div/text()'); expect(await (await text.getProperty('nodeType')).jsonValue()).toBe(3 /* Node.TEXT_NODE */); }); it('should allow you to select an element with single slash', async() => { - const { page } = getTestState(); + const {page} = getTestState(); await page.setContent(`
some text
`); const waitForXPath = page.waitForXPath('/html/body/div'); diff --git a/test/worker.spec.js b/test/worker.spec.js index 5a948578ada79..92d467df48df2 100644 --- a/test/worker.spec.js +++ b/test/worker.spec.js @@ -23,7 +23,7 @@ describeFailsFirefox('Workers', function() { setupTestBrowserHooks(); setupTestPageAndContextHooks(); it('Page.workers', async() => { - const { page, server } = getTestState(); + const {page, server} = getTestState(); await Promise.all([ new Promise(x => page.once('workercreated', x)), @@ -37,7 +37,7 @@ describeFailsFirefox('Workers', function() { expect(page.workers().length).toBe(0); }); it('should emit created and destroyed events', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const workerCreatedPromise = new Promise(x => page.once('workercreated', x)); const workerObj = await page.evaluateHandle(() => new Worker('data:text/javascript,1')); @@ -50,7 +50,7 @@ describeFailsFirefox('Workers', function() { expect(error.message).toContain('Most likely the worker has been closed.'); }); it('should report console logs', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const [message] = await Promise.all([ waitEvent(page, 'console'), @@ -64,7 +64,7 @@ describeFailsFirefox('Workers', function() { }); }); it('should have JSHandles for console logs', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const logPromise = new Promise(x => page.on('console', x)); await page.evaluate(() => new Worker(`data:text/javascript,console.log(1,2,3,this)`)); @@ -74,7 +74,7 @@ describeFailsFirefox('Workers', function() { expect(await (await log.args()[3].getProperty('origin')).jsonValue()).toBe('null'); }); it('should have an execution context', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const workerCreatedPromise = new Promise(x => page.once('workercreated', x)); await page.evaluate(() => new Worker(`data:text/javascript,console.log(1)`)); @@ -82,7 +82,7 @@ describeFailsFirefox('Workers', function() { expect(await (await worker.executionContext()).evaluate('1+1')).toBe(2); }); it('should report errors', async() => { - const { page } = getTestState(); + const {page} = getTestState(); const errorPromise = new Promise(x => page.on('pageerror', x)); await page.evaluate(() => new Worker(`data:text/javascript, throw new Error('this is my error');`)); diff --git a/utils/doclint/check_public_api/MDBuilder.js b/utils/doclint/check_public_api/MDBuilder.js index bc3776aed5148..0e8ce0d61d511 100644 --- a/utils/doclint/check_public_api/MDBuilder.js +++ b/utils/doclint/check_public_api/MDBuilder.js @@ -297,6 +297,6 @@ module.exports = async function(page, sources) { errors.push(...outline.errors); } const documentation = new Documentation(classes); - return { documentation, errors }; + return {documentation, errors}; }; diff --git a/utils/doclint/check_public_api/index.js b/utils/doclint/check_public_api/index.js index 916a005dfa025..5f2ba1f915658 100644 --- a/utils/doclint/check_public_api/index.js +++ b/utils/doclint/check_public_api/index.js @@ -324,7 +324,7 @@ function diff(actual, expected) { const N = actual.length; const M = expected.length; if (N === 0 && M === 0) - return { extra: [], missing: [], equal: []}; + return {extra: [], missing: [], equal: []}; if (N === 0) return {extra: [], missing: expected.slice(), equal: []}; if (M === 0) diff --git a/utils/fetch_devices.js b/utils/fetch_devices.js index 98b03f211d5ff..c20e4dd4f1278 100755 --- a/utils/fetch_devices.js +++ b/utils/fetch_devices.js @@ -54,7 +54,7 @@ devices and save to the . `; const argv = require('minimist')(process.argv.slice(2), { - alias: { u: 'url', h: 'help' }, + alias: {u: 'url', h: 'help'}, }); if (argv.help) { diff --git a/utils/testserver/index.js b/utils/testserver/index.js index 85f2d1fdd77d9..a256f28ab760b 100644 --- a/utils/testserver/index.js +++ b/utils/testserver/index.js @@ -147,7 +147,7 @@ class TestServer { */ setRedirect(from, to) { this.setRoute(from, (req, res) => { - res.writeHead(302, { location: to }); + res.writeHead(302, {location: to}); res.end(); }); } @@ -199,7 +199,7 @@ class TestServer { const auth = this._auths.get(pathName); const credentials = Buffer.from((request.headers.authorization || '').split(' ')[1] || '', 'base64').toString(); if (credentials !== `${auth.username}:${auth.password}`) { - response.writeHead(401, { 'WWW-Authenticate': 'Basic realm="Secure Area"' }); + response.writeHead(401, {'WWW-Authenticate': 'Basic realm="Secure Area"'}); response.end('HTTP Error 401 Unauthorized: Access is denied'); return; }