mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: enforce naming of errors in catch blocks (#5763)
This commit is contained in:
parent
3bf9bd199d
commit
1ccfbcb684
@ -9,7 +9,8 @@ module.exports = {
|
||||
|
||||
"plugins": [
|
||||
"mocha",
|
||||
"@typescript-eslint"
|
||||
"@typescript-eslint",
|
||||
"unicorn"
|
||||
],
|
||||
|
||||
"rules": {
|
||||
@ -99,7 +100,10 @@ module.exports = {
|
||||
}],
|
||||
|
||||
// ensure we don't have any it.only or describe.only in prod
|
||||
"mocha/no-exclusive-tests": "error"
|
||||
"mocha/no-exclusive-tests": "error",
|
||||
|
||||
// enforce the variable in a catch block is named error
|
||||
"unicorn/catch-error-name": "error"
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
|
@ -69,6 +69,7 @@
|
||||
"cross-env": "^5.0.5",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-plugin-mocha": "^6.3.0",
|
||||
"eslint-plugin-unicorn": "^19.0.1",
|
||||
"esprima": "^4.0.0",
|
||||
"expect": "^25.2.7",
|
||||
"jpeg-js": "^0.3.7",
|
||||
|
@ -429,7 +429,7 @@ function installDMG(dmgPath: string, folderPath: string): Promise<void> {
|
||||
});
|
||||
}
|
||||
|
||||
return new Promise<void>(mountAndCopy).catch(err => { console.error(err); }).finally(unmount);
|
||||
return new Promise<void>(mountAndCopy).catch(error => { console.error(error); }).finally(unmount);
|
||||
}
|
||||
|
||||
function httpRequest(url: string, method: string, response: (x: http.IncomingMessage) => void): http.ClientRequest {
|
||||
|
@ -105,9 +105,9 @@ class JSCoverage {
|
||||
const response = await this._client.send('Debugger.getScriptSource', {scriptId: event.scriptId});
|
||||
this._scriptURLs.set(event.scriptId, event.url);
|
||||
this._scriptSources.set(event.scriptId, response.scriptSource);
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
// This might happen if the page has already navigated away.
|
||||
debugError(e);
|
||||
debugError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,9 +196,9 @@ class CSSCoverage {
|
||||
const response = await this._client.send('CSS.getStyleSheetText', {styleSheetId: header.styleSheetId});
|
||||
this._stylesheetURLs.set(header.styleSheetId, header.sourceURL);
|
||||
this._stylesheetSources.set(header.styleSheetId, response.text);
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
// This might happen if the page has already navigated away.
|
||||
debugError(e);
|
||||
debugError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -579,8 +579,8 @@ class WaitTask {
|
||||
let error = null;
|
||||
try {
|
||||
success = await (await this._domWorld.executionContext()).evaluateHandle(waitForPredicatePageFunction, this._predicateBody, this._polling, this._timeout, ...this._args);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
|
||||
if (this._terminated || runCount !== this._runCount) {
|
||||
@ -592,7 +592,7 @@ class WaitTask {
|
||||
// Ignore timeouts in pageScript - we track timeouts ourselves.
|
||||
// If the frame's execution context has already changed, `frame.evaluate` will
|
||||
// throw an error - ignore this predicate run altogether.
|
||||
if (!error && await this._domWorld.evaluate(s => !s, success).catch(e => true)) {
|
||||
if (!error && await this._domWorld.evaluate(s => !s, success).catch(error_ => true)) {
|
||||
await success.dispose();
|
||||
return;
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ export class ExecutionContext {
|
||||
let functionText = pageFunction.toString();
|
||||
try {
|
||||
new Function('(' + functionText + ')');
|
||||
} catch (e1) {
|
||||
} catch (error) {
|
||||
// This means we might have a function shorthand. Try another
|
||||
// time prefixing 'function '.
|
||||
if (functionText.startsWith('async '))
|
||||
@ -81,7 +81,7 @@ export class ExecutionContext {
|
||||
functionText = 'function ' + functionText;
|
||||
try {
|
||||
new Function('(' + functionText + ')');
|
||||
} catch (e2) {
|
||||
} catch (error) {
|
||||
// We tried hard to serialize, but there's a weird beast here.
|
||||
throw new Error('Passed function is not well-serializable!');
|
||||
}
|
||||
@ -96,10 +96,10 @@ export class ExecutionContext {
|
||||
awaitPromise: true,
|
||||
userGesture: true
|
||||
});
|
||||
} catch (err) {
|
||||
if (err instanceof TypeError && err.message.startsWith('Converting circular structure to JSON'))
|
||||
err.message += ' Are you passing a nested JSHandle?';
|
||||
throw err;
|
||||
} catch (error) {
|
||||
if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON'))
|
||||
error.message += ' Are you passing a nested JSHandle?';
|
||||
throw error;
|
||||
}
|
||||
const {exceptionDetails, result: remoteObject} = await callFunctionOnPromise.catch(rewriteError);
|
||||
if (exceptionDetails)
|
||||
|
@ -98,7 +98,7 @@ class BrowserRunner {
|
||||
if (this._tempDirectory) {
|
||||
removeFolderAsync(this._tempDirectory)
|
||||
.then(() => fulfill())
|
||||
.catch(err => console.error(err));
|
||||
.catch(error => console.error(error));
|
||||
} else {
|
||||
fulfill();
|
||||
}
|
||||
@ -819,9 +819,9 @@ function getWSEndpoint(browserURL) {
|
||||
request.on('error', reject);
|
||||
request.end();
|
||||
|
||||
return promise.catch(e => {
|
||||
e.message = `Failed to fetch browser webSocket url from ${endpointURL}: ` + e.message;
|
||||
throw e;
|
||||
return promise.catch(error => {
|
||||
error.message = `Failed to fetch browser webSocket url from ${endpointURL}: ` + error.message;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
|
10
src/Page.js
10
src/Page.js
@ -179,9 +179,9 @@ class Page extends EventEmitter {
|
||||
let callback;
|
||||
const promise = new Promise(x => callback = x);
|
||||
this._fileChooserInterceptors.add(callback);
|
||||
return helper.waitWithTimeout(promise, 'waiting for file chooser', timeout).catch(e => {
|
||||
return helper.waitWithTimeout(promise, 'waiting for file chooser', timeout).catch(error => {
|
||||
this._fileChooserInterceptors.delete(callback);
|
||||
throw e;
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
|
||||
@ -851,10 +851,10 @@ class Page extends EventEmitter {
|
||||
async emulateTimezone(timezoneId) {
|
||||
try {
|
||||
await this._client.send('Emulation.setTimezoneOverride', {timezoneId: timezoneId || ''});
|
||||
} catch (exception) {
|
||||
if (exception.message.includes('Invalid timezone'))
|
||||
} catch (error) {
|
||||
if (error.message.includes('Invalid timezone'))
|
||||
throw new Error(`Invalid timezone ID: ${timezoneId}`);
|
||||
throw exception;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,12 +90,12 @@ function installAsyncStackHooks(classType: AnyClass): void {
|
||||
stack: ''
|
||||
};
|
||||
Error.captureStackTrace(syncStack);
|
||||
return method.call(this, ...args).catch(e => {
|
||||
return method.call(this, ...args).catch(error => {
|
||||
const stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
|
||||
const clientStack = stack.substring(stack.indexOf('\n'));
|
||||
if (e instanceof Error && e.stack && !e.stack.includes(clientStack))
|
||||
e.stack += '\n -- ASYNC --\n' + stack;
|
||||
throw e;
|
||||
if (error instanceof Error && error.stack && !error.stack.includes(clientStack))
|
||||
error.stack += '\n -- ASYNC --\n' + stack;
|
||||
throw error;
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -149,9 +149,9 @@ async function waitForEvent<T extends any>(emitter: NodeJS.EventEmitter, eventNa
|
||||
const result = await Promise.race([promise, abortPromise]).then(r => {
|
||||
cleanup();
|
||||
return r;
|
||||
}, e => {
|
||||
}, error => {
|
||||
cleanup();
|
||||
throw e;
|
||||
throw error;
|
||||
});
|
||||
if (result instanceof Error)
|
||||
throw result;
|
||||
|
@ -72,8 +72,8 @@ describeChromeOnly('Target.createCDPSession', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await client.send('Runtime.evaluate', {expression: '3 + 1', returnByValue: true});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain('Session closed.');
|
||||
});
|
||||
|
@ -26,7 +26,7 @@ describe('BrowserContext', function() {
|
||||
const defaultContext = browser.browserContexts()[0];
|
||||
expect(defaultContext.isIncognito()).toBe(false);
|
||||
let error = null;
|
||||
await defaultContext.close().catch(e => error = e);
|
||||
await defaultContext.close().catch(error_ => error = error_);
|
||||
expect(browser.defaultBrowserContext()).toBe(defaultContext);
|
||||
expect(error.message).toContain('cannot be closed');
|
||||
});
|
||||
@ -104,7 +104,7 @@ describe('BrowserContext', function() {
|
||||
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);
|
||||
const error = await context.waitForTarget(target => target.url() === server.EMPTY_PAGE, {timeout: 1}).catch(error_ => error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
await context.close();
|
||||
});
|
||||
|
@ -46,7 +46,7 @@ describeChromeOnly('Chromium-Specific Launcher tests', function() {
|
||||
const browserURL = 'http://127.0.0.1:21222';
|
||||
|
||||
let error = null;
|
||||
await puppeteer.connect({browserURL, browserWSEndpoint: originalBrowser.wsEndpoint()}).catch(e => error = e);
|
||||
await puppeteer.connect({browserURL, browserWSEndpoint: originalBrowser.wsEndpoint()}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Exactly one of browserWSEndpoint, browserURL or transport');
|
||||
|
||||
originalBrowser.close();
|
||||
@ -60,7 +60,7 @@ describeChromeOnly('Chromium-Specific Launcher tests', function() {
|
||||
const browserURL = 'http://127.0.0.1:32333';
|
||||
|
||||
let error = null;
|
||||
await puppeteer.connect({browserURL}).catch(e => error = e);
|
||||
await puppeteer.connect({browserURL}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Failed to fetch browser webSocket url from');
|
||||
originalBrowser.close();
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ describe('Page.click', function() {
|
||||
await Promise.all([
|
||||
newPage.close(),
|
||||
newPage.mouse.click(1, 2),
|
||||
]).catch(e => {});
|
||||
]).catch(error => {});
|
||||
});
|
||||
it('should click the button after navigation ', async() => {
|
||||
const {page, server} = getTestState();
|
||||
@ -197,7 +197,7 @@ describe('Page.click', function() {
|
||||
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
let error = null;
|
||||
await page.click('button.does-not-exist').catch(e => error = e);
|
||||
await page.click('button.does-not-exist').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('No node found for selector: button.does-not-exist');
|
||||
});
|
||||
// @see https://github.com/puppeteer/puppeteer/issues/161
|
||||
|
@ -270,8 +270,8 @@ describe('Cookie specs', () => {
|
||||
let error = null;
|
||||
try {
|
||||
await page.setCookie({name: 'example-cookie', value: 'best'});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain('At least one of the url and domain needs to be specified');
|
||||
});
|
||||
@ -285,8 +285,8 @@ describe('Cookie specs', () => {
|
||||
{name: 'example-cookie', value: 'best'},
|
||||
{url: 'about:blank', name: 'example-cookie-blank', value: 'best'}
|
||||
);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toEqual(
|
||||
`Blank page can not have cookie "example-cookie-blank"`
|
||||
@ -299,8 +299,8 @@ describe('Cookie specs', () => {
|
||||
await page.goto('data:,Hello%2C%20World!');
|
||||
try {
|
||||
await page.setCookie({name: 'example-cookie', value: 'best'});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain('At least one of the url and domain needs to be specified');
|
||||
});
|
||||
|
@ -183,7 +183,7 @@ describe('ElementHandle specs', function() {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);
|
||||
let error = null;
|
||||
await buttonTextNode.click().catch(err => error = err);
|
||||
await buttonTextNode.click().catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Node is not of type HTMLElement');
|
||||
});
|
||||
it('should throw for detached nodes', async() => {
|
||||
@ -193,7 +193,7 @@ describe('ElementHandle specs', function() {
|
||||
const button = await page.$('button');
|
||||
await page.evaluate(button => button.remove(), button);
|
||||
let error = null;
|
||||
await button.click().catch(err => error = err);
|
||||
await button.click().catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Node is detached from document');
|
||||
});
|
||||
it('should throw for hidden nodes', async() => {
|
||||
@ -202,7 +202,7 @@ describe('ElementHandle specs', function() {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const button = await page.$('button');
|
||||
await page.evaluate(button => button.style.display = 'none', button);
|
||||
const error = await button.click().catch(err => err);
|
||||
const error = await button.click().catch(error_ => error_);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
it('should throw for recursively hidden nodes', async() => {
|
||||
@ -211,7 +211,7 @@ describe('ElementHandle specs', function() {
|
||||
await page.goto(server.PREFIX + '/input/button.html');
|
||||
const button = await page.$('button');
|
||||
await page.evaluate(button => button.parentElement.style.display = 'none', button);
|
||||
const error = await button.click().catch(err => err);
|
||||
const error = await button.click().catch(error_ => error_);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
itFailsFirefox('should throw for <br> elements', async() => {
|
||||
@ -219,7 +219,7 @@ describe('ElementHandle specs', function() {
|
||||
|
||||
await page.setContent('hello<br>goodbye');
|
||||
const br = await page.$('br');
|
||||
const error = await br.click().catch(err => err);
|
||||
const error = await br.click().catch(error_ => error_);
|
||||
expect(error.message).toBe('Node is either not visible or not an HTMLElement');
|
||||
});
|
||||
});
|
||||
|
@ -148,7 +148,7 @@ describe('Emulation', () => {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.emulateMedia('bad').catch(e => error = e);
|
||||
await page.emulateMedia('bad').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Unsupported media type: bad');
|
||||
});
|
||||
});
|
||||
@ -173,7 +173,7 @@ describe('Emulation', () => {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.emulateMediaType('bad').catch(e => error = e);
|
||||
await page.emulateMediaType('bad').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Unsupported media type: bad');
|
||||
});
|
||||
});
|
||||
@ -213,7 +213,7 @@ describe('Emulation', () => {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.emulateMediaFeatures([{name: 'bad', value: ''}]).catch(e => error = e);
|
||||
await page.emulateMediaFeatures([{name: 'bad', value: ''}]).catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Unsupported media feature: bad');
|
||||
});
|
||||
});
|
||||
@ -242,9 +242,9 @@ describe('Emulation', () => {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.emulateTimezone('Foo/Bar').catch(e => error = e);
|
||||
await page.emulateTimezone('Foo/Bar').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Invalid timezone ID: Foo/Bar');
|
||||
await page.emulateTimezone('Baz/Qux').catch(e => error = e);
|
||||
await page.emulateTimezone('Baz/Qux').catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Invalid timezone ID: Baz/Qux');
|
||||
});
|
||||
});
|
||||
|
@ -115,7 +115,7 @@ describe('Evaluation specs', function() {
|
||||
await page.evaluate(() => {
|
||||
location.reload();
|
||||
return new Promise(() => {});
|
||||
}).catch(e => error = e);
|
||||
}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Protocol error');
|
||||
});
|
||||
it('should await promise', async() => {
|
||||
@ -150,7 +150,7 @@ describe('Evaluation specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.evaluate(() => not_existing_object.property).catch(e => error = e);
|
||||
await page.evaluate(() => not_existing_object.property).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('not_existing_object');
|
||||
});
|
||||
@ -158,7 +158,7 @@ describe('Evaluation specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.evaluate(() => { throw 'qwerty'; }).catch(e => error = e);
|
||||
await page.evaluate(() => { throw 'qwerty'; }).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('qwerty');
|
||||
});
|
||||
@ -166,7 +166,7 @@ describe('Evaluation specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.evaluate(() => { throw 100500; }).catch(e => error = e);
|
||||
await page.evaluate(() => { throw 100500; }).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('100500');
|
||||
});
|
||||
@ -239,10 +239,10 @@ describe('Evaluation specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
const windowHandle = await page.evaluateHandle(() => window);
|
||||
const errorText = await windowHandle.jsonValue().catch(e => e.message);
|
||||
const errorText = await windowHandle.jsonValue().catch(error_ => error_.message);
|
||||
const error = await page.evaluate(errorText => {
|
||||
throw new Error(errorText);
|
||||
}, errorText).catch(e => e);
|
||||
}, errorText).catch(error_ => error_);
|
||||
expect(error.message).toContain(errorText);
|
||||
});
|
||||
it('should accept a string', async() => {
|
||||
@ -279,7 +279,7 @@ describe('Evaluation specs', function() {
|
||||
expect(element).toBeTruthy();
|
||||
await element.dispose();
|
||||
let error = null;
|
||||
await page.evaluate(e => e.textContent, element).catch(e => error = e);
|
||||
await page.evaluate(e => e.textContent, element).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('JSHandle is disposed');
|
||||
});
|
||||
itFailsFirefox('should throw if elementHandles are from other frames', async() => {
|
||||
@ -288,7 +288,7 @@ describe('Evaluation specs', function() {
|
||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
const bodyHandle = await page.frames()[1].$('body');
|
||||
let error = null;
|
||||
await page.evaluate(body => body.innerHTML, bodyHandle).catch(e => error = e);
|
||||
await page.evaluate(body => body.innerHTML, bodyHandle).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created');
|
||||
});
|
||||
@ -311,7 +311,7 @@ describe('Evaluation specs', function() {
|
||||
page.waitForNavigation(),
|
||||
executionContext.evaluate(() => window.location.reload())
|
||||
]);
|
||||
const error = await executionContext.evaluate(() => null).catch(e => e);
|
||||
const error = await executionContext.evaluate(() => null).catch(error_ => error_);
|
||||
expect(error.message).toContain('navigation');
|
||||
});
|
||||
itFailsFirefox('should not throw an error when evaluation does a navigation', async() => {
|
||||
@ -336,7 +336,7 @@ describe('Evaluation specs', function() {
|
||||
let error = null;
|
||||
await page.evaluate(() => new Promise(() => {
|
||||
throw new Error('Error in promise');
|
||||
})).catch(e => error = e);
|
||||
})).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Error in promise');
|
||||
});
|
||||
});
|
||||
@ -362,7 +362,7 @@ describe('Evaluation specs', function() {
|
||||
expect(await page.evaluate(() => window.injected)).toBe(123);
|
||||
|
||||
// Make sure CSP works.
|
||||
await page.addScriptTag({content: 'window.e = 10;'}).catch(e => void e);
|
||||
await page.addScriptTag({content: 'window.e = 10;'}).catch(error => void error);
|
||||
expect(await page.evaluate(() => window.e)).toBe(undefined);
|
||||
});
|
||||
});
|
||||
|
@ -69,7 +69,7 @@ describe('Frame specs', function() {
|
||||
const frame1 = await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
await utils.detachFrame(page, 'frame1');
|
||||
let error = null;
|
||||
await frame1.evaluate(() => 7 * 8).catch(e => error = e);
|
||||
await frame1.evaluate(() => 7 * 8).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Execution Context is not available in detached frame');
|
||||
});
|
||||
});
|
||||
|
@ -109,7 +109,7 @@ describeChromeOnly('headful tests', function() {
|
||||
const cookie = await headlessPage.evaluate(() => document.cookie);
|
||||
await headlessBrowser.close();
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
await rmAsync(userDataDir).catch(e => {});
|
||||
await rmAsync(userDataDir).catch(error => {});
|
||||
expect(cookie).toBe('foo=true');
|
||||
});
|
||||
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548
|
||||
|
@ -92,7 +92,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
|
||||
const {httpsServer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
|
||||
const response = await page.goto(httpsServer.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
expect(error).toBe(null);
|
||||
expect(response.ok()).toBe(true);
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ describe('input tests', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForFileChooser({timeout: 1}).catch(e => error = e);
|
||||
await page.waitForFileChooser({timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should respect default timeout when there is no custom timeout', async() => {
|
||||
@ -85,7 +85,7 @@ describe('input tests', function() {
|
||||
|
||||
page.setDefaultTimeout(1);
|
||||
let error = null;
|
||||
await page.waitForFileChooser().catch(e => error = e);
|
||||
await page.waitForFileChooser().catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should prioritize exact timeout over default timeout', async() => {
|
||||
@ -93,7 +93,7 @@ describe('input tests', function() {
|
||||
|
||||
page.setDefaultTimeout(0);
|
||||
let error = null;
|
||||
await page.waitForFileChooser({timeout: 1}).catch(e => error = e);
|
||||
await page.waitForFileChooser({timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should work with no timeout', async() => {
|
||||
@ -181,7 +181,7 @@ describe('input tests', function() {
|
||||
await chooser.accept([
|
||||
path.relative(process.cwd(), __dirname + '/assets/file-to-upload.txt'),
|
||||
path.relative(process.cwd(), __dirname + '/assets/pptr.png'),
|
||||
]).catch(e => error = e);
|
||||
]).catch(error_ => error = error_);
|
||||
expect(error).not.toBe(null);
|
||||
});
|
||||
it('should fail for non-existent files', async() => {
|
||||
@ -193,7 +193,7 @@ describe('input tests', function() {
|
||||
page.click('input'),
|
||||
]);
|
||||
let error = null;
|
||||
await chooser.accept(['file-does-not-exist.txt']).catch(e => error = e);
|
||||
await chooser.accept(['file-does-not-exist.txt']).catch(error_ => error = error_);
|
||||
expect(error).not.toBe(null);
|
||||
});
|
||||
it('should fail when accepting file chooser twice', async() => {
|
||||
@ -206,7 +206,7 @@ describe('input tests', function() {
|
||||
]);
|
||||
await fileChooser.accept([]);
|
||||
let error = null;
|
||||
await fileChooser.accept([]).catch(e => error = e);
|
||||
await fileChooser.accept([]).catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Cannot accept FileChooser which is already handled!');
|
||||
});
|
||||
});
|
||||
@ -240,7 +240,7 @@ describe('input tests', function() {
|
||||
]);
|
||||
await fileChooser.cancel();
|
||||
let error = null;
|
||||
await fileChooser.cancel().catch(e => error = e);
|
||||
await fileChooser.cancel().catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Cannot cancel FileChooser which is already handled!');
|
||||
});
|
||||
});
|
||||
|
@ -50,7 +50,7 @@ describe('JSHandle', function() {
|
||||
await page.evaluateHandle(
|
||||
opts => opts.elem.querySelector('p'),
|
||||
{elem: aHandle}
|
||||
).catch(e => error = e);
|
||||
).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Are you passing a nested JSHandle?');
|
||||
});
|
||||
it('should accept object handle to unserializable value', async() => {
|
||||
@ -113,7 +113,7 @@ describe('JSHandle', function() {
|
||||
|
||||
const windowHandle = await page.evaluateHandle('window');
|
||||
let error = null;
|
||||
await windowHandle.jsonValue().catch(e => error = e);
|
||||
await windowHandle.jsonValue().catch(error_ => error = error_);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('Object reference chain is too long');
|
||||
else
|
||||
|
@ -233,13 +233,13 @@ describe('Keyboard', function() {
|
||||
it('should throw on unknown keys', async() => {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = await page.keyboard.press('NotARealKey').catch(e => e);
|
||||
let error = await page.keyboard.press('NotARealKey').catch(error_ => error_);
|
||||
expect(error.message).toBe('Unknown key: "NotARealKey"');
|
||||
|
||||
error = await page.keyboard.press('ё').catch(e => e);
|
||||
error = await page.keyboard.press('ё').catch(error_ => error_);
|
||||
expect(error && error.message).toBe('Unknown key: "ё"');
|
||||
|
||||
error = await page.keyboard.press('😊').catch(e => e);
|
||||
error = await page.keyboard.press('😊').catch(error_ => error_);
|
||||
expect(error && error.message).toBe('Unknown key: "😊"');
|
||||
});
|
||||
itFailsFirefox('should type emoji', async() => {
|
||||
|
@ -102,7 +102,7 @@ describe('Launcher specs', function() {
|
||||
const browser = await puppeteer.launch(defaultBrowserOptions);
|
||||
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
|
||||
const page = await remote.newPage();
|
||||
const navigationPromise = page.goto(server.PREFIX + '/one-style.html', {timeout: 60000}).catch(e => e);
|
||||
const navigationPromise = page.goto(server.PREFIX + '/one-style.html', {timeout: 60000}).catch(error_ => error_);
|
||||
await server.waitForRequest('/one-style.css');
|
||||
remote.disconnect();
|
||||
const error = await navigationPromise;
|
||||
@ -116,7 +116,7 @@ describe('Launcher specs', function() {
|
||||
const browser = await puppeteer.launch(defaultBrowserOptions);
|
||||
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
|
||||
const page = await remote.newPage();
|
||||
const watchdog = page.waitForSelector('div', {timeout: 60000}).catch(e => e);
|
||||
const watchdog = page.waitForSelector('div', {timeout: 60000}).catch(error_ => error_);
|
||||
remote.disconnect();
|
||||
const error = await watchdog;
|
||||
expect(error.message).toContain('Protocol error');
|
||||
@ -131,8 +131,8 @@ describe('Launcher specs', function() {
|
||||
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
|
||||
const newPage = await remote.newPage();
|
||||
const results = await Promise.all([
|
||||
newPage.waitForRequest(server.EMPTY_PAGE).catch(e => e),
|
||||
newPage.waitForResponse(server.EMPTY_PAGE).catch(e => e),
|
||||
newPage.waitForRequest(server.EMPTY_PAGE).catch(error => error),
|
||||
newPage.waitForResponse(server.EMPTY_PAGE).catch(error => error),
|
||||
browser.close()
|
||||
]);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
@ -149,7 +149,7 @@ describe('Launcher specs', function() {
|
||||
const browser = await puppeteer.launch(defaultBrowserOptions);
|
||||
const page = await browser.newPage();
|
||||
let error = null;
|
||||
const neverResolves = page.evaluate(() => new Promise(r => {})).catch(e => error = e);
|
||||
const neverResolves = page.evaluate(() => new Promise(r => {})).catch(error_ => error = error_);
|
||||
await browser.close();
|
||||
await neverResolves;
|
||||
expect(error.message).toContain('Protocol error');
|
||||
@ -159,7 +159,7 @@ describe('Launcher specs', function() {
|
||||
|
||||
let waitError = null;
|
||||
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'});
|
||||
await puppeteer.launch(options).catch(e => waitError = e);
|
||||
await puppeteer.launch(options).catch(error => waitError = error);
|
||||
expect(waitError.message).toContain('Failed to launch');
|
||||
});
|
||||
it('userDataDir option', async() => {
|
||||
@ -174,7 +174,7 @@ describe('Launcher specs', function() {
|
||||
await browser.close();
|
||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
await rmAsync(userDataDir).catch(e => {});
|
||||
await rmAsync(userDataDir).catch(error => {});
|
||||
});
|
||||
it('userDataDir argument', async() => {
|
||||
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
|
||||
@ -198,7 +198,7 @@ describe('Launcher specs', function() {
|
||||
await browser.close();
|
||||
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
await rmAsync(userDataDir).catch(e => {});
|
||||
await rmAsync(userDataDir).catch(error => {});
|
||||
});
|
||||
it('userDataDir option should restore state', async() => {
|
||||
const {server, puppeteer, defaultBrowserOptions} = getTestState();
|
||||
@ -217,7 +217,7 @@ describe('Launcher specs', function() {
|
||||
expect(await page2.evaluate(() => localStorage.hey)).toBe('hello');
|
||||
await browser2.close();
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
await rmAsync(userDataDir).catch(e => {});
|
||||
await rmAsync(userDataDir).catch(error => {});
|
||||
});
|
||||
// This mysteriously fails on Windows on AppVeyor. See https://github.com/puppeteer/puppeteer/issues/4111
|
||||
xit('userDataDir option should restore cookies', async() => {
|
||||
@ -237,7 +237,7 @@ describe('Launcher specs', function() {
|
||||
expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true');
|
||||
await browser2.close();
|
||||
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778
|
||||
await rmAsync(userDataDir).catch(e => {});
|
||||
await rmAsync(userDataDir).catch(error => {});
|
||||
});
|
||||
it('should return the default arguments', async() => {
|
||||
const {isChrome, isFirefox, puppeteer} = getTestState();
|
||||
@ -429,7 +429,7 @@ describe('Launcher specs', function() {
|
||||
let error = null;
|
||||
const [serverRequest, response] = await Promise.all([
|
||||
httpsServer.waitForRequest('/empty.html'),
|
||||
page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e)
|
||||
page.goto(httpsServer.EMPTY_PAGE).catch(error_ => error = error_)
|
||||
]);
|
||||
expect(error).toBe(null);
|
||||
expect(response.ok()).toBe(true);
|
||||
|
@ -75,7 +75,7 @@ describe('navigation', function() {
|
||||
res.end();
|
||||
});
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
|
||||
await page.goto(server.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
expect(error).not.toBe(null);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('net::ERR_ABORTED');
|
||||
@ -114,7 +114,7 @@ describe('navigation', function() {
|
||||
const {page, isChrome} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.goto('asdfasdf').catch(e => error = e);
|
||||
await page.goto('asdfasdf').catch(error_ => error = error_);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('Cannot navigate to invalid URL');
|
||||
else
|
||||
@ -129,7 +129,7 @@ describe('navigation', function() {
|
||||
page.on('requestfinished', request => expect(request).toBeTruthy());
|
||||
page.on('requestfailed', request => expect(request).toBeTruthy());
|
||||
let error = null;
|
||||
await page.goto(httpsServer.EMPTY_PAGE).catch(e => error = e);
|
||||
await page.goto(httpsServer.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID');
|
||||
else
|
||||
@ -141,7 +141,7 @@ describe('navigation', function() {
|
||||
server.setRedirect('/redirect/1.html', '/redirect/2.html');
|
||||
server.setRedirect('/redirect/2.html', '/empty.html');
|
||||
let error = null;
|
||||
await page.goto(httpsServer.PREFIX + '/redirect/1.html').catch(e => error = e);
|
||||
await page.goto(httpsServer.PREFIX + '/redirect/1.html').catch(error_ => error = error_);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID');
|
||||
else
|
||||
@ -151,14 +151,14 @@ describe('navigation', function() {
|
||||
const {page, server} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle'}).catch(err => error = err);
|
||||
await page.goto(server.EMPTY_PAGE, {waitUntil: 'networkidle'}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('"networkidle" option is no longer supported');
|
||||
});
|
||||
itFailsFirefox('should fail when main resources failed to load', async() => {
|
||||
const {page, isChrome} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.goto('http://localhost:44123/non-existing-url').catch(e => error = e);
|
||||
await page.goto('http://localhost:44123/non-existing-url').catch(error_ => error = error_);
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('net::ERR_CONNECTION_REFUSED');
|
||||
else
|
||||
@ -170,7 +170,7 @@ describe('navigation', function() {
|
||||
// Hang for request to the empty.html
|
||||
server.setRoute('/empty.html', (req, res) => { });
|
||||
let error = null;
|
||||
await page.goto(server.PREFIX + '/empty.html', {timeout: 1}).catch(e => error = e);
|
||||
await page.goto(server.PREFIX + '/empty.html', {timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
@ -181,7 +181,7 @@ describe('navigation', function() {
|
||||
server.setRoute('/empty.html', (req, res) => { });
|
||||
let error = null;
|
||||
page.setDefaultNavigationTimeout(1);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(e => error = e);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
@ -192,7 +192,7 @@ describe('navigation', function() {
|
||||
server.setRoute('/empty.html', (req, res) => { });
|
||||
let error = null;
|
||||
page.setDefaultTimeout(1);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(e => error = e);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
@ -204,7 +204,7 @@ describe('navigation', function() {
|
||||
let error = null;
|
||||
page.setDefaultTimeout(0);
|
||||
page.setDefaultNavigationTimeout(1);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(e => error = e);
|
||||
await page.goto(server.PREFIX + '/empty.html').catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Navigation timeout of 1 ms exceeded');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
@ -214,7 +214,7 @@ describe('navigation', function() {
|
||||
let error = null;
|
||||
let loaded = false;
|
||||
page.once('load', () => loaded = true);
|
||||
await page.goto(server.PREFIX + '/grid.html', {timeout: 0, waitUntil: ['load']}).catch(e => error = e);
|
||||
await page.goto(server.PREFIX + '/grid.html', {timeout: 0, waitUntil: ['load']}).catch(error_ => error = error_);
|
||||
expect(error).toBe(null);
|
||||
expect(loaded).toBe(true);
|
||||
});
|
||||
@ -324,7 +324,7 @@ describe('navigation', function() {
|
||||
const warningHandler = w => warning = w;
|
||||
process.on('warning', warningHandler);
|
||||
for (let i = 0; i < 20; ++i)
|
||||
await page.goto('asdf').catch(e => {/* swallow navigation error */});
|
||||
await page.goto('asdf').catch(error => {/* swallow navigation error */});
|
||||
process.removeListener('warning', warningHandler);
|
||||
expect(warning).toBe(null);
|
||||
});
|
||||
@ -378,8 +378,8 @@ describe('navigation', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.goto(url);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain(url);
|
||||
});
|
||||
@ -581,7 +581,7 @@ describe('navigation', function() {
|
||||
await page.goto(server.PREFIX + '/frames/one-frame.html');
|
||||
|
||||
server.setRoute('/empty.html', () => {});
|
||||
const navigationPromise = page.frames()[1].goto(server.EMPTY_PAGE).catch(e => e);
|
||||
const navigationPromise = page.frames()[1].goto(server.EMPTY_PAGE).catch(error_ => error_);
|
||||
await server.waitForRequest('/empty.html');
|
||||
|
||||
await page.$eval('iframe', frame => frame.remove());
|
||||
@ -642,7 +642,7 @@ describe('navigation', function() {
|
||||
|
||||
server.setRoute('/empty.html', () => {});
|
||||
let error = null;
|
||||
const navigationPromise = frame.waitForNavigation().catch(e => error = e);
|
||||
const navigationPromise = frame.waitForNavigation().catch(error_ => error = error_);
|
||||
await Promise.all([
|
||||
server.waitForRequest('/empty.html'),
|
||||
frame.evaluate(() => window.location = '/empty.html')
|
||||
|
@ -211,7 +211,7 @@ describe('network', function() {
|
||||
const redirected = redirectChain[0].response();
|
||||
expect(redirected.status()).toBe(302);
|
||||
let error = null;
|
||||
await redirected.text().catch(e => error = e);
|
||||
await redirected.text().catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Response body is unavailable for redirect responses');
|
||||
});
|
||||
it('should wait until response completes', async() => {
|
||||
@ -458,8 +458,8 @@ describe('network', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.setExtraHTTPHeaders({'foo': 1});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.');
|
||||
});
|
||||
|
@ -30,7 +30,7 @@ describe('Page', function() {
|
||||
const newPage = await context.newPage();
|
||||
let error = null;
|
||||
await Promise.all([
|
||||
newPage.evaluate(() => new Promise(r => {})).catch(e => error = e),
|
||||
newPage.evaluate(() => new Promise(r => {})).catch(error_ => error = error_),
|
||||
newPage.close(),
|
||||
]);
|
||||
expect(error.message).toContain('Protocol error');
|
||||
@ -85,8 +85,8 @@ describe('Page', function() {
|
||||
|
||||
const newPage = await context.newPage();
|
||||
const results = await Promise.all([
|
||||
newPage.waitForRequest(server.EMPTY_PAGE).catch(e => e),
|
||||
newPage.waitForResponse(server.EMPTY_PAGE).catch(e => e),
|
||||
newPage.waitForRequest(server.EMPTY_PAGE).catch(error => error),
|
||||
newPage.waitForResponse(server.EMPTY_PAGE).catch(error => error),
|
||||
newPage.close()
|
||||
]);
|
||||
for (let i = 0; i < 2; i++) {
|
||||
@ -117,7 +117,7 @@ describe('Page', function() {
|
||||
res.end();
|
||||
});
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
|
||||
await page.goto(server.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
expect(error).not.toBe(null);
|
||||
expect(error.stack).toContain(__filename);
|
||||
});
|
||||
@ -129,7 +129,7 @@ describe('Page', function() {
|
||||
|
||||
let error = null;
|
||||
page.on('error', err => error = err);
|
||||
page.goto('chrome://crash').catch(e => {});
|
||||
page.goto('chrome://crash').catch(error_ => {});
|
||||
await waitEvent(page, 'error');
|
||||
expect(error.message).toBe('Page crashed!');
|
||||
});
|
||||
@ -217,7 +217,7 @@ describe('Page', function() {
|
||||
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
let error = null;
|
||||
await context.overridePermissions(server.EMPTY_PAGE, ['foo']).catch(e => error = e);
|
||||
await context.overridePermissions(server.EMPTY_PAGE, ['foo']).catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Unknown permission: foo');
|
||||
});
|
||||
itFailsFirefox('should grant permission when listed', async() => {
|
||||
@ -301,8 +301,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.setGeolocation({longitude: 200, latitude: 10});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain('Invalid longitude "200"');
|
||||
});
|
||||
@ -314,7 +314,7 @@ describe('Page', function() {
|
||||
|
||||
await page.setOfflineMode(true);
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
|
||||
await page.goto(server.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
await page.setOfflineMode(false);
|
||||
const response = await page.reload();
|
||||
@ -361,7 +361,7 @@ describe('Page', function() {
|
||||
const prototypeHandle = await page.evaluateHandle(() => HTMLBodyElement.prototype);
|
||||
await prototypeHandle.dispose();
|
||||
let error = null;
|
||||
await page.queryObjects(prototypeHandle).catch(e => error = e);
|
||||
await page.queryObjects(prototypeHandle).catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Prototype JSHandle is disposed!');
|
||||
});
|
||||
it('should fail primitive values as prototypes', async() => {
|
||||
@ -369,7 +369,7 @@ describe('Page', function() {
|
||||
|
||||
const prototypeHandle = await page.evaluateHandle(() => 42);
|
||||
let error = null;
|
||||
await page.queryObjects(prototypeHandle).catch(e => error = e);
|
||||
await page.queryObjects(prototypeHandle).catch(error_ => error = error_);
|
||||
expect(error.message).toBe('Prototype JSHandle must not be referencing primitive value');
|
||||
});
|
||||
});
|
||||
@ -435,7 +435,7 @@ describe('Page', function() {
|
||||
await page.goto('about:blank');
|
||||
const [message] = await Promise.all([
|
||||
waitEvent(page, 'console'),
|
||||
page.evaluate(async url => fetch(url).catch(e => {}), server.EMPTY_PAGE)
|
||||
page.evaluate(async url => fetch(url).catch(error => {}), server.EMPTY_PAGE)
|
||||
]);
|
||||
expect(message.text()).toContain('Access-Control-Allow-Origin');
|
||||
if (isChrome)
|
||||
@ -582,7 +582,7 @@ describe('Page', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForRequest(() => false, {timeout: 1}).catch(e => error = e);
|
||||
await page.waitForRequest(() => false, {timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should respect default timeout', async() => {
|
||||
@ -590,7 +590,7 @@ describe('Page', function() {
|
||||
|
||||
let error = null;
|
||||
page.setDefaultTimeout(1);
|
||||
await page.waitForRequest(() => false).catch(e => error = e);
|
||||
await page.waitForRequest(() => false).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should work with no timeout', async() => {
|
||||
@ -628,7 +628,7 @@ describe('Page', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForResponse(() => false, {timeout: 1}).catch(e => error = e);
|
||||
await page.waitForResponse(() => false, {timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should respect default timeout', async() => {
|
||||
@ -636,7 +636,7 @@ describe('Page', function() {
|
||||
|
||||
let error = null;
|
||||
page.setDefaultTimeout(1);
|
||||
await page.waitForResponse(() => false).catch(e => error = e);
|
||||
await page.waitForResponse(() => false).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
itFailsFirefox('should work with predicate', async() => {
|
||||
@ -690,8 +690,8 @@ describe('Page', function() {
|
||||
const {message, stack} = await page.evaluate(async() => {
|
||||
try {
|
||||
await woof();
|
||||
} catch (e) {
|
||||
return {message: e.message, stack: e.stack};
|
||||
} catch (error) {
|
||||
return {message: error.message, stack: error.stack};
|
||||
}
|
||||
});
|
||||
expect(message).toBe('WOOF WOOF');
|
||||
@ -706,8 +706,8 @@ describe('Page', function() {
|
||||
const thrown = await page.evaluate(async() => {
|
||||
try {
|
||||
await woof();
|
||||
} catch (e) {
|
||||
return e;
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
});
|
||||
expect(thrown).toBe(null);
|
||||
@ -867,7 +867,7 @@ describe('Page', function() {
|
||||
// stall for image
|
||||
server.setRoute(imgPath, (req, res) => {});
|
||||
let error = null;
|
||||
await page.setContent(`<img src="${server.PREFIX + imgPath}"></img>`, {timeout: 1}).catch(e => error = e);
|
||||
await page.setContent(`<img src="${server.PREFIX + imgPath}"></img>`, {timeout: 1}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should respect default navigation timeout', async() => {
|
||||
@ -878,7 +878,7 @@ describe('Page', function() {
|
||||
// stall for image
|
||||
server.setRoute(imgPath, (req, res) => {});
|
||||
let error = null;
|
||||
await page.setContent(`<img src="${server.PREFIX + imgPath}"></img>`).catch(e => error = e);
|
||||
await page.setContent(`<img src="${server.PREFIX + imgPath}"></img>`).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
it('should await resources to load', async() => {
|
||||
@ -932,7 +932,7 @@ describe('Page', function() {
|
||||
|
||||
// Make sure CSP prohibits addScriptTag.
|
||||
await page.goto(server.PREFIX + '/csp.html');
|
||||
await page.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
|
||||
await page.addScriptTag({content: 'window.__injected = 42;'}).catch(error => void error);
|
||||
expect(await page.evaluate(() => window.__injected)).toBe(undefined);
|
||||
|
||||
// By-pass CSP and try one more time.
|
||||
@ -948,7 +948,7 @@ describe('Page', function() {
|
||||
// Make sure CSP prohibits addScriptTag.
|
||||
server.setCSP('/empty.html', 'default-src "self"');
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
|
||||
await page.addScriptTag({content: 'window.__injected = 42;'}).catch(error => void error);
|
||||
expect(await page.evaluate(() => window.__injected)).toBe(undefined);
|
||||
|
||||
// By-pass CSP and try one more time.
|
||||
@ -977,7 +977,7 @@ describe('Page', function() {
|
||||
{
|
||||
// Make sure CSP prohibits addScriptTag in an iframe.
|
||||
const frame = await utils.attachFrame(page, 'frame1', server.PREFIX + '/csp.html');
|
||||
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
|
||||
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(error => void error);
|
||||
expect(await frame.evaluate(() => window.__injected)).toBe(undefined);
|
||||
}
|
||||
|
||||
@ -987,7 +987,7 @@ describe('Page', function() {
|
||||
|
||||
{
|
||||
const frame = await utils.attachFrame(page, 'frame1', server.PREFIX + '/csp.html');
|
||||
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(e => void e);
|
||||
await frame.addScriptTag({content: 'window.__injected = 42;'}).catch(error => void error);
|
||||
expect(await frame.evaluate(() => window.__injected)).toBe(42);
|
||||
}
|
||||
});
|
||||
@ -1000,8 +1000,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.addScriptTag('/injectedfile.js');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property');
|
||||
});
|
||||
@ -1048,8 +1048,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.addScriptTag({url: '/nonexistfile.js'});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Loading script from /nonexistfile.js failed');
|
||||
});
|
||||
@ -1087,7 +1087,7 @@ describe('Page', function() {
|
||||
|
||||
await page.goto(server.PREFIX + '/csp.html');
|
||||
let error = null;
|
||||
await page.addScriptTag({content: 'window.__injected = 35;'}).catch(e => error = e);
|
||||
await page.addScriptTag({content: 'window.__injected = 35;'}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1096,7 +1096,7 @@ describe('Page', function() {
|
||||
|
||||
await page.goto(server.PREFIX + '/csp.html');
|
||||
let error = null;
|
||||
await page.addScriptTag({url: server.CROSS_PROCESS_PREFIX + '/injectedfile.js'}).catch(e => error = e);
|
||||
await page.addScriptTag({url: server.CROSS_PROCESS_PREFIX + '/injectedfile.js'}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1108,8 +1108,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.addStyleTag('/injectedstyle.css');
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property');
|
||||
});
|
||||
@ -1130,8 +1130,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.addStyleTag({url: '/nonexistfile.js'});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toBe('Loading style from /nonexistfile.js failed');
|
||||
});
|
||||
@ -1169,7 +1169,7 @@ describe('Page', function() {
|
||||
|
||||
await page.goto(server.PREFIX + '/csp.html');
|
||||
let error = null;
|
||||
await page.addStyleTag({content: 'body { background-color: green; }'}).catch(e => error = e);
|
||||
await page.addStyleTag({content: 'body { background-color: green; }'}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
|
||||
@ -1178,7 +1178,7 @@ describe('Page', function() {
|
||||
|
||||
await page.goto(server.PREFIX + '/csp.html');
|
||||
let error = null;
|
||||
await page.addStyleTag({url: server.CROSS_PROCESS_PREFIX + '/injectedstyle.css'}).catch(e => error = e);
|
||||
await page.addStyleTag({url: server.CROSS_PROCESS_PREFIX + '/injectedstyle.css'}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1200,7 +1200,7 @@ describe('Page', function() {
|
||||
await page.setJavaScriptEnabled(false);
|
||||
await page.goto('data:text/html, <script>var something = "forbidden"</script>');
|
||||
let error = null;
|
||||
await page.evaluate('something').catch(e => error = e);
|
||||
await page.evaluate('something').catch(error_ => error = error_);
|
||||
expect(error.message).toContain('something is not defined');
|
||||
|
||||
await page.setJavaScriptEnabled(true);
|
||||
@ -1317,7 +1317,7 @@ describe('Page', function() {
|
||||
|
||||
let error = null;
|
||||
await page.goto(server.PREFIX + '/input/select.html');
|
||||
await page.select('body', '').catch(e => error = e);
|
||||
await page.select('body', '').catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Element is not a <select> element.');
|
||||
});
|
||||
it('should return [] on no matched values', async() => {
|
||||
@ -1373,8 +1373,8 @@ describe('Page', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.select('select', 12);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error.message).toContain('Values must be strings');
|
||||
});
|
||||
|
@ -46,7 +46,7 @@ describe('querySelector', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.$eval('section', e => e.id).catch(e => error = e);
|
||||
await page.$eval('section', e => e.id).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('failed to find element matching selector "section"');
|
||||
});
|
||||
});
|
||||
|
@ -202,7 +202,7 @@ describe('request interception', function() {
|
||||
});
|
||||
let failedRequest = null;
|
||||
page.on('requestfailed', request => failedRequest = request);
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => {});
|
||||
await page.goto(server.EMPTY_PAGE).catch(error => {});
|
||||
expect(failedRequest).toBeTruthy();
|
||||
expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED');
|
||||
});
|
||||
@ -226,7 +226,7 @@ describe('request interception', function() {
|
||||
await page.setRequestInterception(true);
|
||||
page.on('request', request => request.abort());
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
|
||||
await page.goto(server.EMPTY_PAGE).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
if (isChrome)
|
||||
expect(error.message).toContain('net::ERR_FAILED');
|
||||
@ -305,8 +305,8 @@ describe('request interception', function() {
|
||||
const result = await page.evaluate(async() => {
|
||||
try {
|
||||
await fetch('/non-existing.json');
|
||||
} catch (e) {
|
||||
return e.message;
|
||||
} catch (error) {
|
||||
return error.message;
|
||||
}
|
||||
});
|
||||
if (isChrome)
|
||||
@ -333,9 +333,9 @@ describe('request interception', function() {
|
||||
spinner = !spinner;
|
||||
});
|
||||
const results = await page.evaluate(() => Promise.all([
|
||||
fetch('/zzz').then(response => response.text()).catch(e => 'FAILED'),
|
||||
fetch('/zzz').then(response => response.text()).catch(e => 'FAILED'),
|
||||
fetch('/zzz').then(response => response.text()).catch(e => 'FAILED'),
|
||||
fetch('/zzz').then(response => response.text()).catch(error => 'FAILED'),
|
||||
fetch('/zzz').then(response => response.text()).catch(error => 'FAILED'),
|
||||
fetch('/zzz').then(response => response.text()).catch(error => 'FAILED'),
|
||||
]));
|
||||
expect(results).toEqual(['11', 'FAILED', '22']);
|
||||
});
|
||||
@ -433,7 +433,7 @@ describe('request interception', function() {
|
||||
// Delete frame to cause request to be canceled.
|
||||
await page.$eval('iframe', frame => frame.remove());
|
||||
let error = null;
|
||||
await request.continue().catch(e => error = e);
|
||||
await request.continue().catch(error_ => error = error_);
|
||||
expect(error).toBe(null);
|
||||
});
|
||||
it('should throw if interception is not enabled', async() => {
|
||||
@ -443,8 +443,8 @@ describe('request interception', function() {
|
||||
page.on('request', async request => {
|
||||
try {
|
||||
await request.continue();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
});
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
@ -257,7 +257,7 @@ describe('Screenshots', function() {
|
||||
|
||||
await page.setContent('<div style="width: 50px; height: 0"></div>');
|
||||
const div = await page.$('div');
|
||||
const error = await div.screenshot().catch(e => e);
|
||||
const error = await div.screenshot().catch(error_ => error_);
|
||||
expect(error.message).toBe('Node has 0 height.');
|
||||
});
|
||||
itFailsFirefox('should work for an element with fractional dimensions', async() => {
|
||||
|
@ -202,7 +202,7 @@ describe('Target', function() {
|
||||
let error = null;
|
||||
await browser.waitForTarget(target => target.url() === server.EMPTY_PAGE, {
|
||||
timeout: 1
|
||||
}).catch(e => error = e);
|
||||
}).catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
});
|
||||
});
|
||||
|
@ -64,7 +64,7 @@ describeChromeOnly('Tracing', function() {
|
||||
await page.tracing.start({path: outputFile});
|
||||
const newPage = await browser.newPage();
|
||||
let error = null;
|
||||
await newPage.tracing.start({path: outputFile}).catch(e => error = e);
|
||||
await newPage.tracing.start({path: outputFile}).catch(error_ => error = error_);
|
||||
await newPage.close();
|
||||
expect(error).toBeTruthy();
|
||||
await page.tracing.stop();
|
||||
|
@ -51,7 +51,7 @@ describe('waittask specs', function() {
|
||||
|
||||
await page.setContent(`<div>some text</div>`);
|
||||
let error = null;
|
||||
await page.waitFor('/html/body/div').catch(e => error = e);
|
||||
await page.waitFor('/html/body/div').catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
});
|
||||
it('should timeout', async() => {
|
||||
@ -82,7 +82,7 @@ describe('waittask specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitFor({foo: 'bar'}).catch(e => error = e);
|
||||
await page.waitFor({foo: 'bar'}).catch(error_ => error = error_);
|
||||
expect(error.message).toContain('Unsupported target type');
|
||||
});
|
||||
it('should wait for predicate with arguments', async() => {
|
||||
@ -149,7 +149,7 @@ describe('waittask specs', function() {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
let error = null;
|
||||
await Promise.all([
|
||||
page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}).catch(e => error = e),
|
||||
page.waitForFunction(() => window.__FOO === 'hit', {polling: 'raf'}).catch(error_ => error = error_),
|
||||
page.evaluate(() => window.__FOO = 'hit')
|
||||
]);
|
||||
expect(error).toBe(null);
|
||||
@ -160,8 +160,8 @@ describe('waittask specs', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.waitForFunction(() => !!document.body, {polling: 'unknown'});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('polling');
|
||||
@ -172,8 +172,8 @@ describe('waittask specs', function() {
|
||||
let error = null;
|
||||
try {
|
||||
await page.waitForFunction(() => !!document.body, {polling: -10});
|
||||
} catch (e) {
|
||||
error = e;
|
||||
} catch (error_) {
|
||||
error = error_;
|
||||
}
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('Cannot poll with non-positive interval');
|
||||
@ -203,7 +203,7 @@ describe('waittask specs', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForFunction('false', {timeout: 10}).catch(e => error = e);
|
||||
await page.waitForFunction('false', {timeout: 10}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('waiting for function failed: timeout');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
@ -213,7 +213,7 @@ describe('waittask specs', function() {
|
||||
|
||||
page.setDefaultTimeout(1);
|
||||
let error = null;
|
||||
await page.waitForFunction('false').catch(e => error = e);
|
||||
await page.waitForFunction('false').catch(error_ => error = error_);
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
expect(error.message).toContain('waiting for function failed: timeout');
|
||||
});
|
||||
@ -334,7 +334,7 @@ describe('waittask specs', function() {
|
||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
const frame = page.frames()[1];
|
||||
let waitError = null;
|
||||
const waitPromise = frame.waitForSelector('.box').catch(e => waitError = e);
|
||||
const waitPromise = frame.waitForSelector('.box').catch(error => waitError = error);
|
||||
await utils.detachFrame(page, 'frame1');
|
||||
await waitPromise;
|
||||
expect(waitError).toBeTruthy();
|
||||
@ -425,7 +425,7 @@ describe('waittask specs', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForSelector('div', {timeout: 10}).catch(e => error = e);
|
||||
await page.waitForSelector('div', {timeout: 10}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('waiting for selector "div" failed: timeout');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
@ -435,7 +435,7 @@ describe('waittask specs', function() {
|
||||
|
||||
await page.setContent(`<div></div>`);
|
||||
let error = null;
|
||||
await page.waitForSelector('div', {hidden: true, timeout: 10}).catch(e => error = e);
|
||||
await page.waitForSelector('div', {hidden: true, timeout: 10}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('waiting for selector "div" to be hidden failed: timeout');
|
||||
});
|
||||
@ -461,7 +461,7 @@ describe('waittask specs', function() {
|
||||
const {page} = getTestState();
|
||||
|
||||
let error;
|
||||
await page.waitForSelector('.zombo', {timeout: 10}).catch(e => error = e);
|
||||
await page.waitForSelector('.zombo', {timeout: 10}).catch(error_ => error = error_);
|
||||
expect(error.stack).toContain('waittask.spec.js');
|
||||
});
|
||||
});
|
||||
@ -480,7 +480,7 @@ describe('waittask specs', function() {
|
||||
const {page, puppeteer} = getTestState();
|
||||
|
||||
let error = null;
|
||||
await page.waitForXPath('//div', {timeout: 10}).catch(e => error = e);
|
||||
await page.waitForXPath('//div', {timeout: 10}).catch(error_ => error = error_);
|
||||
expect(error).toBeTruthy();
|
||||
expect(error.message).toContain('waiting for XPath "//div" failed: timeout');
|
||||
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
|
||||
@ -504,7 +504,7 @@ describe('waittask specs', function() {
|
||||
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
|
||||
const frame = page.frames()[1];
|
||||
let waitError = null;
|
||||
const waitPromise = frame.waitForXPath('//*[@class="box"]').catch(e => waitError = e);
|
||||
const waitPromise = frame.waitForXPath('//*[@class="box"]').catch(error => waitError = error);
|
||||
await utils.detachFrame(page, 'frame1');
|
||||
await waitPromise;
|
||||
expect(waitError).toBeTruthy();
|
||||
|
@ -37,8 +37,8 @@ const fileExists = async filePath => fsAccess(filePath).then(() => true).catch((
|
||||
* place.
|
||||
*/
|
||||
async function compileTypeScript() {
|
||||
return exec('npm run tsc').catch(err => {
|
||||
console.error('Error running TypeScript', err);
|
||||
return exec('npm run tsc').catch(error => {
|
||||
console.error('Error running TypeScript', error);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
|
@ -80,8 +80,8 @@ async function main(url) {
|
||||
let json = null;
|
||||
try {
|
||||
json = JSON.parse(text);
|
||||
} catch (e) {
|
||||
console.error(`FAILED: error parsing response - ${e.message}`);
|
||||
} catch (error) {
|
||||
console.error(`FAILED: error parsing response - ${error.message}`);
|
||||
return;
|
||||
}
|
||||
const devicePayloads = json.extensions.filter(extension => extension.type === 'emulated-device').map(extension => extension.device);
|
||||
|
Loading…
Reference in New Issue
Block a user