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.
This commit is contained in:
Jack Franklin 2020-04-21 10:40:04 +01:00 committed by GitHub
parent 3600f2f99b
commit e3922ea1f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
55 changed files with 791 additions and 789 deletions

View File

@ -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"],

View File

@ -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);

View File

@ -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",

View File

@ -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');

View File

@ -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) => {

View File

@ -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
})

View File

@ -77,4 +77,4 @@ const Events = {
},
};
module.exports = { Events };
module.exports = {Events};

View File

@ -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};
}
/**

View File

@ -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(),
]);

View File

@ -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};

View File

@ -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;

View File

@ -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<any>} */ (this.proc.stdio);
const {3: pipeWrite, 4: pipeRead} = /** @type {!Array<any>} */ (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});

View File

@ -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);
}

View File

@ -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 = {

View File

@ -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);

View File

@ -33,4 +33,4 @@ class TaskQueue {
}
}
export = { TaskQueue };
export = {TaskQueue};

View File

@ -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 {

View File

@ -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);

View File

@ -22,7 +22,7 @@ describeFailsFirefox('Accessibility', function() {
setupTestPageAndContextHooks();
it('should work', async() => {
const { page, isFirefox } = getTestState();
const {page, isFirefox} = getTestState();
await page.setContent(`
<head>
@ -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(`<textarea>hi</textarea>`);
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('<div tabIndex=-1 aria-roledescription="foo">Hi</div>');
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('<a href="" role="slider" aria-orientation="vertical">11</a>');
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('<input type="number" aria-autocomplete="list" />');
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('<div role="grid" tabIndex=-1 aria-multiselectable=true>hey</div>');
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('<div role="grid" tabIndex=-1 aria-keyshortcuts="foo">hey</div>');
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(`
<div role="tablist">
@ -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(`
<div contenteditable="true">
@ -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(`
<div contenteditable="true" role='textbox'>
@ -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(`
<div contenteditable="plaintext-only" role='textbox'>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
@ -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(`
<div contenteditable="plaintext-only">Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
@ -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(`
<div contenteditable="plaintext-only" tabIndex=0>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
@ -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(`
<div role="textbox" tabIndex=0 aria-checked="true" aria-label="my favorite textbox">
@ -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(`
<div role="checkbox" tabIndex=0 aria-checked="true" aria-label="my favorite checkbox">
@ -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(`
<div role="checkbox" aria-checked="true">
@ -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(`<button>My Button</button>`);
@ -357,7 +357,7 @@ describeFailsFirefox('Accessibility', function() {
});
});
it('should work an input', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input title="My Input" value="My Value">`);
@ -369,7 +369,7 @@ describeFailsFirefox('Accessibility', function() {
});
});
it('should work a menu', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`
<div role="menu" title="My Menu">
@ -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(`<button>My Button</button>`);
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(`<div><button>My Button</button></div>`);
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'},
],
},
],

View File

@ -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});

View File

@ -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();

View File

@ -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(`
<script>

View File

@ -22,14 +22,14 @@ describe('Page.click', function() {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
it('should click the button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
});
itFailsFirefox('should click svg', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`
<svg height="100" width="100">
@ -40,7 +40,7 @@ describe('Page.click', function() {
expect(await page.evaluate(() => window.__CLICKED)).toBe(42);
});
itFailsFirefox('should click the button if window.Node is removed', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
await page.evaluate(() => delete window.Node);
@ -49,7 +49,7 @@ describe('Page.click', function() {
});
// @see https://github.com/puppeteer/puppeteer/issues/4281
itFailsFirefox('should click on a span with an inline element inside', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`
<style>
@ -63,7 +63,7 @@ describe('Page.click', function() {
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
});
it('should not throw UnhandledPromiseRejection when page closes', async() => {
const { page } = getTestState();
const {page} = getTestState();
const newPage = await page.browser().newPage();
await Promise.all([
@ -72,7 +72,7 @@ describe('Page.click', function() {
]).catch(e => {});
});
it('should click the button after navigation ', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
await page.click('button');
@ -81,7 +81,7 @@ describe('Page.click', function() {
expect(await page.evaluate(() => result)).toBe('Clicked');
});
itFailsFirefox('should click with disabled javascript', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.setJavaScriptEnabled(false);
await page.goto(server.PREFIX + '/wrappedlink.html');
@ -92,7 +92,7 @@ describe('Page.click', function() {
expect(page.url()).toBe(server.PREFIX + '/wrappedlink.html#clicked');
});
itFailsFirefox('should click when one of inline box children is outside of viewport', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`
<style>
@ -107,7 +107,7 @@ describe('Page.click', function() {
expect(await page.evaluate(() => window.CLICKED)).toBe(42);
});
it('should select the text by triple clicking', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -122,7 +122,7 @@ describe('Page.click', function() {
})).toBe(text);
});
itFailsFirefox('should click offscreen buttons', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/offscreenbuttons.html');
const messages = [];
@ -148,7 +148,7 @@ describe('Page.click', function() {
});
it('should click wrapped links', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/wrappedlink.html');
await page.click('a');
@ -156,7 +156,7 @@ describe('Page.click', function() {
});
it('should click on checkbox input and toggle', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/checkbox.html');
expect(await page.evaluate(() => result.check)).toBe(null);
@ -177,7 +177,7 @@ describe('Page.click', function() {
});
itFailsFirefox('should click on checkbox label and toggle', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/checkbox.html');
expect(await page.evaluate(() => result.check)).toBe(null);
@ -193,7 +193,7 @@ describe('Page.click', function() {
});
it('should fail to click a missing button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
let error = null;
@ -202,7 +202,7 @@ describe('Page.click', function() {
});
// @see https://github.com/puppeteer/puppeteer/issues/161
it('should not hang with touch-enabled viewports', async() => {
const { page, puppeteer } = getTestState();
const {page, puppeteer} = getTestState();
await page.setViewport(puppeteer.devices['iPhone 6'].viewport);
await page.mouse.down();
@ -210,7 +210,7 @@ describe('Page.click', function() {
await page.mouse.up();
});
it('should scroll and click the button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.click('#button-5');
@ -219,7 +219,7 @@ describe('Page.click', function() {
expect(await page.evaluate(() => document.querySelector('#button-80').textContent)).toBe('clicked');
});
itFailsFirefox('should double click the button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
await page.evaluate(() => {
@ -230,12 +230,12 @@ describe('Page.click', function() {
});
});
const button = await page.$('button');
await button.click({ clickCount: 2 });
await button.click({clickCount: 2});
expect(await page.evaluate('double')).toBe(true);
expect(await page.evaluate('result')).toBe('Clicked');
});
it('should click a partially obscured button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
await page.evaluate(() => {
@ -248,14 +248,14 @@ describe('Page.click', function() {
expect(await page.evaluate(() => window.result)).toBe('Clicked');
});
it('should click a rotated button', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/rotatedButton.html');
await page.click('button');
expect(await page.evaluate(() => result)).toBe('Clicked');
});
it('should fire contextmenu event on right click', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.click('#button-8', {button: 'right'});
@ -263,14 +263,14 @@ describe('Page.click', function() {
});
// @see https://github.com/puppeteer/puppeteer/issues/206
itFailsFirefox('should click links which cause navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.setContent(`<a href="${server.EMPTY_PAGE}">empty.html</a>`);
// This await should not hang.
await page.click('a');
});
itFailsFirefox('should click the button inside an iframe', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setContent('<div style="width:100px;height:100px">spacer</div>');
@ -282,7 +282,7 @@ describe('Page.click', function() {
});
// @see https://github.com/puppeteer/puppeteer/issues/4110
xit('should click the button with fixed position inside an iframe', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setViewport({width: 500, height: 500});
@ -294,7 +294,7 @@ describe('Page.click', function() {
expect(await frame.evaluate(() => window.result)).toBe('Clicked');
});
itFailsFirefox('should click the button with deviceScaleFactor set', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.setViewport({width: 400, height: 400, deviceScaleFactor: 5});
expect(await page.evaluate(() => window.devicePixelRatio)).toBe(5);

View File

@ -153,7 +153,7 @@ describe('Cookie specs', () => {
});
describe('Page.setCookie', function() {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -163,7 +163,7 @@ describe('Cookie specs', () => {
expect(await page.evaluate(() => document.cookie)).toEqual('password=123456');
});
itFailsFirefox('should isolate cookies in browser contexts', async() => {
const { page, server, browser } = getTestState();
const {page, server, browser} = getTestState();
const anotherContext = await browser.createIncognitoBrowserContext();
const anotherPage = await anotherContext.newPage();
@ -185,7 +185,7 @@ describe('Cookie specs', () => {
await anotherContext.close();
});
itFailsFirefox('should set multiple cookies', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -204,7 +204,7 @@ describe('Cookie specs', () => {
]);
});
itFailsFirefox('should have |expires| set to |-1| for session cookies', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -216,7 +216,7 @@ describe('Cookie specs', () => {
expect(cookies[0].expires).toBe(-1);
});
itFailsFirefox('should set cookie with reasonable defaults', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -237,7 +237,7 @@ describe('Cookie specs', () => {
}]);
});
itFailsFirefox('should set a cookie with a path', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/grid.html');
await page.setCookie({
@ -264,7 +264,7 @@ describe('Cookie specs', () => {
expect(await page.evaluate('document.cookie')).toBe('gridcookie=GRID');
});
it('should not set a cookie on a blank page', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.goto('about:blank');
let error = null;
@ -276,7 +276,7 @@ describe('Cookie specs', () => {
expect(error.message).toContain('At least one of the url and domain needs to be specified');
});
it('should not set a cookie with blank page URL', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let error = null;
await page.goto(server.EMPTY_PAGE);
@ -293,7 +293,7 @@ describe('Cookie specs', () => {
);
});
it('should not set a cookie on a data URL page', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.goto('data:,Hello%2C%20World!');
@ -305,7 +305,7 @@ describe('Cookie specs', () => {
expect(error.message).toContain('At least one of the url and domain needs to be specified');
});
itFailsFirefox('should default to setting secure cookie for HTTPS websites', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const SECURE_URL = 'https://example.com';
@ -318,7 +318,7 @@ describe('Cookie specs', () => {
expect(cookie.secure).toBe(true);
});
itFailsFirefox('should be able to set unsecure cookie for HTTP website', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const HTTP_URL = 'http://example.com';
@ -331,7 +331,7 @@ describe('Cookie specs', () => {
expect(cookie.secure).toBe(false);
});
itFailsFirefox('should set a cookie on a different domain', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -354,7 +354,7 @@ describe('Cookie specs', () => {
}]);
});
itFailsFirefox('should set cookies from a frame', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/grid.html');
await page.setCookie({name: 'localhost-cookie', value: 'best'});
@ -399,7 +399,7 @@ describe('Cookie specs', () => {
describe('Page.deleteCookie', function() {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({

View File

@ -23,19 +23,19 @@ describe('Coverage specs', function() {
setupTestPageAndContextHooks();
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/simple.html', {waitUntil: 'networkidle0'});
const coverage = await page.coverage.stopJSCoverage();
expect(coverage.length).toBe(1);
expect(coverage[0].url).toContain('/jscoverage/simple.html');
expect(coverage[0].ranges).toEqual([
{ start: 0, end: 17 },
{ start: 35, end: 61 },
{start: 0, end: 17},
{start: 35, end: 61},
]);
});
it('should report sourceURLs', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/sourceurl.html');
@ -44,7 +44,7 @@ describe('Coverage specs', function() {
expect(coverage[0].url).toBe('nicename.js');
});
it('should ignore eval() scripts by default', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/eval.html');
@ -52,7 +52,7 @@ describe('Coverage specs', function() {
expect(coverage.length).toBe(1);
});
it('shouldn\'t ignore eval() scripts if reportAnonymousScripts is true', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage({reportAnonymousScripts: true});
await page.goto(server.PREFIX + '/jscoverage/eval.html');
@ -61,7 +61,7 @@ describe('Coverage specs', function() {
expect(coverage.length).toBe(2);
});
it('should ignore pptr internal scripts if reportAnonymousScripts is true', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage({reportAnonymousScripts: true});
await page.goto(server.EMPTY_PAGE);
@ -71,7 +71,7 @@ describe('Coverage specs', function() {
expect(coverage.length).toBe(0);
});
it('should report multiple scripts', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
@ -82,7 +82,7 @@ describe('Coverage specs', function() {
expect(coverage[1].url).toContain('/jscoverage/script2.js');
});
it('should report right ranges', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/ranges.html');
@ -94,7 +94,7 @@ describe('Coverage specs', function() {
expect(entry.text.substring(range.start, range.end)).toBe(`console.log('used!');`);
});
it('should report scripts that have no coverage', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/unused.html');
@ -105,7 +105,7 @@ describe('Coverage specs', function() {
expect(entry.ranges.length).toBe(0);
});
it('should work with conditionals', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.PREFIX + '/jscoverage/involved.html');
@ -114,7 +114,7 @@ describe('Coverage specs', function() {
});
describe('resetOnNavigation', function() {
it('should report scripts across navigations when disabled', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage({resetOnNavigation: false});
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
@ -124,7 +124,7 @@ describe('Coverage specs', function() {
});
it('should NOT report scripts across navigations when enabled', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage(); // Enabled by default.
await page.goto(server.PREFIX + '/jscoverage/multiple.html');
@ -135,7 +135,7 @@ describe('Coverage specs', function() {
});
// @see https://crbug.com/990945
xit('should not hang when there is a debugger statement', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startJSCoverage();
await page.goto(server.EMPTY_PAGE);
@ -151,7 +151,7 @@ describe('Coverage specs', function() {
setupTestPageAndContextHooks();
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/simple.html');
@ -165,7 +165,7 @@ describe('Coverage specs', function() {
expect(coverage[0].text.substring(range.start, range.end)).toBe('div { color: green; }');
});
it('should report sourceURLs', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/sourceurl.html');
@ -174,7 +174,7 @@ describe('Coverage specs', function() {
expect(coverage[0].url).toBe('nicename.css');
});
it('should report multiple stylesheets', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/multiple.html');
@ -185,7 +185,7 @@ describe('Coverage specs', function() {
expect(coverage[1].url).toContain('/csscoverage/stylesheet2.css');
});
it('should report stylesheets that have no coverage', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/unused.html');
@ -195,7 +195,7 @@ describe('Coverage specs', function() {
expect(coverage[0].ranges.length).toBe(0);
});
it('should work with media queries', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/media.html');
@ -207,7 +207,7 @@ describe('Coverage specs', function() {
]);
});
it('should work with complicated usecases', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.goto(server.PREFIX + '/csscoverage/involved.html');
@ -215,7 +215,7 @@ describe('Coverage specs', function() {
expect(JSON.stringify(coverage, null, 2).replace(/:\d{4}\//g, ':<PORT>/')).toBeGolden('csscoverage-involved.txt');
});
it('should ignore injected stylesheets', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.coverage.startCSSCoverage();
await page.addStyleTag({content: 'body { margin: 10px;}'});
@ -227,7 +227,7 @@ describe('Coverage specs', function() {
});
describe('resetOnNavigation', function() {
it('should report stylesheets across navigations', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage({resetOnNavigation: false});
await page.goto(server.PREFIX + '/csscoverage/multiple.html');
@ -236,7 +236,7 @@ describe('Coverage specs', function() {
expect(coverage.length).toBe(2);
});
it('should NOT report scripts across navigations', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage(); // Enabled by default.
await page.goto(server.PREFIX + '/csscoverage/multiple.html');
@ -246,7 +246,7 @@ describe('Coverage specs', function() {
});
});
it('should work with a recently loaded stylesheet', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.coverage.startCSSCoverage();
await page.evaluate(async url => {

View File

@ -20,7 +20,7 @@ describe('DefaultBrowserContext', function() {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
itFailsFirefox('page.cookies() should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
@ -39,7 +39,7 @@ describe('DefaultBrowserContext', function() {
}]);
});
itFailsFirefox('page.setCookie() should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({
@ -60,7 +60,7 @@ describe('DefaultBrowserContext', function() {
}]);
});
itFailsFirefox('page.deleteCookie() should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setCookie({

View File

@ -20,7 +20,7 @@ describe('Page.Events.Dialog', function() {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
it('should fire', async() => {
const { page } = getTestState();
const {page} = getTestState();
page.on('dialog', dialog => {
expect(dialog.type()).toBe('alert');
@ -31,7 +31,7 @@ describe('Page.Events.Dialog', function() {
await page.evaluate(() => alert('yo'));
});
itFailsFirefox('should allow accepting prompts', async() => {
const { page } = getTestState();
const {page} = getTestState();
page.on('dialog', dialog => {
expect(dialog.type()).toBe('prompt');
@ -43,7 +43,7 @@ describe('Page.Events.Dialog', function() {
expect(result).toBe('answer!');
});
it('should dismiss the prompt', async() => {
const { page } = getTestState();
const {page} = getTestState();
page.on('dialog', dialog => {
dialog.dismiss();

View File

@ -25,16 +25,16 @@ describe('ElementHandle specs', function() {
describeFailsFirefox('ElementHandle.boundingBox', 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');
const elementHandle = await page.$('.box:nth-of-type(13)');
const box = await elementHandle.boundingBox();
expect(box).toEqual({ x: 100, y: 50, width: 50, height: 50 });
expect(box).toEqual({x: 100, y: 50, width: 50, height: 50});
});
it('should handle nested frames', async() => {
const { page, server, isChrome } = getTestState();
const {page, server, isChrome} = getTestState();
await page.setViewport({width: 500, height: 500});
await page.goto(server.PREFIX + '/frames/nested-frames.html');
@ -42,29 +42,29 @@ describe('ElementHandle specs', function() {
const elementHandle = await nestedFrame.$('div');
const box = await elementHandle.boundingBox();
if (isChrome)
expect(box).toEqual({ x: 28, y: 260, width: 264, height: 18 });
expect(box).toEqual({x: 28, y: 260, width: 264, height: 18});
else
expect(box).toEqual({ x: 28, y: 182, width: 254, height: 18 });
expect(box).toEqual({x: 28, y: 182, width: 254, height: 18});
});
it('should return null for invisible elements', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<div style="display:none">hi</div>');
const element = await page.$('div');
expect(await element.boundingBox()).toBe(null);
});
it('should force a layout', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setViewport({ width: 500, height: 500 });
await page.setViewport({width: 500, height: 500});
await page.setContent('<div style="width: 100px; height: 100px">hello</div>');
const elementHandle = await page.$('div');
await page.evaluate(element => element.style.height = '200px', elementHandle);
const box = await elementHandle.boundingBox();
expect(box).toEqual({ x: 8, y: 8, width: 100, height: 200 });
expect(box).toEqual({x: 8, y: 8, width: 100, height: 200});
});
it('should work with SVG nodes', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
@ -83,7 +83,7 @@ describe('ElementHandle specs', function() {
describeFailsFirefox('ElementHandle.boxModel', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/resetcss.html');
@ -140,7 +140,7 @@ describe('ElementHandle specs', function() {
});
it('should return null for invisible elements', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<div style="display:none">hi</div>');
const element = await page.$('div');
@ -150,7 +150,7 @@ describe('ElementHandle specs', function() {
describe('ElementHandle.contentFrame', function() {
itFailsFirefox('should work', async() => {
const { page,server } = getTestState();
const {page,server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
@ -162,7 +162,7 @@ describe('ElementHandle specs', function() {
describe('ElementHandle.click', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button');
@ -170,7 +170,7 @@ describe('ElementHandle specs', function() {
expect(await page.evaluate(() => result)).toBe('Clicked');
});
it('should work for Shadow DOM v1', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/shadow.html');
const buttonHandle = await page.evaluateHandle(() => button);
@ -178,7 +178,7 @@ describe('ElementHandle specs', function() {
expect(await page.evaluate(() => clicked)).toBe(true);
});
it('should work for TextNodes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);
@ -187,7 +187,7 @@ describe('ElementHandle specs', function() {
expect(error.message).toBe('Node is not of type HTMLElement');
});
it('should throw for detached nodes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button');
@ -197,7 +197,7 @@ describe('ElementHandle specs', function() {
expect(error.message).toBe('Node is detached from document');
});
it('should throw for hidden nodes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button');
@ -206,7 +206,7 @@ describe('ElementHandle specs', function() {
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
});
it('should throw for recursively hidden nodes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button');
@ -215,7 +215,7 @@ describe('ElementHandle specs', function() {
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
});
itFailsFirefox('should throw for <br> elements', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('hello<br>goodbye');
const br = await page.$('br');
@ -226,7 +226,7 @@ describe('ElementHandle specs', function() {
describe('ElementHandle.hover', function() {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
const button = await page.$('#button-6');
@ -237,7 +237,7 @@ describe('ElementHandle specs', function() {
describe('ElementHandle.isIntersectingViewport', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/offscreenbuttons.html');
for (let i = 0; i < 11; ++i) {

View File

@ -32,14 +32,14 @@ describe('Emulation', () => {
describe('Page.viewport', function() {
it('should get the proper viewport size', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(page.viewport()).toEqual({width: 800, height: 600});
await page.setViewport({width: 123, height: 456});
expect(page.viewport()).toEqual({width: 123, height: 456});
});
it('should support mobile emulation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/mobile.html');
expect(await page.evaluate(() => window.innerWidth)).toBe(800);
@ -49,7 +49,7 @@ describe('Emulation', () => {
expect(await page.evaluate(() => window.innerWidth)).toBe(400);
});
itFailsFirefox('should support touch emulation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/mobile.html');
expect(await page.evaluate(() => 'ontouchstart' in window)).toBe(false);
@ -73,7 +73,7 @@ describe('Emulation', () => {
}
});
itFailsFirefox('should be detectable by Modernizr', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/detect-touch.html');
expect(await page.evaluate(() => document.body.textContent.trim())).toBe('NO');
@ -82,14 +82,14 @@ describe('Emulation', () => {
expect(await page.evaluate(() => document.body.textContent.trim())).toBe('YES');
});
itFailsFirefox('should detect touch when applying viewport with touches', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.setViewport({ width: 800, height: 600, hasTouch: true });
await page.setViewport({width: 800, height: 600, hasTouch: true});
await page.addScriptTag({url: server.PREFIX + '/modernizr.js'});
expect(await page.evaluate(() => Modernizr.touchevents)).toBe(true);
});
itFailsFirefox('should support landscape emulation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/mobile.html');
expect(await page.evaluate(() => screen.orientation.type)).toBe('portrait-primary');
@ -102,7 +102,7 @@ describe('Emulation', () => {
describe('Page.emulate', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/mobile.html');
await page.emulate(iPhone);
@ -110,7 +110,7 @@ describe('Emulation', () => {
expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone');
});
it('should support clicking', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.emulate(iPhone);
await page.goto(server.PREFIX + '/input/button.html');
@ -133,7 +133,7 @@ describe('Emulation', () => {
* tests, and vice-versa.
*/
itFailsFirefox('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
@ -145,7 +145,7 @@ describe('Emulation', () => {
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
});
it('should throw in case of bad argument', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.emulateMedia('bad').catch(e => error = e);
@ -158,7 +158,7 @@ describe('Emulation', () => {
* too (and see the big comment for why we have these duplicated).
*/
itFailsFirefox('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(await page.evaluate(() => matchMedia('screen').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
@ -170,7 +170,7 @@ describe('Emulation', () => {
expect(await page.evaluate(() => matchMedia('print').matches)).toBe(false);
});
it('should throw in case of bad argument', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.emulateMediaType('bad').catch(e => error = e);
@ -180,28 +180,28 @@ describe('Emulation', () => {
describe('Page.emulateMediaFeatures', function() {
itFailsFirefox('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.emulateMediaFeatures([
{ name: 'prefers-reduced-motion', value: 'reduce' },
{name: 'prefers-reduced-motion', value: 'reduce'},
]);
expect(await page.evaluate(() => matchMedia('(prefers-reduced-motion: reduce)').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('(prefers-reduced-motion: no-preference)').matches)).toBe(false);
await page.emulateMediaFeatures([
{ name: 'prefers-color-scheme', value: 'light' },
{name: 'prefers-color-scheme', value: 'light'},
]);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches)).toBe(false);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches)).toBe(false);
await page.emulateMediaFeatures([
{ name: 'prefers-color-scheme', value: 'dark' },
{name: 'prefers-color-scheme', value: 'dark'},
]);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches)).toBe(false);
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches)).toBe(false);
await page.emulateMediaFeatures([
{ name: 'prefers-reduced-motion', value: 'reduce' },
{ name: 'prefers-color-scheme', value: 'light' },
{name: 'prefers-reduced-motion', value: 'reduce'},
{name: 'prefers-color-scheme', value: 'light'},
]);
expect(await page.evaluate(() => matchMedia('(prefers-reduced-motion: reduce)').matches)).toBe(true);
expect(await page.evaluate(() => matchMedia('(prefers-reduced-motion: no-preference)').matches)).toBe(false);
@ -210,17 +210,17 @@ describe('Emulation', () => {
expect(await page.evaluate(() => matchMedia('(prefers-color-scheme: no-preference)').matches)).toBe(false);
});
it('should throw in case of bad argument', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.emulateMediaFeatures([{ name: 'bad', value: '' }]).catch(e => error = e);
await page.emulateMediaFeatures([{name: 'bad', value: ''}]).catch(e => error = e);
expect(error.message).toBe('Unsupported media feature: bad');
});
});
describeFailsFirefox('Page.emulateTimezone', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
page.evaluate(() => {
globalThis.date = new Date(1479579154987);
@ -239,7 +239,7 @@ describe('Emulation', () => {
});
it('should throw for invalid timezone IDs', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.emulateTimezone('Foo/Bar').catch(e => error = e);

View File

@ -27,72 +27,72 @@ describe('Evaluation specs', function() {
describe('Page.evaluate', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => 7 * 3);
expect(result).toBe(21);
});
(bigint ? itFailsFirefox : xit)('should transfer BigInt', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, BigInt(42));
expect(result).toBe(BigInt(42));
});
itFailsFirefox('should transfer NaN', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, NaN);
expect(Object.is(result, NaN)).toBe(true);
});
itFailsFirefox('should transfer -0', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, -0);
expect(Object.is(result, -0)).toBe(true);
});
itFailsFirefox('should transfer Infinity', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, Infinity);
expect(Object.is(result, Infinity)).toBe(true);
});
itFailsFirefox('should transfer -Infinity', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, -Infinity);
expect(Object.is(result, -Infinity)).toBe(true);
});
it('should transfer arrays', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a, [1, 2, 3]);
expect(result).toEqual([1,2,3]);
});
it('should transfer arrays as arrays, not objects', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => Array.isArray(a), [1, 2, 3]);
expect(result).toBe(true);
});
it('should modify global environment', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.evaluate(() => window.globalVar = 123);
expect(await page.evaluate('globalVar')).toBe(123);
});
it('should evaluate in the page context', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/global-var.html');
expect(await page.evaluate('globalVar')).toBe(123);
});
itFailsFirefox('should return undefined for objects with symbols', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(await page.evaluate(() => [Symbol('foo4')])).toBe(undefined);
});
it('should work with function shorthands', async() => {
const { page } = getTestState();
const {page} = getTestState();
const a = {
sum(a, b) { return a + b; },
@ -103,13 +103,13 @@ describe('Evaluation specs', function() {
expect(await page.evaluate(a.mult, 2, 4)).toBe(8);
});
it('should work with unicode chars', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(a => a['中文字符'], {'中文字符': 42});
expect(result).toBe(42);
});
itFailsFirefox('should throw when evaluation triggers reload', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.evaluate(() => {
@ -119,13 +119,13 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('Protocol error');
});
it('should await promise', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => Promise.resolve(8 * 7));
expect(result).toBe(56);
});
it('should work right after framenavigated', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let frameEvaluation = null;
page.on('framenavigated', async frame => {
@ -135,7 +135,7 @@ describe('Evaluation specs', function() {
expect(await frameEvaluation).toBe(42);
});
itFailsFirefox('should work from-inside an exposed function', async() => {
const { page } = getTestState();
const {page} = getTestState();
// Setup inpage callback, which calls Page.evaluate
await page.exposeFunction('callController', async function(a, b) {
@ -147,7 +147,7 @@ describe('Evaluation specs', function() {
expect(result).toBe(27);
});
it('should reject promise with exception', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.evaluate(() => not_existing_object.property).catch(e => error = e);
@ -155,7 +155,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('not_existing_object');
});
it('should support thrown strings as error messages', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.evaluate(() => { throw 'qwerty'; }).catch(e => error = e);
@ -163,7 +163,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('qwerty');
});
it('should support thrown numbers as error messages', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.evaluate(() => { throw 100500; }).catch(e => error = e);
@ -171,7 +171,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('100500');
});
it('should return complex objects', async() => {
const { page } = getTestState();
const {page} = getTestState();
const object = {foo: 'bar!'};
const result = await page.evaluate(a => a, object);
@ -179,53 +179,53 @@ describe('Evaluation specs', function() {
expect(result).toEqual(object);
});
(bigint ? itFailsFirefox : xit)('should return BigInt', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => BigInt(42));
expect(result).toBe(BigInt(42));
});
itFailsFirefox('should return NaN', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => NaN);
expect(Object.is(result, NaN)).toBe(true);
});
itFailsFirefox('should return -0', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => -0);
expect(Object.is(result, -0)).toBe(true);
});
itFailsFirefox('should return Infinity', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => Infinity);
expect(Object.is(result, Infinity)).toBe(true);
});
itFailsFirefox('should return -Infinity', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => -Infinity);
expect(Object.is(result, -Infinity)).toBe(true);
});
it('should accept "undefined" as one of multiple parameters', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate((a, b) => Object.is(a, undefined) && Object.is(b, 'foo'), undefined, 'foo');
expect(result).toBe(true);
});
it('should properly serialize null fields', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(await page.evaluate(() => ({a: undefined}))).toEqual({});
});
itFailsFirefox('should return undefined for non-serializable objects', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect(await page.evaluate(() => window)).toBe(undefined);
});
itFailsFirefox('should fail for circular object', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => {
const a = {};
@ -236,7 +236,7 @@ describe('Evaluation specs', function() {
expect(result).toBe(undefined);
});
itFailsFirefox('should be able to throw a tricky error', async() => {
const { page } = getTestState();
const {page} = getTestState();
const windowHandle = await page.evaluateHandle(() => window);
const errorText = await windowHandle.jsonValue().catch(e => e.message);
@ -246,25 +246,25 @@ describe('Evaluation specs', function() {
expect(error.message).toContain(errorText);
});
it('should accept a string', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate('1 + 2');
expect(result).toBe(3);
});
it('should accept a string with semi colons', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate('1 + 5;');
expect(result).toBe(6);
});
it('should accept a string with comments', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate('2 + 5;\n// do some math!');
expect(result).toBe(7);
});
itFailsFirefox('should accept element handle as an argument', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<section>42</section>');
const element = await page.$('section');
@ -272,7 +272,7 @@ describe('Evaluation specs', function() {
expect(text).toBe('42');
});
itFailsFirefox('should throw if underlying element was disposed', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<section>39</section>');
const element = await page.$('section');
@ -283,7 +283,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('JSHandle is disposed');
});
itFailsFirefox('should throw if elementHandles are from other frames', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
const bodyHandle = await page.frames()[1].$('body');
@ -293,7 +293,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created');
});
itFailsFirefox('should simulate a user gesture', async() => {
const { page } = getTestState();
const {page} = getTestState();
const result = await page.evaluate(() => {
document.body.appendChild(document.createTextNode('test'));
@ -303,7 +303,7 @@ describe('Evaluation specs', function() {
expect(result).toBe(true);
});
itFailsFirefox('should throw a nice error after a navigation', async() => {
const { page } = getTestState();
const {page} = getTestState();
const executionContext = await page.mainFrame().executionContext();
@ -315,7 +315,7 @@ describe('Evaluation specs', function() {
expect(error.message).toContain('navigation');
});
itFailsFirefox('should not throw an error when evaluation does a navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/one-style.html');
const result = await page.evaluate(() => {
@ -325,13 +325,13 @@ describe('Evaluation specs', function() {
expect(result).toEqual([42]);
});
itFailsFirefox('should transfer 100Mb of data from page to node.js', async function() {
const { page } = getTestState();
const {page} = getTestState();
const a = await page.evaluate(() => Array(100 * 1024 * 1024 + 1).join('a'));
expect(a.length).toBe(100 * 1024 * 1024);
});
it('should throw error with detailed information on exception inside promise ', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
await page.evaluate(() => new Promise(() => {
@ -343,7 +343,7 @@ describe('Evaluation specs', function() {
describeFailsFirefox('Page.evaluateOnNewDocument', function() {
it('should evaluate before anything else on the page', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.evaluateOnNewDocument(function(){
window.injected = 123;
@ -352,7 +352,7 @@ describe('Evaluation specs', function() {
expect(await page.evaluate(() => window.result)).toBe(123);
});
it('should work with CSP', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setCSP('/empty.html', 'script-src ' + server.PREFIX);
await page.evaluateOnNewDocument(function(){
@ -369,7 +369,7 @@ describe('Evaluation specs', function() {
describe('Frame.evaluate', function() {
itFailsFirefox('should have different execution contexts', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
@ -380,7 +380,7 @@ describe('Evaluation specs', function() {
expect(await page.frames()[1].evaluate(() => window.FOO)).toBe('bar');
});
itFailsFirefox('should have correct execution contexts', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames().length).toBe(2);
@ -388,7 +388,7 @@ describe('Evaluation specs', function() {
expect(await page.frames()[1].evaluate(() => document.body.textContent.trim())).toBe(`Hi, I'm frame`);
});
it('should execute after cross-site navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const mainFrame = page.mainFrame();

View File

@ -21,7 +21,7 @@ const path = require('path');
describe('Fixtures', function() {
itFailsFirefox('dumpio option should work with pipe option ', async() => {
const { defaultBrowserOptions, puppeteerPath } = getTestState();
const {defaultBrowserOptions, puppeteerPath} = getTestState();
let dumpioData = '';
const {spawn} = require('child_process');
@ -33,7 +33,7 @@ describe('Fixtures', function() {
expect(dumpioData).toContain('message from dumpio');
});
it('should dump browser process stderr', async() => {
const { defaultBrowserOptions, puppeteerPath} = getTestState();
const {defaultBrowserOptions, puppeteerPath} = getTestState();
let dumpioData = '';
const {spawn} = require('child_process');
@ -45,7 +45,7 @@ describe('Fixtures', function() {
expect(dumpioData).toContain('DevTools listening on ws://');
});
it('should close the browser when the node process closes', async() => {
const { defaultBrowserOptions, puppeteerPath, puppeteer} = getTestState();
const {defaultBrowserOptions, puppeteerPath, puppeteer} = getTestState();
const {spawn, execSync} = require('child_process');
const options = Object.assign({}, defaultBrowserOptions, {
@ -61,7 +61,7 @@ describe('Fixtures', function() {
if (output.indexOf('\n'))
wsEndPointCallback(output.substring(0, output.indexOf('\n')));
});
const browser = await puppeteer.connect({ browserWSEndpoint: await wsEndPointPromise });
const browser = await puppeteer.connect({browserWSEndpoint: await wsEndPointPromise});
const promises = [
new Promise(resolve => browser.once('disconnected', resolve)),
new Promise(resolve => res.on('close', resolve))

View File

@ -24,7 +24,7 @@ describe('Frame specs', function() {
describe('Frame.executionContext', function() {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
@ -53,7 +53,7 @@ describe('Frame specs', function() {
describe('Frame.evaluateHandle', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const mainFrame = page.mainFrame();
@ -64,7 +64,7 @@ describe('Frame specs', function() {
describe('Frame.evaluate', function() {
itFailsFirefox('should throw for detached frames', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const frame1 = await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
await utils.detachFrame(page, 'frame1');
@ -76,7 +76,7 @@ describe('Frame specs', function() {
describe('Frame Management', function() {
itFailsFirefox('should handle nested frames', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/nested-frames.html');
expect(utils.dumpFrames(page.mainFrame())).toEqual([
@ -88,7 +88,7 @@ describe('Frame specs', function() {
]);
});
itFailsFirefox('should send events when frames are manipulated dynamically', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
// validate frameattached events
@ -113,7 +113,7 @@ describe('Frame specs', function() {
expect(detachedFrames[0].isDetached()).toBe(true);
});
itFailsFirefox('should send "framenavigated" when navigating on anchor URLs', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await Promise.all([
@ -123,7 +123,7 @@ describe('Frame specs', function() {
expect(page.url()).toBe(server.EMPTY_PAGE + '#foo');
});
it('should persist mainFrame on cross-process navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const mainFrame = page.mainFrame();
@ -131,7 +131,7 @@ describe('Frame specs', function() {
expect(page.mainFrame() === mainFrame).toBeTruthy();
});
it('should not send attach/detach events for main frame', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let hasEvents = false;
page.on('frameattached', frame => hasEvents = true);
@ -140,7 +140,7 @@ describe('Frame specs', function() {
expect(hasEvents).toBe(false);
});
itFailsFirefox('should detach child frames on navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let attachedFrames = [];
let detachedFrames = [];
@ -162,7 +162,7 @@ describe('Frame specs', function() {
expect(navigatedFrames.length).toBe(1);
});
itFailsFirefox('should support framesets', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let attachedFrames = [];
let detachedFrames = [];
@ -184,7 +184,7 @@ describe('Frame specs', function() {
expect(navigatedFrames.length).toBe(1);
});
itFailsFirefox('should report frame from-inside shadow DOM', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/shadow.html');
await page.evaluate(async url => {
@ -197,7 +197,7 @@ describe('Frame specs', function() {
expect(page.frames()[1].url()).toBe(server.EMPTY_PAGE);
});
itFailsFirefox('should report frame.name()', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await utils.attachFrame(page, 'theFrameId', server.EMPTY_PAGE);
await page.evaluate(url => {
@ -212,7 +212,7 @@ describe('Frame specs', function() {
expect(page.frames()[2].name()).toBe('theFrameName');
});
itFailsFirefox('should report frame.parent()', 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);
@ -221,7 +221,7 @@ describe('Frame specs', function() {
expect(page.frames()[2].parentFrame()).toBe(page.mainFrame());
});
itFailsFirefox('should report different frame instance when frame re-attaches', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const frame1 = await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
await page.evaluate(() => {

View File

@ -38,7 +38,7 @@ const GoldenComparators = {
*/
function compareImages(actualBuffer, expectedBuffer, mimeType) {
if (!actualBuffer || !(actualBuffer instanceof Buffer))
return { errorMessage: 'Actual result should be Buffer.' };
return {errorMessage: 'Actual result should be Buffer.'};
const actual = mimeType === 'image/png' ? PNG.sync.read(actualBuffer) : jpeg.decode(actualBuffer);
const expected = mimeType === 'image/png' ? PNG.sync.read(expectedBuffer) : jpeg.decode(expectedBuffer);
@ -49,7 +49,7 @@ function compareImages(actualBuffer, expectedBuffer, mimeType) {
}
const diff = new PNG({width: expected.width, height: expected.height});
const count = pixelmatch(expected.data, actual.data, diff.data, expected.width, expected.height, {threshold: 0.1});
return count > 0 ? { diff: PNG.sync.write(diff) } : null;
return count > 0 ? {diff: PNG.sync.write(diff)} : null;
}
/**
@ -59,7 +59,7 @@ function compareImages(actualBuffer, expectedBuffer, mimeType) {
*/
function compareText(actual, expectedBuffer) {
if (typeof actual !== 'string')
return { errorMessage: 'Actual result should be string' };
return {errorMessage: 'Actual result should be string'};
const expected = expectedBuffer.toString('utf-8');
if (expected === actual)
return null;
@ -107,7 +107,7 @@ function compare(goldenPath, outputPath, actual, goldenName) {
}
const result = comparator(actual, expected, mimeType);
if (!result)
return { pass: true };
return {pass: true};
ensureOutputDir();
if (goldenPath === outputPath) {
fs.writeFileSync(addSuffix(actualPath, '-actual'), actual);

View File

@ -93,7 +93,7 @@ describeChromeOnly('headful tests', function() {
*/
new Date('2020-06-01'),
'headless should be able to read cookies written by headful', async() => {
const { server, puppeteer } = getTestState();
const {server, puppeteer} = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
// Write a cookie in headful chrome
@ -114,7 +114,7 @@ describeChromeOnly('headful tests', function() {
});
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
xit('OOPIF: should report google.com frame', async() => {
const { server } = getTestState();
const {server} = getTestState();
// https://google.com is isolated by default in Chromium embedder.
const browser = await puppeteer.launch(headfulOptions);
@ -137,7 +137,7 @@ describeChromeOnly('headful tests', function() {
await browser.close();
});
it('should close browser with beforeunload page', async() => {
const { server, puppeteer } = getTestState();
const {server, puppeteer} = getTestState();
const browser = await puppeteer.launch(headfulOptions);
const page = await browser.newPage();

View File

@ -50,7 +50,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
describe('Response.securityDetails', function() {
it('should work', async() => {
const { httpsServer } = getTestState();
const {httpsServer} = getTestState();
const [serverRequest, response] = await Promise.all([
httpsServer.waitForRequest('/empty.html'),
@ -65,13 +65,13 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
expect(securityDetails.validTo()).toBe(33086084863);
});
it('should be |null| for non-secure requests', async() => {
const { server } = getTestState();
const {server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.securityDetails()).toBe(null);
});
it('Network redirects should report SecurityDetails', async() => {
const { httpsServer } = getTestState();
const {httpsServer} = getTestState();
httpsServer.setRedirect('/plzredirect', '/empty.html');
const responses = [];
@ -89,7 +89,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
});
it('should work', async() => {
const { httpsServer } = getTestState();
const {httpsServer} = getTestState();
let error = null;
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
@ -97,7 +97,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
expect(response.ok()).toBe(true);
});
it('should work with request interception', async() => {
const { httpsServer } = getTestState();
const {httpsServer} = getTestState();
await page.setRequestInterception(true);
page.on('request', request => request.continue());
@ -105,7 +105,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
expect(response.status()).toBe(200);
});
it('should work with mixed content', async() => {
const { server, httpsServer } = getTestState();
const {server, httpsServer} = getTestState();
httpsServer.setRoute('/mixedcontent.html', (req, res) => {
res.end(`<iframe src=${server.EMPTY_PAGE}></iframe>`);

View File

@ -26,7 +26,7 @@ describe('input tests', function() {
describeFailsFirefox('input', function() {
it('should upload the file', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/fileupload.html');
const filePath = path.relative(process.cwd(), FILE_TO_UPLOAD);
@ -51,7 +51,7 @@ describe('input tests', function() {
describeFailsFirefox('Page.waitForFileChooser', function() {
it('should work when file input is attached to DOM', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [chooser] = await Promise.all([
@ -61,7 +61,7 @@ describe('input tests', function() {
expect(chooser).toBeTruthy();
});
it('should work when file input is not attached to DOM', async() => {
const { page } = getTestState();
const {page} = getTestState();
const [chooser] = await Promise.all([
page.waitForFileChooser(),
@ -74,14 +74,14 @@ describe('input tests', function() {
expect(chooser).toBeTruthy();
});
it('should respect timeout', async() => {
const { page, puppeteer } = getTestState();
const {page, puppeteer} = getTestState();
let error = null;
await page.waitForFileChooser({timeout: 1}).catch(e => error = e);
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should respect default timeout when there is no custom timeout', async() => {
const { page, puppeteer } = getTestState();
const {page, puppeteer} = getTestState();
page.setDefaultTimeout(1);
let error = null;
@ -89,7 +89,7 @@ describe('input tests', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should prioritize exact timeout over default timeout', async() => {
const { page, puppeteer } = getTestState();
const {page, puppeteer} = getTestState();
page.setDefaultTimeout(0);
let error = null;
@ -97,7 +97,7 @@ describe('input tests', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should work with no timeout', async() => {
const { page } = getTestState();
const {page} = getTestState();
const [chooser] = await Promise.all([
page.waitForFileChooser({timeout: 0}),
@ -110,7 +110,7 @@ describe('input tests', function() {
expect(chooser).toBeTruthy();
});
it('should return the same file chooser when there are many watchdogs simultaneously', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [fileChooser1, fileChooser2] = await Promise.all([
@ -124,7 +124,7 @@ describe('input tests', function() {
describeFailsFirefox('FileChooser.accept', function() {
it('should accept single file', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file oninput='javascript:console.timeStamp()'>`);
const [chooser] = await Promise.all([
@ -139,7 +139,7 @@ describe('input tests', function() {
expect(await page.$eval('input', input => input.files[0].name)).toBe('file-to-upload.txt');
});
it('should be able to read selected file', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
page.waitForFileChooser().then(chooser => chooser.accept([FILE_TO_UPLOAD]));
@ -153,7 +153,7 @@ describe('input tests', function() {
})).toBe('contents of the file');
});
it('should be able to reset selected files with empty file list', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
page.waitForFileChooser().then(chooser => chooser.accept([FILE_TO_UPLOAD]));
@ -170,7 +170,7 @@ describe('input tests', function() {
})).toBe(0);
});
it('should not accept multiple files for single-file input', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [chooser] = await Promise.all([
@ -185,7 +185,7 @@ describe('input tests', function() {
expect(error).not.toBe(null);
});
it('should fail when accepting file chooser twice', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [fileChooser] = await Promise.all([
@ -201,7 +201,7 @@ describe('input tests', function() {
describeFailsFirefox('FileChooser.cancel', function() {
it('should cancel dialog', async() => {
const { page } = getTestState();
const {page} = getTestState();
// Consider file chooser canceled if we can summon another one.
// There's no reliable way in WebPlatform to see that FileChooser was
@ -219,7 +219,7 @@ describe('input tests', function() {
]);
});
it('should fail when canceling file chooser twice', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [fileChooser] = await Promise.all([
@ -235,7 +235,7 @@ describe('input tests', function() {
describeFailsFirefox('FileChooser.isMultiple', () => {
it('should work for single file pick', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input type=file>`);
const [chooser] = await Promise.all([
@ -245,7 +245,7 @@ describe('input tests', function() {
expect(chooser.isMultiple()).toBe(false);
});
it('should work for "multiple"', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input multiple type=file>`);
const [chooser] = await Promise.all([
@ -255,7 +255,7 @@ describe('input tests', function() {
expect(chooser.isMultiple()).toBe(true);
});
it('should work for "webkitdirectory"', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent(`<input multiple webkitdirectory type=file>`);
const [chooser] = await Promise.all([

View File

@ -23,44 +23,44 @@ describe('JSHandle', function() {
describe('Page.evaluateHandle', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const windowHandle = await page.evaluateHandle(() => window);
expect(windowHandle).toBeTruthy();
});
it('should accept object handle as an argument', async() => {
const { page } = getTestState();
const {page} = getTestState();
const navigatorHandle = await page.evaluateHandle(() => navigator);
const text = await page.evaluate(e => e.userAgent, navigatorHandle);
expect(text).toContain('Mozilla');
});
it('should accept object handle to primitive types', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => 5);
const isFive = await page.evaluate(e => Object.is(e, 5), aHandle);
expect(isFive).toBeTruthy();
});
it('should warn on nested object handles', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => document.body);
let error = null;
await page.evaluateHandle(
opts => opts.elem.querySelector('p'),
{ elem: aHandle }
{elem: aHandle}
).catch(e => error = e);
expect(error.message).toContain('Are you passing a nested JSHandle?');
});
it('should accept object handle to unserializable value', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => Infinity);
expect(await page.evaluate(e => Object.is(e, Infinity), aHandle)).toBe(true);
});
it('should use the same JS wrappers', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => {
window.FOO = 123;
@ -69,7 +69,7 @@ describe('JSHandle', function() {
expect(await page.evaluate(e => e.FOO, aHandle)).toBe(123);
});
it('should work with primitives', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => {
window.FOO = 123;
@ -81,7 +81,7 @@ describe('JSHandle', function() {
describe('JSHandle.getProperty', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => ({
one: 1,
@ -95,21 +95,21 @@ describe('JSHandle', function() {
describe('JSHandle.jsonValue', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => ({foo: 'bar'}));
const json = await aHandle.jsonValue();
expect(json).toEqual({foo: 'bar'});
});
itFailsFirefox('should not work with dates', async() => {
const { page } = getTestState();
const {page} = getTestState();
const dateHandle = await page.evaluateHandle(() => new Date('2017-09-26T00:00:00.000Z'));
const json = await dateHandle.jsonValue();
expect(json).toEqual({});
});
it('should throw for circular objects', async() => {
const { page, isChrome } = getTestState();
const {page, isChrome} = getTestState();
const windowHandle = await page.evaluateHandle('window');
let error = null;
@ -123,7 +123,7 @@ describe('JSHandle', function() {
describe('JSHandle.getProperties', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => ({
foo: 'bar'
@ -134,7 +134,7 @@ describe('JSHandle', function() {
expect(await foo.jsonValue()).toBe('bar');
});
it('should return even non-own properties', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => {
class A {
@ -158,21 +158,21 @@ describe('JSHandle', function() {
describe('JSHandle.asElement', function() {
it('should work', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => document.body);
const element = aHandle.asElement();
expect(element).toBeTruthy();
});
it('should return null for non-elements', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => 2);
const element = aHandle.asElement();
expect(element).toBeFalsy();
});
itFailsFirefox('should return ElementHandle for TextNodes', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<div>ee!</div>');
const aHandle = await page.evaluateHandle(() => document.querySelector('div').firstChild);
@ -181,7 +181,7 @@ describe('JSHandle', function() {
expect(await page.evaluate(e => e.nodeType === HTMLElement.TEXT_NODE, element));
});
itFailsFirefox('should work with nullified Node', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<section>test</section>');
await page.evaluate(() => delete Node);
@ -193,7 +193,7 @@ describe('JSHandle', function() {
describe('JSHandle.toString', function() {
it('should work for primitives', async() => {
const { page } = getTestState();
const {page} = getTestState();
const numberHandle = await page.evaluateHandle(() => 2);
expect(numberHandle.toString()).toBe('JSHandle:2');
@ -201,13 +201,13 @@ describe('JSHandle', function() {
expect(stringHandle.toString()).toBe('JSHandle:a');
});
it('should work for complicated objects', async() => {
const { page } = getTestState();
const {page} = getTestState();
const aHandle = await page.evaluateHandle(() => window);
expect(aHandle.toString()).toBe('JSHandle@object');
});
it('should work with different subtypes', async() => {
const { page } = getTestState();
const {page} = getTestState();
expect((await page.evaluateHandle('(function(){})')).toString()).toBe('JSHandle@function');
expect((await page.evaluateHandle('12')).toString()).toBe('JSHandle:12');

View File

@ -24,7 +24,7 @@ describe('Keyboard', function() {
setupTestPageAndContextHooks();
it('should type into a textarea', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.evaluate(() => {
const textarea = document.createElement('textarea');
@ -36,7 +36,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe(text);
});
itFailsFirefox('should press the metaKey', async() => {
const { page, isFirefox } = getTestState();
const {page, isFirefox} = getTestState();
await page.evaluate(() => {
window.keyPromise = new Promise(resolve => document.addEventListener('keydown', event => resolve(event.key)));
@ -45,7 +45,7 @@ describe('Keyboard', function() {
expect(await page.evaluate('keyPromise')).toBe(isFirefox && os.platform() !== 'darwin' ? 'OS' : 'Meta');
});
it('should move with the arrow keys', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.type('textarea', 'Hello World!');
@ -62,7 +62,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('Hello World!');
});
it('should send a character with ElementHandle.press', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
const textarea = await page.$('textarea');
@ -75,7 +75,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('a');
});
itFailsFirefox('ElementHandle.press should support |text| option', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
const textarea = await page.$('textarea');
@ -83,7 +83,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('ё');
});
itFailsFirefox('should send a character with sendCharacter', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -94,7 +94,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => document.querySelector('textarea').value)).toBe('嗨a');
});
itFailsFirefox('should report shiftKey', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
@ -116,7 +116,7 @@ describe('Keyboard', function() {
}
});
it('should report multiple modifiers', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
@ -134,7 +134,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => getResult())).toBe('Keyup: Alt AltLeft 18 []');
});
it('should send proper codes while typing', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/keyboard.html');
await page.keyboard.type('!');
@ -149,7 +149,7 @@ describe('Keyboard', function() {
'Keyup: ^ Digit6 54 []'].join('\n'));
});
it('should send proper codes while typing with shift', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/keyboard.html');
const keyboard = page.keyboard;
@ -163,7 +163,7 @@ describe('Keyboard', function() {
await keyboard.up('Shift');
});
it('should not type canceled events', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -181,7 +181,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => textarea.value)).toBe('He Wrd!');
});
itFailsFirefox('should specify repeat property', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -201,7 +201,7 @@ describe('Keyboard', function() {
expect(await page.evaluate(() => window.lastEvent.repeat)).toBe(false);
});
itFailsFirefox('should type all kinds of characters', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -210,7 +210,7 @@ describe('Keyboard', function() {
expect(await page.evaluate('result')).toBe(text);
});
itFailsFirefox('should specify location', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.evaluate(() => {
@ -231,7 +231,7 @@ describe('Keyboard', function() {
expect(await page.evaluate('keyLocation')).toBe(3);
});
it('should throw on unknown keys', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = await page.keyboard.press('NotARealKey').catch(e => e);
expect(error.message).toBe('Unknown key: "NotARealKey"');
@ -243,14 +243,14 @@ describe('Keyboard', function() {
expect(error && error.message).toBe('Unknown key: "😊"');
});
itFailsFirefox('should type emoji', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.type('textarea', '👹 Tokyo street Japan 🇯🇵');
expect(await page.$eval('textarea', textarea => textarea.value)).toBe('👹 Tokyo street Japan 🇯🇵');
});
itFailsFirefox('should type emoji into an iframe', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await utils.attachFrame(page, 'emoji-test', server.PREFIX + '/input/textarea.html');
@ -260,7 +260,7 @@ describe('Keyboard', function() {
expect(await frame.$eval('textarea', textarea => textarea.value)).toBe('👹 Tokyo street Japan 🇯🇵');
});
itFailsFirefox('should press the meta key', async() => {
const { page, isFirefox } = getTestState();
const {page, isFirefox} = getTestState();
await page.evaluate(() => {
window.result = null;

View File

@ -30,7 +30,7 @@ describe('Launcher specs', function() {
describe('Puppeteer', function() {
describe('BrowserFetcher', function() {
it('should download and extract chrome linux binary', async() => {
const { server, puppeteer} = getTestState();
const {server, puppeteer} = getTestState();
const downloadsFolder = await mkdtempAsync(TMP_FOLDER);
const browserFetcher = puppeteer.createBrowserFetcher({
@ -62,7 +62,7 @@ describe('Launcher specs', function() {
await rmAsync(downloadsFolder);
});
it('should download and extract firefox linux binary', async() => {
const { server , puppeteer} = getTestState();
const {server , puppeteer} = getTestState();
const downloadsFolder = await mkdtempAsync(TMP_FOLDER);
const browserFetcher = puppeteer.createBrowserFetcher({
@ -97,7 +97,7 @@ describe('Launcher specs', function() {
describe('Browser.disconnect', function() {
it('should reject navigation when browser closes', async() => {
const { server, puppeteer, defaultBrowserOptions} = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
server.setRoute('/one-style.css', () => {});
const browser = await puppeteer.launch(defaultBrowserOptions);
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
@ -110,7 +110,7 @@ describe('Launcher specs', function() {
await browser.close();
});
it('should reject waitForSelector when browser closes', async() => {
const { server, puppeteer, defaultBrowserOptions} = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
server.setRoute('/empty.html', () => {});
const browser = await puppeteer.launch(defaultBrowserOptions);
@ -125,7 +125,7 @@ describe('Launcher specs', function() {
});
describe('Browser.close', function() {
it('should terminate network waiters', async() => {
const { server, puppeteer, defaultBrowserOptions } = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
const browser = await puppeteer.launch(defaultBrowserOptions);
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
@ -155,7 +155,7 @@ describe('Launcher specs', function() {
expect(error.message).toContain('Protocol error');
});
it('should reject if executable path is invalid', async() => {
const { defaultBrowserOptions, puppeteer} = getTestState();
const {defaultBrowserOptions, puppeteer} = getTestState();
let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
@ -163,7 +163,7 @@ describe('Launcher specs', function() {
expect(waitError.message).toContain('Failed to launch');
});
it('userDataDir option', async() => {
const { defaultBrowserOptions, puppeteer} = getTestState();
const {defaultBrowserOptions, puppeteer} = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
@ -177,7 +177,7 @@ describe('Launcher specs', function() {
await rmAsync(userDataDir).catch(e => {});
});
it('userDataDir argument', async() => {
const { isChrome, puppeteer, defaultBrowserOptions} = getTestState();
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({}, defaultBrowserOptions);
@ -201,7 +201,7 @@ describe('Launcher specs', function() {
await rmAsync(userDataDir).catch(e => {});
});
it('userDataDir option should restore state', async() => {
const { server, puppeteer, defaultBrowserOptions} = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
@ -221,7 +221,7 @@ describe('Launcher specs', function() {
});
// This mysteriously fails on Windows on AppVeyor. See https://github.com/puppeteer/puppeteer/issues/4111
xit('userDataDir option should restore cookies', async() => {
const { server , puppeteer} = getTestState();
const {server , puppeteer} = getTestState();
const userDataDir = await mkdtempAsync(TMP_FOLDER);
const options = Object.assign({userDataDir}, defaultBrowserOptions);
@ -300,7 +300,7 @@ describe('Launcher specs', function() {
await browser.close();
});
itFailsFirefox('should have custom URL when launching browser', async() => {
const { server, puppeteer, defaultBrowserOptions} = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
const options = Object.assign({}, defaultBrowserOptions);
options.args = [server.EMPTY_PAGE].concat(options.args || []);
@ -338,7 +338,7 @@ describe('Launcher specs', function() {
await browser.close();
});
itFailsFirefox('should take fullPage screenshots when defaultViewport is null', async() => {
const { server, puppeteer, defaultBrowserOptions} = getTestState();
const {server, puppeteer, defaultBrowserOptions} = getTestState();
const options = Object.assign({}, defaultBrowserOptions, {
defaultViewport: null
@ -392,7 +392,7 @@ describe('Launcher specs', function() {
describe('Puppeteer.connect', function() {
it('should be able to connect multiple times to the same browser', async() => {
const { puppeteer, defaultBrowserOptions} = getTestState();
const {puppeteer, defaultBrowserOptions} = getTestState();
const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const otherBrowser = await puppeteer.connect({
@ -407,7 +407,7 @@ describe('Launcher specs', function() {
await originalBrowser.close();
});
it('should be able to close remote browser', async() => {
const { defaultBrowserOptions, puppeteer} = getTestState();
const {defaultBrowserOptions, puppeteer} = getTestState();
const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const remoteBrowser = await puppeteer.connect({
@ -419,7 +419,7 @@ describe('Launcher specs', function() {
]);
});
itFailsFirefox('should support ignoreHTTPSErrors option', async() => {
const { httpsServer, puppeteer, defaultBrowserOptions} = getTestState();
const {httpsServer, puppeteer, defaultBrowserOptions} = getTestState();
const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const browserWSEndpoint = originalBrowser.wsEndpoint();
@ -440,7 +440,7 @@ describe('Launcher specs', function() {
await browser.close();
});
itFailsFirefox('should be able to reconnect to a disconnected browser', async() => {
const { server , puppeteer, defaultBrowserOptions} = getTestState();
const {server , puppeteer, defaultBrowserOptions} = getTestState();
const originalBrowser = await puppeteer.launch(defaultBrowserOptions);
const browserWSEndpoint = originalBrowser.wsEndpoint();
@ -463,10 +463,10 @@ describe('Launcher specs', function() {
});
// @see https://github.com/puppeteer/puppeteer/issues/4197#issuecomment-481793410
itFailsFirefox('should be able to connect to the same page simultaneously', async() => {
const { puppeteer } = getTestState();
const {puppeteer} = getTestState();
const browserOne = await puppeteer.launch();
const browserTwo = await puppeteer.connect({ browserWSEndpoint: browserOne.wsEndpoint() });
const browserTwo = await puppeteer.connect({browserWSEndpoint: browserOne.wsEndpoint()});
const [page1, page2] = await Promise.all([
new Promise(x => browserOne.once('targetcreated', target => x(target.page()))),
browserTwo.newPage(),
@ -479,7 +479,7 @@ describe('Launcher specs', function() {
});
describe('Puppeteer.executablePath', function() {
itFailsFirefox('should work', async() => {
const { puppeteer } = getTestState();
const {puppeteer} = getTestState();
const executablePath = puppeteer.executablePath();
expect(fs.existsSync(executablePath)).toBe(true);
@ -503,7 +503,7 @@ describe('Launcher specs', function() {
describe('Browser target events', function() {
itFailsFirefox('should work', async() => {
const { server , puppeteer, defaultBrowserOptions} = getTestState();
const {server , puppeteer, defaultBrowserOptions} = getTestState();
const browser = await puppeteer.launch(defaultBrowserOptions);
const events = [];

View File

@ -31,7 +31,7 @@ describe('Mouse', function() {
setupTestBrowserHooks();
setupTestPageAndContextHooks();
it('should click the document', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.evaluate(() => {
window.clickPromise = new Promise(resolve => {
@ -57,7 +57,7 @@ describe('Mouse', function() {
expect(event.button).toBe(0);
});
itFailsFirefox('should resize the textarea', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
const {x, y, width, height} = await page.evaluate(dimensions);
@ -71,7 +71,7 @@ describe('Mouse', function() {
expect(newDimensions.height).toBe(Math.round(height + 104));
});
itFailsFirefox('should select the text with mouse', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/textarea.html');
await page.focus('textarea');
@ -91,7 +91,7 @@ describe('Mouse', function() {
})).toBe(text);
});
itFailsFirefox('should trigger hover state', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.hover('#button-6');
@ -102,7 +102,7 @@ describe('Mouse', function() {
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-91');
});
itFailsFirefox('should trigger hover state with removed window.Node', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.evaluate(() => delete window.Node);
@ -110,7 +110,7 @@ describe('Mouse', function() {
expect(await page.evaluate(() => document.querySelector('button:hover').id)).toBe('button-6');
});
it('should set modifier keys on click', async() => {
const { page, server, isFirefox } = getTestState();
const {page, server, isFirefox} = getTestState();
await page.goto(server.PREFIX + '/input/scrollable.html');
await page.evaluate(() => document.querySelector('#button-3').addEventListener('mousedown', e => window.lastEvent = e, true));
@ -132,7 +132,7 @@ describe('Mouse', function() {
}
});
itFailsFirefox('should tween mouse movement', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.mouse.move(100, 100);
await page.evaluate(() => {
@ -152,7 +152,7 @@ describe('Mouse', function() {
});
// @see https://crbug.com/929806
itFailsFirefox('should work with mobile viewports and cross process navigations', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setViewport({width: 360, height: 640, isMobile: true});

View File

@ -23,13 +23,13 @@ describe('navigation', function() {
setupTestPageAndContextHooks();
describe('Page.goto', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);
});
itFailsFirefox('should work with anchor navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
expect(page.url()).toBe(server.EMPTY_PAGE);
@ -39,7 +39,7 @@ describe('navigation', function() {
expect(page.url()).toBe(server.EMPTY_PAGE + '#bar');
});
it('should work with redirects', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRedirect('/redirect/1.html', '/redirect/2.html');
server.setRedirect('/redirect/2.html', '/empty.html');
@ -47,19 +47,19 @@ describe('navigation', function() {
expect(page.url()).toBe(server.EMPTY_PAGE);
});
it('should navigate to about:blank', async() => {
const { page } = getTestState();
const {page} = getTestState();
const response = await page.goto('about:blank');
expect(response).toBe(null);
});
itFailsFirefox('should return response when page changes its URL after load', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/historyapi.html');
expect(response.status()).toBe(200);
});
it('should work with subframes return 204', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRoute('/frames/frame.html', (req, res) => {
res.statusCode = 204;
@ -68,7 +68,7 @@ describe('navigation', function() {
await page.goto(server.PREFIX + '/frames/one-frame.html');
});
itFailsFirefox('should fail when server returns 204', async() => {
const { page, server, isChrome } = getTestState();
const {page, server, isChrome} = getTestState();
server.setRoute('/empty.html', (req, res) => {
res.statusCode = 204;
@ -83,13 +83,13 @@ describe('navigation', function() {
expect(error.message).toContain('NS_BINDING_ABORTED');
});
itFailsFirefox('should navigate to empty page with domcontentloaded', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'domcontentloaded'});
expect(response.status()).toBe(200);
});
itFailsFirefox('should work when page calls history API in beforeunload', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
@ -99,19 +99,19 @@ describe('navigation', function() {
expect(response.status()).toBe(200);
});
itFailsFirefox('should navigate to empty page with networkidle0', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle0'});
expect(response.status()).toBe(200);
});
itFailsFirefox('should navigate to empty page with networkidle2', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle2'});
expect(response.status()).toBe(200);
});
itFailsFirefox('should fail when navigating to bad url', async() => {
const { page, isChrome } = getTestState();
const {page, isChrome} = getTestState();
let error = null;
await page.goto('asdfasdf').catch(e => error = e);
@ -121,7 +121,7 @@ describe('navigation', function() {
expect(error.message).toContain('Invalid url');
});
itFailsFirefox('should fail when navigating to bad SSL', async() => {
const { page, httpsServer, isChrome } = getTestState();
const {page, httpsServer, isChrome} = getTestState();
// Make sure that network events do not emit 'undefined'.
// @see https://crbug.com/750469
@ -136,7 +136,7 @@ describe('navigation', function() {
expect(error.message).toContain('SSL_ERROR_UNKNOWN');
});
itFailsFirefox('should fail when navigating to bad SSL after redirects', async() => {
const { page, server, httpsServer, isChrome } = getTestState();
const {page, server, httpsServer, isChrome} = getTestState();
server.setRedirect('/redirect/1.html', '/redirect/2.html');
server.setRedirect('/redirect/2.html', '/empty.html');
@ -148,14 +148,14 @@ describe('navigation', function() {
expect(error.message).toContain('SSL_ERROR_UNKNOWN');
});
it('should throw if networkidle is passed as an option', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let error = null;
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle'}).catch(err => error = err);
expect(error.message).toContain('"networkidle" option is no longer supported');
});
itFailsFirefox('should fail when main resources failed to load', async() => {
const { page, isChrome } = getTestState();
const {page, isChrome} = getTestState();
let error = null;
await page.goto('http://localhost:44123/non-existing-url').catch(e => error = e);
@ -165,7 +165,7 @@ describe('navigation', function() {
expect(error.message).toContain('NS_ERROR_CONNECTION_REFUSED');
});
it('should fail when exceeding maximum navigation timeout', async() => {
const { page, server, puppeteer } = getTestState();
const {page, server, puppeteer} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', (req, res) => { });
@ -175,7 +175,7 @@ describe('navigation', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should fail when exceeding default maximum navigation timeout', async() => {
const { page, server, puppeteer } = getTestState();
const {page, server, puppeteer} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', (req, res) => { });
@ -186,7 +186,7 @@ describe('navigation', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should fail when exceeding default maximum timeout', async() => {
const { page, server, puppeteer } = getTestState();
const {page, server, puppeteer} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', (req, res) => { });
@ -197,7 +197,7 @@ describe('navigation', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should prioritize default navigation timeout over default timeout', async() => {
const { page, server, puppeteer } = getTestState();
const {page, server, puppeteer} = getTestState();
// Hang for request to the empty.html
server.setRoute('/empty.html', (req, res) => { });
@ -209,7 +209,7 @@ describe('navigation', function() {
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
});
it('should disable timeout when its set to 0', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let error = null;
let loaded = false;
@ -219,26 +219,26 @@ describe('navigation', function() {
expect(loaded).toBe(true);
});
itFailsFirefox('should work when navigating to valid url', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
});
itFailsFirefox('should work when navigating to data url', async() => {
const { page } = getTestState();
const {page} = getTestState();
const response = await page.goto('data:text/html,hello');
expect(response.ok()).toBe(true);
});
itFailsFirefox('should work when navigating to 404', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/not-found');
expect(response.ok()).toBe(false);
expect(response.status()).toBe(404);
});
itFailsFirefox('should return last response in redirect chain', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRedirect('/redirect/1.html', '/redirect/2.html');
server.setRedirect('/redirect/2.html', '/redirect/3.html');
@ -248,7 +248,7 @@ describe('navigation', function() {
expect(response.url()).toBe(server.EMPTY_PAGE);
});
itFailsFirefox('should wait for network idle to succeed navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let responses = [];
// Hold on to a bunch of requests without answering.
@ -307,7 +307,7 @@ describe('navigation', function() {
expect(response.ok()).toBe(true);
});
it('should not leak listeners during navigation', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let warning = null;
const warningHandler = w => warning = w;
@ -318,7 +318,7 @@ describe('navigation', function() {
expect(warning).toBe(null);
});
itFailsFirefox('should not leak listeners during bad navigation', async() => {
const { page } = getTestState();
const {page} = getTestState();
let warning = null;
const warningHandler = w => warning = w;
@ -329,7 +329,7 @@ describe('navigation', function() {
expect(warning).toBe(null);
});
it('should not leak listeners during navigation of 11 pages', async() => {
const { context, server } = getTestState();
const {context, server} = getTestState();
let warning = null;
const warningHandler = w => warning = w;
@ -343,7 +343,7 @@ describe('navigation', function() {
expect(warning).toBe(null);
});
itFailsFirefox('should navigate to dataURL and fire dataURL requests', async() => {
const { page } = getTestState();
const {page} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -354,7 +354,7 @@ describe('navigation', function() {
expect(requests[0].url()).toBe(dataURL);
});
itFailsFirefox('should navigate to URL with hash and fire requests without hash', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -365,14 +365,14 @@ describe('navigation', function() {
expect(requests[0].url()).toBe(server.EMPTY_PAGE);
});
itFailsFirefox('should work with self requesting page', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/self-request.html');
expect(response.status()).toBe(200);
expect(response.url()).toContain('self-request.html');
});
itFailsFirefox('should fail when navigating and show the url at the error message', async() => {
const { page, httpsServer } = getTestState();
const {page, httpsServer} = getTestState();
const url = httpsServer.PREFIX + '/redirect/1.html';
let error = null;
@ -384,7 +384,7 @@ describe('navigation', function() {
expect(error.message).toContain(url);
});
itFailsFirefox('should send referer', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const [request1, request2] = await Promise.all([
server.waitForRequest('/grid.html'),
@ -401,7 +401,7 @@ describe('navigation', function() {
describe('Page.waitForNavigation', function() {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const [response] = await Promise.all([
@ -412,7 +412,7 @@ describe('navigation', function() {
expect(response.url()).toContain('grid.html');
});
it('should work with both domcontentloaded and load', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
let response = null;
server.setRoute('/one-style.css', (req, res) => response = res);
@ -434,7 +434,7 @@ describe('navigation', function() {
await navigationPromise;
});
itFailsFirefox('should work with clicking on anchor links', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setContent(`<a href='#foobar'>foobar</a>`);
@ -446,7 +446,7 @@ describe('navigation', function() {
expect(page.url()).toBe(server.EMPTY_PAGE + '#foobar');
});
itFailsFirefox('should work with history.pushState()', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
@ -463,7 +463,7 @@ describe('navigation', function() {
expect(page.url()).toBe(server.PREFIX + '/wow.html');
});
itFailsFirefox('should work with history.replaceState()', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
@ -480,7 +480,7 @@ describe('navigation', function() {
expect(page.url()).toBe(server.PREFIX + '/replaced.html');
});
itFailsFirefox('should work with DOM history.back()/history.forward()', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
@ -508,7 +508,7 @@ describe('navigation', function() {
expect(page.url()).toBe(server.PREFIX + '/second.html');
});
itFailsFirefox('should work when subframe issues window.stop()', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRoute('/frames/style.css', (req, res) => {});
const navigationPromise = page.goto(server.PREFIX + '/frames/one-frame.html');
@ -528,7 +528,7 @@ describe('navigation', function() {
describeFailsFirefox('Page.goBack', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.goto(server.PREFIX + '/grid.html');
@ -545,7 +545,7 @@ describe('navigation', function() {
expect(response).toBe(null);
});
it('should work with HistoryAPI', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => {
@ -565,7 +565,7 @@ describe('navigation', function() {
describeFailsFirefox('Frame.goto', function() {
it('should navigate subframes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/one-frame.html');
expect(page.frames()[0].url()).toContain('/frames/one-frame.html');
@ -576,7 +576,7 @@ describe('navigation', function() {
expect(response.frame()).toBe(page.frames()[1]);
});
it('should reject when frame detaches', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/one-frame.html');
@ -589,7 +589,7 @@ describe('navigation', function() {
expect(error.message).toBe('Navigating frame was detached');
});
it('should return matching responses', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
// Disable cache: otherwise, chromium will cache similar requests.
await page.setCacheEnabled(false);
@ -621,7 +621,7 @@ describe('navigation', function() {
describeFailsFirefox('Frame.waitForNavigation', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/one-frame.html');
const frame = page.frames()[1];
@ -635,7 +635,7 @@ describe('navigation', function() {
expect(page.url()).toContain('/frames/one-frame.html');
});
it('should fail when frame detaches', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.PREFIX + '/frames/one-frame.html');
const frame = page.frames()[1];
@ -655,7 +655,7 @@ describe('navigation', function() {
describe('Page.reload', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
await page.evaluate(() => window._foo = 10);

View File

@ -26,7 +26,7 @@ describe('network', function() {
describe('Page.Events.Request', function() {
it('should fire for navigation requests', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -34,7 +34,7 @@ describe('network', function() {
expect(requests.length).toBe(1);
});
itFailsFirefox('should fire for iframes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -43,7 +43,7 @@ describe('network', function() {
expect(requests.length).toBe(2);
});
it('should fire for fetches', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -55,7 +55,7 @@ describe('network', function() {
describe('Request.frame', function() {
it('should work for main frame navigation request', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => !utils.isFavicon(request) && requests.push(request));
@ -64,7 +64,7 @@ describe('network', function() {
expect(requests[0].frame()).toBe(page.mainFrame());
});
itFailsFirefox('should work for subframe navigation request', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
const requests = [];
@ -74,7 +74,7 @@ describe('network', function() {
expect(requests[0].frame()).toBe(page.frames()[1]);
});
it('should work for fetch requests', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
let requests = [];
@ -88,7 +88,7 @@ describe('network', function() {
describeFailsFirefox('Request.headers', function() {
it('should work', async() => {
const { page, server, isChrome } = getTestState();
const {page, server, isChrome} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
if (isChrome)
@ -100,7 +100,7 @@ describe('network', function() {
describeFailsFirefox('Response.headers', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRoute('/empty.html', (req, res) => {
res.setHeader('foo', 'bar');
@ -113,14 +113,14 @@ describe('network', function() {
describeFailsFirefox('Response.fromCache', function() {
it('should return |false| for non-cached content', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.fromCache()).toBe(false);
});
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const responses = new Map();
page.on('response', r => !utils.isFavicon(r.request()) && responses.set(r.url().split('/').pop(), r));
@ -139,14 +139,14 @@ describe('network', function() {
describeFailsFirefox('Response.fromServiceWorker', function() {
it('should return |false| for non-service-worker content', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.fromServiceWorker()).toBe(false);
});
it('Response.fromServiceWorker', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const responses = new Map();
page.on('response', r => responses.set(r.url().split('/').pop(), r));
@ -166,18 +166,18 @@ describe('network', function() {
describeFailsFirefox('Request.postData', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
server.setRoute('/post', (req, res) => res.end());
let request = null;
page.on('request', r => request = r);
await page.evaluate(() => fetch('./post', { method: 'POST', body: JSON.stringify({foo: 'bar'})}));
await page.evaluate(() => fetch('./post', {method: 'POST', body: JSON.stringify({foo: 'bar'})}));
expect(request).toBeTruthy();
expect(request.postData()).toBe('{"foo":"bar"}');
});
it('should be |undefined| when there is no post data', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.EMPTY_PAGE);
expect(response.request().postData()).toBe(undefined);
@ -186,14 +186,14 @@ describe('network', function() {
describeFailsFirefox('Response.text', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/simple.json');
const responseText = (await response.text()).trimEnd();
expect(responseText).toBe('{"foo": "bar"}');
});
it('should return uncompressed text', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.enableGzip('/simple.json');
const response = await page.goto(server.PREFIX + '/simple.json');
@ -202,7 +202,7 @@ describe('network', function() {
expect(responseText).toBe('{"foo": "bar"}');
});
it('should throw when requesting body of redirected response', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRedirect('/foo.html', '/empty.html');
const response = await page.goto(server.PREFIX + '/foo.html');
@ -215,7 +215,7 @@ describe('network', function() {
expect(error.message).toContain('Response body is unavailable for redirect responses');
});
it('should wait until response completes', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.goto(server.EMPTY_PAGE);
// Setup server to trap request.
@ -233,7 +233,7 @@ describe('network', function() {
// send request and wait for server response
const [pageResponse] = await Promise.all([
page.waitForResponse(r => !utils.isFavicon(r.request())),
page.evaluate(() => fetch('./get', { method: 'GET'})),
page.evaluate(() => fetch('./get', {method: 'GET'})),
server.waitForRequest('/get'),
]);
@ -253,7 +253,7 @@ describe('network', function() {
describeFailsFirefox('Response.json', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/simple.json');
expect(await response.json()).toEqual({foo: 'bar'});
@ -262,7 +262,7 @@ describe('network', function() {
describeFailsFirefox('Response.buffer', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const response = await page.goto(server.PREFIX + '/pptr.png');
const imageBuffer = fs.readFileSync(path.join(__dirname, 'assets', 'pptr.png'));
@ -270,7 +270,7 @@ describe('network', function() {
expect(responseBuffer.equals(imageBuffer)).toBe(true);
});
it('should work with compression', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.enableGzip('/pptr.png');
const response = await page.goto(server.PREFIX + '/pptr.png');
@ -282,7 +282,7 @@ describe('network', function() {
describeFailsFirefox('Response.statusText', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setRoute('/cool', (req, res) => {
res.writeHead(200, 'cool!');
@ -295,7 +295,7 @@ describe('network', function() {
describeFailsFirefox('Network Events', function() {
it('Page.Events.Request', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => requests.push(request));
@ -309,7 +309,7 @@ describe('network', function() {
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
});
it('Page.Events.Response', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const responses = [];
page.on('response', response => responses.push(response));
@ -326,7 +326,7 @@ describe('network', function() {
});
it('Page.Events.RequestFailed', async() => {
const { page, server, isChrome } = getTestState();
const {page, server, isChrome} = getTestState();
await page.setRequestInterception(true);
page.on('request', request => {
@ -349,7 +349,7 @@ describe('network', function() {
expect(failedRequests[0].frame()).toBeTruthy();
});
it('Page.Events.RequestFinished', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('requestfinished', request => requests.push(request));
@ -361,7 +361,7 @@ describe('network', function() {
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
});
it('should fire events in proper order', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const events = [];
page.on('request', request => events.push('request'));
@ -371,7 +371,7 @@ describe('network', function() {
expect(events).toEqual(['request', 'response', 'requestfinished']);
});
it('should support redirects', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const events = [];
page.on('request', request => events.push(`${request.method()} ${request.url()}`));
@ -400,7 +400,7 @@ describe('network', function() {
describe('Request.isNavigationRequest', () => {
itFailsFirefox('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = new Map();
page.on('request', request => requests.set(request.url().split('/').pop(), request));
@ -413,7 +413,7 @@ describe('network', function() {
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
});
itFailsFirefox('should work with request interception', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = new Map();
page.on('request', request => {
@ -430,7 +430,7 @@ describe('network', function() {
expect(requests.get('style.css').isNavigationRequest()).toBe(false);
});
it('should work when navigating to image', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
const requests = [];
page.on('request', request => requests.push(request));
@ -441,7 +441,7 @@ describe('network', function() {
describeFailsFirefox('Page.setExtraHTTPHeaders', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
await page.setExtraHTTPHeaders({
foo: 'bar'
@ -453,11 +453,11 @@ describe('network', function() {
expect(request.headers['foo']).toBe('bar');
});
it('should throw for non-string header values', async() => {
const { page } = getTestState();
const {page} = getTestState();
let error = null;
try {
await page.setExtraHTTPHeaders({ 'foo': 1 });
await page.setExtraHTTPHeaders({'foo': 1});
} catch (e) {
error = e;
}
@ -467,7 +467,7 @@ describe('network', function() {
describeFailsFirefox('Page.authenticate', function() {
it('should work', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
server.setAuth('/empty.html', 'user', 'pass');
let response = await page.goto(server.EMPTY_PAGE);
@ -480,7 +480,7 @@ describe('network', function() {
expect(response.status()).toBe(200);
});
it('should fail if wrong credentials', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user2', 'pass2');
@ -492,7 +492,7 @@ describe('network', function() {
expect(response.status()).toBe(401);
});
it('should allow disable authentication', async() => {
const { page, server } = getTestState();
const {page, server} = getTestState();
// Use unique user/password since Chrome caches credentials per origin.
server.setAuth('/empty.html', 'user3', 'pass3');

View File

@ -46,14 +46,14 @@ describeChromeOnly('OOPIF', function() {
browser = null;
});
xit('should report oopif frames', async() => {
const { server } = getTestState();
const {server} = getTestState();
await page.goto(server.PREFIX + '/dynamic-oopif.html');
expect(oopifs(context).length).toBe(1);
expect(page.frames().length).toBe(2);
});
it('should load oopif iframes with subresources and request interception', async() => {
const { server } = getTestState();
const {server} = getTestState();
await page.setRequestInterception(true);
page.on('request', request => request.continue());

File diff suppressed because it is too large Load Diff

View File

@ -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('<section id="testAttribute">43543</section>');
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('<section>hello</section>');
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('<section>hello</section><div> world</div>');
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('<div>hello</div><div>beautiful</div><div>world!</div>');
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('<section>test</section>');
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('<div>A</div><br/><div>B</div>');
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('<section>test</section>');
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('<div></div><div></div>');
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('<html><body><div class="second"><div class="inner">A</div></div></body></html>');
@ -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('<html><body><div class="second"><div class="inner">B</div></div></body></html>');
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('<html><body><div class="tweet"><div class="like">100</div><div class="retweets">10</div></div></body></html>');
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 = '<div class="a">not-a-child-div</div><div id="myId"><div class="a">a-child-div</div></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 = '<div class="a">not-a-child-div</div><div id="myId"></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('<html><body><div class="tweet"><div class="like">100</div><div class="like">10</div></div></body></html>');
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 = '<div class="a">not-a-child-div</div><div id="myId"><div class="a">a1-child-div</div><div class="a">a2-child-div</div></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 = '<div class="a">not-a-child-div</div><div id="myId"></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('<html><body><div>A</div><br/><div>B</div></body></html>');
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('<html><body><span>A</span><br/><span>B</span></body></html>');
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('<html><body><div class="second"><div class="inner">A</div></div></body></html>');
@ -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('<html><body><div class="second"><div class="inner">B</div></div></body></html>');
const html = await page.$('html');

View File

@ -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('<iframe></iframe>');
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 => {

View File

@ -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(`<div style="position:absolute;
@ -244,7 +244,7 @@ describe('Screenshots', function() {
expect(screenshot).toBeGolden('screenshot-element-rotate.png');
});
itFailsFirefox('should fail to screenshot a detached element', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<h1>remove this</h1>');
const elementHandle = await page.$('h1');
@ -253,7 +253,7 @@ describe('Screenshots', function() {
expect(screenshotError.message).toBe('Node is either not visible or not an HTMLElement');
});
itFailsFirefox('should not hang with zero width/height element', async() => {
const { page } = getTestState();
const {page} = getTestState();
await page.setContent('<div style="width: 50px; height: 0"></div>');
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('<div style="width:48.51px;height:19.8px;border:1px solid black;"></div>');
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('<div style="position:absolute; top: 10.3px; left: 20.4px;width:50.3px;height:20.2px;border:1px solid black;"></div>');
const elementHandle = await page.$('div');

View File

@ -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, {

View File

@ -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');

View File

@ -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(`<div>some text</div>`);
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('<div></div>');
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(`<div style='display: block;'></div>`);
@ -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(`<div style='display: block;'></div>`);
@ -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(`<div></div>`);
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(`<div></div>`);
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(`<div class='zombo'>anything</div>`);
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(`<p>red herring</p><p>hello world </p>`);
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(`<div style='display: block;'></div>`);
@ -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(`<div class='zombo'>anything</div>`);
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(`<div>some text</div>`);
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(`<div>some text</div>`);
const waitForXPath = page.waitForXPath('/html/body/div');

View File

@ -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');`));

View File

@ -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};
};

View File

@ -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)

View File

@ -54,7 +54,7 @@ devices and save to the <outputPath>.
`;
const argv = require('minimist')(process.argv.slice(2), {
alias: { u: 'url', h: 'help' },
alias: {u: 'url', h: 'help'},
});
if (argv.help) {

View File

@ -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;
}