chore: enforce naming of errors in catch blocks (#5763)

This commit is contained in:
Jack Franklin 2020-04-28 14:16:28 +01:00 committed by GitHub
parent 3bf9bd199d
commit 1ccfbcb684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 191 additions and 186 deletions

View File

@ -9,7 +9,8 @@ module.exports = {
"plugins": [ "plugins": [
"mocha", "mocha",
"@typescript-eslint" "@typescript-eslint",
"unicorn"
], ],
"rules": { "rules": {
@ -99,7 +100,10 @@ module.exports = {
}], }],
// ensure we don't have any it.only or describe.only in prod // 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": [ "overrides": [
{ {

View File

@ -69,6 +69,7 @@
"cross-env": "^5.0.5", "cross-env": "^5.0.5",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-plugin-mocha": "^6.3.0", "eslint-plugin-mocha": "^6.3.0",
"eslint-plugin-unicorn": "^19.0.1",
"esprima": "^4.0.0", "esprima": "^4.0.0",
"expect": "^25.2.7", "expect": "^25.2.7",
"jpeg-js": "^0.3.7", "jpeg-js": "^0.3.7",

View File

@ -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 { function httpRequest(url: string, method: string, response: (x: http.IncomingMessage) => void): http.ClientRequest {

View File

@ -105,9 +105,9 @@ class JSCoverage {
const response = await this._client.send('Debugger.getScriptSource', {scriptId: event.scriptId}); const response = await this._client.send('Debugger.getScriptSource', {scriptId: event.scriptId});
this._scriptURLs.set(event.scriptId, event.url); this._scriptURLs.set(event.scriptId, event.url);
this._scriptSources.set(event.scriptId, response.scriptSource); this._scriptSources.set(event.scriptId, response.scriptSource);
} catch (e) { } catch (error) {
// This might happen if the page has already navigated away. // 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}); const response = await this._client.send('CSS.getStyleSheetText', {styleSheetId: header.styleSheetId});
this._stylesheetURLs.set(header.styleSheetId, header.sourceURL); this._stylesheetURLs.set(header.styleSheetId, header.sourceURL);
this._stylesheetSources.set(header.styleSheetId, response.text); this._stylesheetSources.set(header.styleSheetId, response.text);
} catch (e) { } catch (error) {
// This might happen if the page has already navigated away. // This might happen if the page has already navigated away.
debugError(e); debugError(error);
} }
} }

View File

@ -579,8 +579,8 @@ class WaitTask {
let error = null; let error = null;
try { try {
success = await (await this._domWorld.executionContext()).evaluateHandle(waitForPredicatePageFunction, this._predicateBody, this._polling, this._timeout, ...this._args); success = await (await this._domWorld.executionContext()).evaluateHandle(waitForPredicatePageFunction, this._predicateBody, this._polling, this._timeout, ...this._args);
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
if (this._terminated || runCount !== this._runCount) { if (this._terminated || runCount !== this._runCount) {
@ -592,7 +592,7 @@ class WaitTask {
// Ignore timeouts in pageScript - we track timeouts ourselves. // Ignore timeouts in pageScript - we track timeouts ourselves.
// If the frame's execution context has already changed, `frame.evaluate` will // If the frame's execution context has already changed, `frame.evaluate` will
// throw an error - ignore this predicate run altogether. // 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(); await success.dispose();
return; return;
} }

View File

@ -72,7 +72,7 @@ export class ExecutionContext {
let functionText = pageFunction.toString(); let functionText = pageFunction.toString();
try { try {
new Function('(' + functionText + ')'); new Function('(' + functionText + ')');
} catch (e1) { } catch (error) {
// This means we might have a function shorthand. Try another // This means we might have a function shorthand. Try another
// time prefixing 'function '. // time prefixing 'function '.
if (functionText.startsWith('async ')) if (functionText.startsWith('async '))
@ -81,7 +81,7 @@ export class ExecutionContext {
functionText = 'function ' + functionText; functionText = 'function ' + functionText;
try { try {
new Function('(' + functionText + ')'); new Function('(' + functionText + ')');
} catch (e2) { } catch (error) {
// We tried hard to serialize, but there's a weird beast here. // We tried hard to serialize, but there's a weird beast here.
throw new Error('Passed function is not well-serializable!'); throw new Error('Passed function is not well-serializable!');
} }
@ -96,10 +96,10 @@ export class ExecutionContext {
awaitPromise: true, awaitPromise: true,
userGesture: true userGesture: true
}); });
} catch (err) { } catch (error) {
if (err instanceof TypeError && err.message.startsWith('Converting circular structure to JSON')) if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON'))
err.message += ' Are you passing a nested JSHandle?'; error.message += ' Are you passing a nested JSHandle?';
throw err; throw error;
} }
const {exceptionDetails, result: remoteObject} = await callFunctionOnPromise.catch(rewriteError); const {exceptionDetails, result: remoteObject} = await callFunctionOnPromise.catch(rewriteError);
if (exceptionDetails) if (exceptionDetails)

View File

@ -98,7 +98,7 @@ class BrowserRunner {
if (this._tempDirectory) { if (this._tempDirectory) {
removeFolderAsync(this._tempDirectory) removeFolderAsync(this._tempDirectory)
.then(() => fulfill()) .then(() => fulfill())
.catch(err => console.error(err)); .catch(error => console.error(error));
} else { } else {
fulfill(); fulfill();
} }
@ -819,9 +819,9 @@ function getWSEndpoint(browserURL) {
request.on('error', reject); request.on('error', reject);
request.end(); request.end();
return promise.catch(e => { return promise.catch(error => {
e.message = `Failed to fetch browser webSocket url from ${endpointURL}: ` + e.message; error.message = `Failed to fetch browser webSocket url from ${endpointURL}: ` + error.message;
throw e; throw error;
}); });
} }

View File

@ -179,9 +179,9 @@ class Page extends EventEmitter {
let callback; let callback;
const promise = new Promise(x => callback = x); const promise = new Promise(x => callback = x);
this._fileChooserInterceptors.add(callback); 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); this._fileChooserInterceptors.delete(callback);
throw e; throw error;
}); });
} }
@ -851,10 +851,10 @@ class Page extends EventEmitter {
async emulateTimezone(timezoneId) { async emulateTimezone(timezoneId) {
try { try {
await this._client.send('Emulation.setTimezoneOverride', {timezoneId: timezoneId || ''}); await this._client.send('Emulation.setTimezoneOverride', {timezoneId: timezoneId || ''});
} catch (exception) { } catch (error) {
if (exception.message.includes('Invalid timezone')) if (error.message.includes('Invalid timezone'))
throw new Error(`Invalid timezone ID: ${timezoneId}`); throw new Error(`Invalid timezone ID: ${timezoneId}`);
throw exception; throw error;
} }
} }

View File

@ -90,12 +90,12 @@ function installAsyncStackHooks(classType: AnyClass): void {
stack: '' stack: ''
}; };
Error.captureStackTrace(syncStack); 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 stack = syncStack.stack.substring(syncStack.stack.indexOf('\n') + 1);
const clientStack = stack.substring(stack.indexOf('\n')); const clientStack = stack.substring(stack.indexOf('\n'));
if (e instanceof Error && e.stack && !e.stack.includes(clientStack)) if (error instanceof Error && error.stack && !error.stack.includes(clientStack))
e.stack += '\n -- ASYNC --\n' + stack; error.stack += '\n -- ASYNC --\n' + stack;
throw e; 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 => { const result = await Promise.race([promise, abortPromise]).then(r => {
cleanup(); cleanup();
return r; return r;
}, e => { }, error => {
cleanup(); cleanup();
throw e; throw error;
}); });
if (result instanceof Error) if (result instanceof Error)
throw result; throw result;

View File

@ -72,8 +72,8 @@ describeChromeOnly('Target.createCDPSession', function() {
let error = null; let error = null;
try { try {
await client.send('Runtime.evaluate', {expression: '3 + 1', returnByValue: true}); await client.send('Runtime.evaluate', {expression: '3 + 1', returnByValue: true});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain('Session closed.'); expect(error.message).toContain('Session closed.');
}); });

View File

@ -26,7 +26,7 @@ describe('BrowserContext', function() {
const defaultContext = browser.browserContexts()[0]; const defaultContext = browser.browserContexts()[0];
expect(defaultContext.isIncognito()).toBe(false); expect(defaultContext.isIncognito()).toBe(false);
let error = null; let error = null;
await defaultContext.close().catch(e => error = e); await defaultContext.close().catch(error_ => error = error_);
expect(browser.defaultBrowserContext()).toBe(defaultContext); expect(browser.defaultBrowserContext()).toBe(defaultContext);
expect(error.message).toContain('cannot be closed'); expect(error.message).toContain('cannot be closed');
}); });
@ -104,7 +104,7 @@ describe('BrowserContext', function() {
const {browser, server, puppeteer} = getTestState(); const {browser, server, puppeteer} = getTestState();
const context = await browser.createIncognitoBrowserContext(); 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
await context.close(); await context.close();
}); });

View File

@ -46,7 +46,7 @@ describeChromeOnly('Chromium-Specific Launcher tests', function() {
const browserURL = 'http://127.0.0.1:21222'; const browserURL = 'http://127.0.0.1:21222';
let error = null; 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'); expect(error.message).toContain('Exactly one of browserWSEndpoint, browserURL or transport');
originalBrowser.close(); originalBrowser.close();
@ -60,7 +60,7 @@ describeChromeOnly('Chromium-Specific Launcher tests', function() {
const browserURL = 'http://127.0.0.1:32333'; const browserURL = 'http://127.0.0.1:32333';
let error = null; 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'); expect(error.message).toContain('Failed to fetch browser webSocket url from');
originalBrowser.close(); originalBrowser.close();
}); });

View File

@ -69,7 +69,7 @@ describe('Page.click', function() {
await Promise.all([ await Promise.all([
newPage.close(), newPage.close(),
newPage.mouse.click(1, 2), newPage.mouse.click(1, 2),
]).catch(e => {}); ]).catch(error => {});
}); });
it('should click the button after navigation ', async() => { it('should click the button after navigation ', async() => {
const {page, server} = getTestState(); const {page, server} = getTestState();
@ -197,7 +197,7 @@ describe('Page.click', function() {
await page.goto(server.PREFIX + '/input/button.html'); await page.goto(server.PREFIX + '/input/button.html');
let error = null; 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'); expect(error.message).toBe('No node found for selector: button.does-not-exist');
}); });
// @see https://github.com/puppeteer/puppeteer/issues/161 // @see https://github.com/puppeteer/puppeteer/issues/161

View File

@ -270,8 +270,8 @@ describe('Cookie specs', () => {
let error = null; let error = null;
try { try {
await page.setCookie({name: 'example-cookie', value: 'best'}); await page.setCookie({name: 'example-cookie', value: 'best'});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain('At least one of the url and domain needs to be specified'); 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'}, {name: 'example-cookie', value: 'best'},
{url: 'about:blank', name: 'example-cookie-blank', value: 'best'} {url: 'about:blank', name: 'example-cookie-blank', value: 'best'}
); );
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toEqual( expect(error.message).toEqual(
`Blank page can not have cookie "example-cookie-blank"` `Blank page can not have cookie "example-cookie-blank"`
@ -299,8 +299,8 @@ describe('Cookie specs', () => {
await page.goto('data:,Hello%2C%20World!'); await page.goto('data:,Hello%2C%20World!');
try { try {
await page.setCookie({name: 'example-cookie', value: 'best'}); await page.setCookie({name: 'example-cookie', value: 'best'});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain('At least one of the url and domain needs to be specified'); expect(error.message).toContain('At least one of the url and domain needs to be specified');
}); });

View File

@ -183,7 +183,7 @@ describe('ElementHandle specs', function() {
await page.goto(server.PREFIX + '/input/button.html'); await page.goto(server.PREFIX + '/input/button.html');
const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild); const buttonTextNode = await page.evaluateHandle(() => document.querySelector('button').firstChild);
let error = null; 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'); expect(error.message).toBe('Node is not of type HTMLElement');
}); });
it('should throw for detached nodes', async() => { it('should throw for detached nodes', async() => {
@ -193,7 +193,7 @@ describe('ElementHandle specs', function() {
const button = await page.$('button'); const button = await page.$('button');
await page.evaluate(button => button.remove(), button); await page.evaluate(button => button.remove(), button);
let error = null; 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'); expect(error.message).toBe('Node is detached from document');
}); });
it('should throw for hidden nodes', async() => { it('should throw for hidden nodes', async() => {
@ -202,7 +202,7 @@ describe('ElementHandle specs', function() {
await page.goto(server.PREFIX + '/input/button.html'); await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button'); const button = await page.$('button');
await page.evaluate(button => button.style.display = 'none', 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'); expect(error.message).toBe('Node is either not visible or not an HTMLElement');
}); });
it('should throw for recursively hidden nodes', async() => { it('should throw for recursively hidden nodes', async() => {
@ -211,7 +211,7 @@ describe('ElementHandle specs', function() {
await page.goto(server.PREFIX + '/input/button.html'); await page.goto(server.PREFIX + '/input/button.html');
const button = await page.$('button'); const button = await page.$('button');
await page.evaluate(button => button.parentElement.style.display = 'none', 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'); expect(error.message).toBe('Node is either not visible or not an HTMLElement');
}); });
itFailsFirefox('should throw for <br> elements', async() => { itFailsFirefox('should throw for <br> elements', async() => {
@ -219,7 +219,7 @@ describe('ElementHandle specs', function() {
await page.setContent('hello<br>goodbye'); await page.setContent('hello<br>goodbye');
const br = await page.$('br'); 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'); expect(error.message).toBe('Node is either not visible or not an HTMLElement');
}); });
}); });

View File

@ -148,7 +148,7 @@ describe('Emulation', () => {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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'); expect(error.message).toBe('Unsupported media type: bad');
}); });
}); });
@ -173,7 +173,7 @@ describe('Emulation', () => {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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'); expect(error.message).toBe('Unsupported media type: bad');
}); });
}); });
@ -213,7 +213,7 @@ describe('Emulation', () => {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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'); expect(error.message).toBe('Unsupported media feature: bad');
}); });
}); });
@ -242,9 +242,9 @@ describe('Emulation', () => {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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'); 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'); expect(error.message).toBe('Invalid timezone ID: Baz/Qux');
}); });
}); });

View File

@ -115,7 +115,7 @@ describe('Evaluation specs', function() {
await page.evaluate(() => { await page.evaluate(() => {
location.reload(); location.reload();
return new Promise(() => {}); return new Promise(() => {});
}).catch(e => error = e); }).catch(error_ => error = error_);
expect(error.message).toContain('Protocol error'); expect(error.message).toContain('Protocol error');
}); });
it('should await promise', async() => { it('should await promise', async() => {
@ -150,7 +150,7 @@ describe('Evaluation specs', function() {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('not_existing_object'); expect(error.message).toContain('not_existing_object');
}); });
@ -158,7 +158,7 @@ describe('Evaluation specs', function() {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('qwerty'); expect(error.message).toContain('qwerty');
}); });
@ -166,7 +166,7 @@ describe('Evaluation specs', function() {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('100500'); expect(error.message).toContain('100500');
}); });
@ -239,10 +239,10 @@ describe('Evaluation specs', function() {
const {page} = getTestState(); const {page} = getTestState();
const windowHandle = await page.evaluateHandle(() => window); 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 => { const error = await page.evaluate(errorText => {
throw new Error(errorText); throw new Error(errorText);
}, errorText).catch(e => e); }, errorText).catch(error_ => error_);
expect(error.message).toContain(errorText); expect(error.message).toContain(errorText);
}); });
it('should accept a string', async() => { it('should accept a string', async() => {
@ -279,7 +279,7 @@ describe('Evaluation specs', function() {
expect(element).toBeTruthy(); expect(element).toBeTruthy();
await element.dispose(); await element.dispose();
let error = null; 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'); expect(error.message).toContain('JSHandle is disposed');
}); });
itFailsFirefox('should throw if elementHandles are from other frames', async() => { 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); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
const bodyHandle = await page.frames()[1].$('body'); const bodyHandle = await page.frames()[1].$('body');
let error = null; 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).toBeTruthy();
expect(error.message).toContain('JSHandles can be evaluated only in the context they were created'); 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(), page.waitForNavigation(),
executionContext.evaluate(() => window.location.reload()) 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'); expect(error.message).toContain('navigation');
}); });
itFailsFirefox('should not throw an error when evaluation does a navigation', async() => { itFailsFirefox('should not throw an error when evaluation does a navigation', async() => {
@ -336,7 +336,7 @@ describe('Evaluation specs', function() {
let error = null; let error = null;
await page.evaluate(() => new Promise(() => { await page.evaluate(() => new Promise(() => {
throw new Error('Error in promise'); throw new Error('Error in promise');
})).catch(e => error = e); })).catch(error_ => error = error_);
expect(error.message).toContain('Error in promise'); expect(error.message).toContain('Error in promise');
}); });
}); });
@ -362,7 +362,7 @@ describe('Evaluation specs', function() {
expect(await page.evaluate(() => window.injected)).toBe(123); expect(await page.evaluate(() => window.injected)).toBe(123);
// Make sure CSP works. // 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); expect(await page.evaluate(() => window.e)).toBe(undefined);
}); });
}); });

View File

@ -69,7 +69,7 @@ describe('Frame specs', function() {
const frame1 = await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); const frame1 = await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
await utils.detachFrame(page, 'frame1'); await utils.detachFrame(page, 'frame1');
let error = null; 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'); expect(error.message).toContain('Execution Context is not available in detached frame');
}); });
}); });

View File

@ -109,7 +109,7 @@ describeChromeOnly('headful tests', function() {
const cookie = await headlessPage.evaluate(() => document.cookie); const cookie = await headlessPage.evaluate(() => document.cookie);
await headlessBrowser.close(); await headlessBrowser.close();
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 // 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'); expect(cookie).toBe('foo=true');
}); });
// TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548 // TODO: Support OOOPIF. @see https://github.com/puppeteer/puppeteer/issues/2548

View File

@ -92,7 +92,7 @@ describeFailsFirefox('ignoreHTTPSErrors', function() {
const {httpsServer} = getTestState(); const {httpsServer} = getTestState();
let error = null; 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(error).toBe(null);
expect(response.ok()).toBe(true); expect(response.ok()).toBe(true);
}); });

View File

@ -77,7 +77,7 @@ describe('input tests', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should respect default timeout when there is no custom timeout', async() => { it('should respect default timeout when there is no custom timeout', async() => {
@ -85,7 +85,7 @@ describe('input tests', function() {
page.setDefaultTimeout(1); page.setDefaultTimeout(1);
let error = null; let error = null;
await page.waitForFileChooser().catch(e => error = e); await page.waitForFileChooser().catch(error_ => error = error_);
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should prioritize exact timeout over default timeout', async() => { it('should prioritize exact timeout over default timeout', async() => {
@ -93,7 +93,7 @@ describe('input tests', function() {
page.setDefaultTimeout(0); page.setDefaultTimeout(0);
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should work with no timeout', async() => { it('should work with no timeout', async() => {
@ -181,7 +181,7 @@ describe('input tests', function() {
await chooser.accept([ await chooser.accept([
path.relative(process.cwd(), __dirname + '/assets/file-to-upload.txt'), path.relative(process.cwd(), __dirname + '/assets/file-to-upload.txt'),
path.relative(process.cwd(), __dirname + '/assets/pptr.png'), path.relative(process.cwd(), __dirname + '/assets/pptr.png'),
]).catch(e => error = e); ]).catch(error_ => error = error_);
expect(error).not.toBe(null); expect(error).not.toBe(null);
}); });
it('should fail for non-existent files', async() => { it('should fail for non-existent files', async() => {
@ -193,7 +193,7 @@ describe('input tests', function() {
page.click('input'), page.click('input'),
]); ]);
let error = null; 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); expect(error).not.toBe(null);
}); });
it('should fail when accepting file chooser twice', async() => { it('should fail when accepting file chooser twice', async() => {
@ -206,7 +206,7 @@ describe('input tests', function() {
]); ]);
await fileChooser.accept([]); await fileChooser.accept([]);
let error = null; 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!'); expect(error.message).toBe('Cannot accept FileChooser which is already handled!');
}); });
}); });
@ -240,7 +240,7 @@ describe('input tests', function() {
]); ]);
await fileChooser.cancel(); await fileChooser.cancel();
let error = null; 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!'); expect(error.message).toBe('Cannot cancel FileChooser which is already handled!');
}); });
}); });

View File

@ -50,7 +50,7 @@ describe('JSHandle', function() {
await page.evaluateHandle( await page.evaluateHandle(
opts => opts.elem.querySelector('p'), opts => opts.elem.querySelector('p'),
{elem: aHandle} {elem: aHandle}
).catch(e => error = e); ).catch(error_ => error = error_);
expect(error.message).toContain('Are you passing a nested JSHandle?'); expect(error.message).toContain('Are you passing a nested JSHandle?');
}); });
it('should accept object handle to unserializable value', async() => { it('should accept object handle to unserializable value', async() => {
@ -113,7 +113,7 @@ describe('JSHandle', function() {
const windowHandle = await page.evaluateHandle('window'); const windowHandle = await page.evaluateHandle('window');
let error = null; let error = null;
await windowHandle.jsonValue().catch(e => error = e); await windowHandle.jsonValue().catch(error_ => error = error_);
if (isChrome) if (isChrome)
expect(error.message).toContain('Object reference chain is too long'); expect(error.message).toContain('Object reference chain is too long');
else else

View File

@ -233,13 +233,13 @@ describe('Keyboard', function() {
it('should throw on unknown keys', async() => { it('should throw on unknown keys', async() => {
const {page} = getTestState(); 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"'); 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: "ё"'); 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: "😊"'); expect(error && error.message).toBe('Unknown key: "😊"');
}); });
itFailsFirefox('should type emoji', async() => { itFailsFirefox('should type emoji', async() => {

View File

@ -102,7 +102,7 @@ describe('Launcher specs', function() {
const browser = await puppeteer.launch(defaultBrowserOptions); const browser = await puppeteer.launch(defaultBrowserOptions);
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()}); const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
const page = await remote.newPage(); 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'); await server.waitForRequest('/one-style.css');
remote.disconnect(); remote.disconnect();
const error = await navigationPromise; const error = await navigationPromise;
@ -116,7 +116,7 @@ describe('Launcher specs', function() {
const browser = await puppeteer.launch(defaultBrowserOptions); const browser = await puppeteer.launch(defaultBrowserOptions);
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()}); const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
const page = await remote.newPage(); 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(); remote.disconnect();
const error = await watchdog; const error = await watchdog;
expect(error.message).toContain('Protocol error'); expect(error.message).toContain('Protocol error');
@ -131,8 +131,8 @@ describe('Launcher specs', function() {
const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()}); const remote = await puppeteer.connect({browserWSEndpoint: browser.wsEndpoint()});
const newPage = await remote.newPage(); const newPage = await remote.newPage();
const results = await Promise.all([ const results = await Promise.all([
newPage.waitForRequest(server.EMPTY_PAGE).catch(e => e), newPage.waitForRequest(server.EMPTY_PAGE).catch(error => error),
newPage.waitForResponse(server.EMPTY_PAGE).catch(e => e), newPage.waitForResponse(server.EMPTY_PAGE).catch(error => error),
browser.close() browser.close()
]); ]);
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
@ -149,7 +149,7 @@ describe('Launcher specs', function() {
const browser = await puppeteer.launch(defaultBrowserOptions); const browser = await puppeteer.launch(defaultBrowserOptions);
const page = await browser.newPage(); const page = await browser.newPage();
let error = null; 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 browser.close();
await neverResolves; await neverResolves;
expect(error.message).toContain('Protocol error'); expect(error.message).toContain('Protocol error');
@ -159,7 +159,7 @@ describe('Launcher specs', function() {
let waitError = null; let waitError = null;
const options = Object.assign({}, defaultBrowserOptions, {executablePath: 'random-invalid-path'}); 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'); expect(waitError.message).toContain('Failed to launch');
}); });
it('userDataDir option', async() => { it('userDataDir option', async() => {
@ -174,7 +174,7 @@ describe('Launcher specs', function() {
await browser.close(); await browser.close();
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 // 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() => { it('userDataDir argument', async() => {
const {isChrome, puppeteer, defaultBrowserOptions} = getTestState(); const {isChrome, puppeteer, defaultBrowserOptions} = getTestState();
@ -198,7 +198,7 @@ describe('Launcher specs', function() {
await browser.close(); await browser.close();
expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0); expect(fs.readdirSync(userDataDir).length).toBeGreaterThan(0);
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 // 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() => { it('userDataDir option should restore state', async() => {
const {server, puppeteer, defaultBrowserOptions} = getTestState(); const {server, puppeteer, defaultBrowserOptions} = getTestState();
@ -217,7 +217,7 @@ describe('Launcher specs', function() {
expect(await page2.evaluate(() => localStorage.hey)).toBe('hello'); expect(await page2.evaluate(() => localStorage.hey)).toBe('hello');
await browser2.close(); await browser2.close();
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 // 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 // This mysteriously fails on Windows on AppVeyor. See https://github.com/puppeteer/puppeteer/issues/4111
xit('userDataDir option should restore cookies', async() => { xit('userDataDir option should restore cookies', async() => {
@ -237,7 +237,7 @@ describe('Launcher specs', function() {
expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true'); expect(await page2.evaluate(() => document.cookie)).toBe('doSomethingOnlyOnce=true');
await browser2.close(); await browser2.close();
// This might throw. See https://github.com/puppeteer/puppeteer/issues/2778 // 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() => { it('should return the default arguments', async() => {
const {isChrome, isFirefox, puppeteer} = getTestState(); const {isChrome, isFirefox, puppeteer} = getTestState();
@ -429,7 +429,7 @@ describe('Launcher specs', function() {
let error = null; let error = null;
const [serverRequest, response] = await Promise.all([ const [serverRequest, response] = await Promise.all([
httpsServer.waitForRequest('/empty.html'), 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(error).toBe(null);
expect(response.ok()).toBe(true); expect(response.ok()).toBe(true);

View File

@ -75,7 +75,7 @@ describe('navigation', function() {
res.end(); res.end();
}); });
let error = null; 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).not.toBe(null);
if (isChrome) if (isChrome)
expect(error.message).toContain('net::ERR_ABORTED'); expect(error.message).toContain('net::ERR_ABORTED');
@ -114,7 +114,7 @@ describe('navigation', function() {
const {page, isChrome} = getTestState(); const {page, isChrome} = getTestState();
let error = null; let error = null;
await page.goto('asdfasdf').catch(e => error = e); await page.goto('asdfasdf').catch(error_ => error = error_);
if (isChrome) if (isChrome)
expect(error.message).toContain('Cannot navigate to invalid URL'); expect(error.message).toContain('Cannot navigate to invalid URL');
else else
@ -129,7 +129,7 @@ describe('navigation', function() {
page.on('requestfinished', request => expect(request).toBeTruthy()); page.on('requestfinished', request => expect(request).toBeTruthy());
page.on('requestfailed', request => expect(request).toBeTruthy()); page.on('requestfailed', request => expect(request).toBeTruthy());
let error = null; 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) if (isChrome)
expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID'); expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID');
else else
@ -141,7 +141,7 @@ describe('navigation', function() {
server.setRedirect('/redirect/1.html', '/redirect/2.html'); server.setRedirect('/redirect/1.html', '/redirect/2.html');
server.setRedirect('/redirect/2.html', '/empty.html'); server.setRedirect('/redirect/2.html', '/empty.html');
let error = null; 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) if (isChrome)
expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID'); expect(error.message).toContain('net::ERR_CERT_AUTHORITY_INVALID');
else else
@ -151,14 +151,14 @@ describe('navigation', function() {
const {page, server} = getTestState(); const {page, server} = getTestState();
let error = null; 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'); expect(error.message).toContain('"networkidle" option is no longer supported');
}); });
itFailsFirefox('should fail when main resources failed to load', async() => { itFailsFirefox('should fail when main resources failed to load', async() => {
const {page, isChrome} = getTestState(); const {page, isChrome} = getTestState();
let error = null; 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) if (isChrome)
expect(error.message).toContain('net::ERR_CONNECTION_REFUSED'); expect(error.message).toContain('net::ERR_CONNECTION_REFUSED');
else else
@ -170,7 +170,7 @@ describe('navigation', function() {
// Hang for request to the empty.html // Hang for request to the empty.html
server.setRoute('/empty.html', (req, res) => { }); server.setRoute('/empty.html', (req, res) => { });
let error = null; 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.message).toContain('Navigation timeout of 1 ms exceeded');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
@ -181,7 +181,7 @@ describe('navigation', function() {
server.setRoute('/empty.html', (req, res) => { }); server.setRoute('/empty.html', (req, res) => { });
let error = null; let error = null;
page.setDefaultNavigationTimeout(1); 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.message).toContain('Navigation timeout of 1 ms exceeded');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
@ -192,7 +192,7 @@ describe('navigation', function() {
server.setRoute('/empty.html', (req, res) => { }); server.setRoute('/empty.html', (req, res) => { });
let error = null; let error = null;
page.setDefaultTimeout(1); 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.message).toContain('Navigation timeout of 1 ms exceeded');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
@ -204,7 +204,7 @@ describe('navigation', function() {
let error = null; let error = null;
page.setDefaultTimeout(0); page.setDefaultTimeout(0);
page.setDefaultNavigationTimeout(1); 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.message).toContain('Navigation timeout of 1 ms exceeded');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
@ -214,7 +214,7 @@ describe('navigation', function() {
let error = null; let error = null;
let loaded = false; let loaded = false;
page.once('load', () => loaded = true); 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(error).toBe(null);
expect(loaded).toBe(true); expect(loaded).toBe(true);
}); });
@ -324,7 +324,7 @@ describe('navigation', function() {
const warningHandler = w => warning = w; const warningHandler = w => warning = w;
process.on('warning', warningHandler); process.on('warning', warningHandler);
for (let i = 0; i < 20; ++i) 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); process.removeListener('warning', warningHandler);
expect(warning).toBe(null); expect(warning).toBe(null);
}); });
@ -378,8 +378,8 @@ describe('navigation', function() {
let error = null; let error = null;
try { try {
await page.goto(url); await page.goto(url);
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain(url); expect(error.message).toContain(url);
}); });
@ -581,7 +581,7 @@ describe('navigation', function() {
await page.goto(server.PREFIX + '/frames/one-frame.html'); await page.goto(server.PREFIX + '/frames/one-frame.html');
server.setRoute('/empty.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 server.waitForRequest('/empty.html');
await page.$eval('iframe', frame => frame.remove()); await page.$eval('iframe', frame => frame.remove());
@ -642,7 +642,7 @@ describe('navigation', function() {
server.setRoute('/empty.html', () => {}); server.setRoute('/empty.html', () => {});
let error = null; let error = null;
const navigationPromise = frame.waitForNavigation().catch(e => error = e); const navigationPromise = frame.waitForNavigation().catch(error_ => error = error_);
await Promise.all([ await Promise.all([
server.waitForRequest('/empty.html'), server.waitForRequest('/empty.html'),
frame.evaluate(() => window.location = '/empty.html') frame.evaluate(() => window.location = '/empty.html')

View File

@ -211,7 +211,7 @@ describe('network', function() {
const redirected = redirectChain[0].response(); const redirected = redirectChain[0].response();
expect(redirected.status()).toBe(302); expect(redirected.status()).toBe(302);
let error = null; 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'); expect(error.message).toContain('Response body is unavailable for redirect responses');
}); });
it('should wait until response completes', async() => { it('should wait until response completes', async() => {
@ -458,8 +458,8 @@ describe('network', function() {
let error = null; let error = null;
try { try {
await page.setExtraHTTPHeaders({'foo': 1}); await page.setExtraHTTPHeaders({'foo': 1});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.'); expect(error.message).toBe('Expected value of header "foo" to be String, but "number" is found.');
}); });

View File

@ -30,7 +30,7 @@ describe('Page', function() {
const newPage = await context.newPage(); const newPage = await context.newPage();
let error = null; let error = null;
await Promise.all([ await Promise.all([
newPage.evaluate(() => new Promise(r => {})).catch(e => error = e), newPage.evaluate(() => new Promise(r => {})).catch(error_ => error = error_),
newPage.close(), newPage.close(),
]); ]);
expect(error.message).toContain('Protocol error'); expect(error.message).toContain('Protocol error');
@ -85,8 +85,8 @@ describe('Page', function() {
const newPage = await context.newPage(); const newPage = await context.newPage();
const results = await Promise.all([ const results = await Promise.all([
newPage.waitForRequest(server.EMPTY_PAGE).catch(e => e), newPage.waitForRequest(server.EMPTY_PAGE).catch(error => error),
newPage.waitForResponse(server.EMPTY_PAGE).catch(e => e), newPage.waitForResponse(server.EMPTY_PAGE).catch(error => error),
newPage.close() newPage.close()
]); ]);
for (let i = 0; i < 2; i++) { for (let i = 0; i < 2; i++) {
@ -117,7 +117,7 @@ describe('Page', function() {
res.end(); res.end();
}); });
let error = null; 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).not.toBe(null);
expect(error.stack).toContain(__filename); expect(error.stack).toContain(__filename);
}); });
@ -129,7 +129,7 @@ describe('Page', function() {
let error = null; let error = null;
page.on('error', err => error = err); page.on('error', err => error = err);
page.goto('chrome://crash').catch(e => {}); page.goto('chrome://crash').catch(error_ => {});
await waitEvent(page, 'error'); await waitEvent(page, 'error');
expect(error.message).toBe('Page crashed!'); expect(error.message).toBe('Page crashed!');
}); });
@ -217,7 +217,7 @@ describe('Page', function() {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
let error = null; 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'); expect(error.message).toBe('Unknown permission: foo');
}); });
itFailsFirefox('should grant permission when listed', async() => { itFailsFirefox('should grant permission when listed', async() => {
@ -301,8 +301,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.setGeolocation({longitude: 200, latitude: 10}); await page.setGeolocation({longitude: 200, latitude: 10});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain('Invalid longitude "200"'); expect(error.message).toContain('Invalid longitude "200"');
}); });
@ -314,7 +314,7 @@ describe('Page', function() {
await page.setOfflineMode(true); await page.setOfflineMode(true);
let error = null; 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(); expect(error).toBeTruthy();
await page.setOfflineMode(false); await page.setOfflineMode(false);
const response = await page.reload(); const response = await page.reload();
@ -361,7 +361,7 @@ describe('Page', function() {
const prototypeHandle = await page.evaluateHandle(() => HTMLBodyElement.prototype); const prototypeHandle = await page.evaluateHandle(() => HTMLBodyElement.prototype);
await prototypeHandle.dispose(); await prototypeHandle.dispose();
let error = null; 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!'); expect(error.message).toBe('Prototype JSHandle is disposed!');
}); });
it('should fail primitive values as prototypes', async() => { it('should fail primitive values as prototypes', async() => {
@ -369,7 +369,7 @@ describe('Page', function() {
const prototypeHandle = await page.evaluateHandle(() => 42); const prototypeHandle = await page.evaluateHandle(() => 42);
let error = null; 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'); expect(error.message).toBe('Prototype JSHandle must not be referencing primitive value');
}); });
}); });
@ -435,7 +435,7 @@ describe('Page', function() {
await page.goto('about:blank'); await page.goto('about:blank');
const [message] = await Promise.all([ const [message] = await Promise.all([
waitEvent(page, 'console'), 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'); expect(message.text()).toContain('Access-Control-Allow-Origin');
if (isChrome) if (isChrome)
@ -582,7 +582,7 @@ describe('Page', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should respect default timeout', async() => { it('should respect default timeout', async() => {
@ -590,7 +590,7 @@ describe('Page', function() {
let error = null; let error = null;
page.setDefaultTimeout(1); 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should work with no timeout', async() => { it('should work with no timeout', async() => {
@ -628,7 +628,7 @@ describe('Page', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should respect default timeout', async() => { it('should respect default timeout', async() => {
@ -636,7 +636,7 @@ describe('Page', function() {
let error = null; let error = null;
page.setDefaultTimeout(1); 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
itFailsFirefox('should work with predicate', async() => { itFailsFirefox('should work with predicate', async() => {
@ -690,8 +690,8 @@ describe('Page', function() {
const {message, stack} = await page.evaluate(async() => { const {message, stack} = await page.evaluate(async() => {
try { try {
await woof(); await woof();
} catch (e) { } catch (error) {
return {message: e.message, stack: e.stack}; return {message: error.message, stack: error.stack};
} }
}); });
expect(message).toBe('WOOF WOOF'); expect(message).toBe('WOOF WOOF');
@ -706,8 +706,8 @@ describe('Page', function() {
const thrown = await page.evaluate(async() => { const thrown = await page.evaluate(async() => {
try { try {
await woof(); await woof();
} catch (e) { } catch (error) {
return e; return error;
} }
}); });
expect(thrown).toBe(null); expect(thrown).toBe(null);
@ -867,7 +867,7 @@ describe('Page', function() {
// stall for image // stall for image
server.setRoute(imgPath, (req, res) => {}); server.setRoute(imgPath, (req, res) => {});
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should respect default navigation timeout', async() => { it('should respect default navigation timeout', async() => {
@ -878,7 +878,7 @@ describe('Page', function() {
// stall for image // stall for image
server.setRoute(imgPath, (req, res) => {}); server.setRoute(imgPath, (req, res) => {});
let error = null; 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); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
it('should await resources to load', async() => { it('should await resources to load', async() => {
@ -932,7 +932,7 @@ describe('Page', function() {
// Make sure CSP prohibits addScriptTag. // Make sure CSP prohibits addScriptTag.
await page.goto(server.PREFIX + '/csp.html'); 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); expect(await page.evaluate(() => window.__injected)).toBe(undefined);
// By-pass CSP and try one more time. // By-pass CSP and try one more time.
@ -948,7 +948,7 @@ describe('Page', function() {
// Make sure CSP prohibits addScriptTag. // Make sure CSP prohibits addScriptTag.
server.setCSP('/empty.html', 'default-src "self"'); server.setCSP('/empty.html', 'default-src "self"');
await page.goto(server.EMPTY_PAGE); 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); expect(await page.evaluate(() => window.__injected)).toBe(undefined);
// By-pass CSP and try one more time. // By-pass CSP and try one more time.
@ -977,7 +977,7 @@ describe('Page', function() {
{ {
// Make sure CSP prohibits addScriptTag in an iframe. // Make sure CSP prohibits addScriptTag in an iframe.
const frame = await utils.attachFrame(page, 'frame1', server.PREFIX + '/csp.html'); 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); 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'); 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); expect(await frame.evaluate(() => window.__injected)).toBe(42);
} }
}); });
@ -1000,8 +1000,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.addScriptTag('/injectedfile.js'); await page.addScriptTag('/injectedfile.js');
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property'); expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property');
}); });
@ -1048,8 +1048,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.addScriptTag({url: '/nonexistfile.js'}); await page.addScriptTag({url: '/nonexistfile.js'});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toBe('Loading script from /nonexistfile.js failed'); expect(error.message).toBe('Loading script from /nonexistfile.js failed');
}); });
@ -1087,7 +1087,7 @@ describe('Page', function() {
await page.goto(server.PREFIX + '/csp.html'); await page.goto(server.PREFIX + '/csp.html');
let error = null; 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(); expect(error).toBeTruthy();
}); });
@ -1096,7 +1096,7 @@ describe('Page', function() {
await page.goto(server.PREFIX + '/csp.html'); await page.goto(server.PREFIX + '/csp.html');
let error = null; 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(); expect(error).toBeTruthy();
}); });
}); });
@ -1108,8 +1108,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.addStyleTag('/injectedstyle.css'); await page.addStyleTag('/injectedstyle.css');
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property'); expect(error.message).toBe('Provide an object with a `url`, `path` or `content` property');
}); });
@ -1130,8 +1130,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.addStyleTag({url: '/nonexistfile.js'}); await page.addStyleTag({url: '/nonexistfile.js'});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toBe('Loading style from /nonexistfile.js failed'); expect(error.message).toBe('Loading style from /nonexistfile.js failed');
}); });
@ -1169,7 +1169,7 @@ describe('Page', function() {
await page.goto(server.PREFIX + '/csp.html'); await page.goto(server.PREFIX + '/csp.html');
let error = null; 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(); expect(error).toBeTruthy();
}); });
@ -1178,7 +1178,7 @@ describe('Page', function() {
await page.goto(server.PREFIX + '/csp.html'); await page.goto(server.PREFIX + '/csp.html');
let error = null; 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(); expect(error).toBeTruthy();
}); });
}); });
@ -1200,7 +1200,7 @@ describe('Page', function() {
await page.setJavaScriptEnabled(false); await page.setJavaScriptEnabled(false);
await page.goto('data:text/html, <script>var something = "forbidden"</script>'); await page.goto('data:text/html, <script>var something = "forbidden"</script>');
let error = null; 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'); expect(error.message).toContain('something is not defined');
await page.setJavaScriptEnabled(true); await page.setJavaScriptEnabled(true);
@ -1317,7 +1317,7 @@ describe('Page', function() {
let error = null; let error = null;
await page.goto(server.PREFIX + '/input/select.html'); 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.'); expect(error.message).toContain('Element is not a <select> element.');
}); });
it('should return [] on no matched values', async() => { it('should return [] on no matched values', async() => {
@ -1373,8 +1373,8 @@ describe('Page', function() {
let error = null; let error = null;
try { try {
await page.select('select', 12); await page.select('select', 12);
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error.message).toContain('Values must be strings'); expect(error.message).toContain('Values must be strings');
}); });

View File

@ -46,7 +46,7 @@ describe('querySelector', function() {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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"'); expect(error.message).toContain('failed to find element matching selector "section"');
}); });
}); });

View File

@ -202,7 +202,7 @@ describe('request interception', function() {
}); });
let failedRequest = null; let failedRequest = null;
page.on('requestfailed', request => failedRequest = request); 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).toBeTruthy();
expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED'); expect(failedRequest.failure().errorText).toBe('net::ERR_INTERNET_DISCONNECTED');
}); });
@ -226,7 +226,7 @@ describe('request interception', function() {
await page.setRequestInterception(true); await page.setRequestInterception(true);
page.on('request', request => request.abort()); page.on('request', request => request.abort());
let error = null; 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(); expect(error).toBeTruthy();
if (isChrome) if (isChrome)
expect(error.message).toContain('net::ERR_FAILED'); expect(error.message).toContain('net::ERR_FAILED');
@ -305,8 +305,8 @@ describe('request interception', function() {
const result = await page.evaluate(async() => { const result = await page.evaluate(async() => {
try { try {
await fetch('/non-existing.json'); await fetch('/non-existing.json');
} catch (e) { } catch (error) {
return e.message; return error.message;
} }
}); });
if (isChrome) if (isChrome)
@ -333,9 +333,9 @@ describe('request interception', function() {
spinner = !spinner; spinner = !spinner;
}); });
const results = await page.evaluate(() => Promise.all([ const results = await page.evaluate(() => Promise.all([
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(e => 'FAILED'), fetch('/zzz').then(response => response.text()).catch(error => 'FAILED'),
fetch('/zzz').then(response => response.text()).catch(e => 'FAILED'), fetch('/zzz').then(response => response.text()).catch(error => 'FAILED'),
])); ]));
expect(results).toEqual(['11', 'FAILED', '22']); expect(results).toEqual(['11', 'FAILED', '22']);
}); });
@ -433,7 +433,7 @@ describe('request interception', function() {
// Delete frame to cause request to be canceled. // Delete frame to cause request to be canceled.
await page.$eval('iframe', frame => frame.remove()); await page.$eval('iframe', frame => frame.remove());
let error = null; let error = null;
await request.continue().catch(e => error = e); await request.continue().catch(error_ => error = error_);
expect(error).toBe(null); expect(error).toBe(null);
}); });
it('should throw if interception is not enabled', async() => { it('should throw if interception is not enabled', async() => {
@ -443,8 +443,8 @@ describe('request interception', function() {
page.on('request', async request => { page.on('request', async request => {
try { try {
await request.continue(); await request.continue();
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
}); });
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);

View File

@ -257,7 +257,7 @@ describe('Screenshots', function() {
await page.setContent('<div style="width: 50px; height: 0"></div>'); await page.setContent('<div style="width: 50px; height: 0"></div>');
const div = await page.$('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.'); expect(error.message).toBe('Node has 0 height.');
}); });
itFailsFirefox('should work for an element with fractional dimensions', async() => { itFailsFirefox('should work for an element with fractional dimensions', async() => {

View File

@ -202,7 +202,7 @@ describe('Target', function() {
let error = null; let error = null;
await browser.waitForTarget(target => target.url() === server.EMPTY_PAGE, { await browser.waitForTarget(target => target.url() === server.EMPTY_PAGE, {
timeout: 1 timeout: 1
}).catch(e => error = e); }).catch(error_ => error = error_);
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
}); });
}); });

View File

@ -64,7 +64,7 @@ describeChromeOnly('Tracing', function() {
await page.tracing.start({path: outputFile}); await page.tracing.start({path: outputFile});
const newPage = await browser.newPage(); const newPage = await browser.newPage();
let error = null; 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(); await newPage.close();
expect(error).toBeTruthy(); expect(error).toBeTruthy();
await page.tracing.stop(); await page.tracing.stop();

View File

@ -51,7 +51,7 @@ describe('waittask specs', function() {
await page.setContent(`<div>some text</div>`); await page.setContent(`<div>some text</div>`);
let error = null; 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(); expect(error).toBeTruthy();
}); });
it('should timeout', async() => { it('should timeout', async() => {
@ -82,7 +82,7 @@ describe('waittask specs', function() {
const {page} = getTestState(); const {page} = getTestState();
let error = null; 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'); expect(error.message).toContain('Unsupported target type');
}); });
it('should wait for predicate with arguments', async() => { it('should wait for predicate with arguments', async() => {
@ -149,7 +149,7 @@ describe('waittask specs', function() {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
let error = null; let error = null;
await Promise.all([ 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') page.evaluate(() => window.__FOO = 'hit')
]); ]);
expect(error).toBe(null); expect(error).toBe(null);
@ -160,8 +160,8 @@ describe('waittask specs', function() {
let error = null; let error = null;
try { try {
await page.waitForFunction(() => !!document.body, {polling: 'unknown'}); await page.waitForFunction(() => !!document.body, {polling: 'unknown'});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error).toBeTruthy(); expect(error).toBeTruthy();
expect(error.message).toContain('polling'); expect(error.message).toContain('polling');
@ -172,8 +172,8 @@ describe('waittask specs', function() {
let error = null; let error = null;
try { try {
await page.waitForFunction(() => !!document.body, {polling: -10}); await page.waitForFunction(() => !!document.body, {polling: -10});
} catch (e) { } catch (error_) {
error = e; error = error_;
} }
expect(error).toBeTruthy(); expect(error).toBeTruthy();
expect(error.message).toContain('Cannot poll with non-positive interval'); expect(error.message).toContain('Cannot poll with non-positive interval');
@ -203,7 +203,7 @@ describe('waittask specs', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('waiting for function failed: timeout'); expect(error.message).toContain('waiting for function failed: timeout');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
@ -213,7 +213,7 @@ describe('waittask specs', function() {
page.setDefaultTimeout(1); page.setDefaultTimeout(1);
let error = null; 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).toBeInstanceOf(puppeteer.errors.TimeoutError);
expect(error.message).toContain('waiting for function failed: timeout'); 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); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
const frame = page.frames()[1]; const frame = page.frames()[1];
let waitError = null; 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 utils.detachFrame(page, 'frame1');
await waitPromise; await waitPromise;
expect(waitError).toBeTruthy(); expect(waitError).toBeTruthy();
@ -425,7 +425,7 @@ describe('waittask specs', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('waiting for selector "div" failed: timeout'); expect(error.message).toContain('waiting for selector "div" failed: timeout');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
@ -435,7 +435,7 @@ describe('waittask specs', function() {
await page.setContent(`<div></div>`); await page.setContent(`<div></div>`);
let error = null; 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).toBeTruthy();
expect(error.message).toContain('waiting for selector "div" to be hidden failed: timeout'); expect(error.message).toContain('waiting for selector "div" to be hidden failed: timeout');
}); });
@ -461,7 +461,7 @@ describe('waittask specs', function() {
const {page} = getTestState(); const {page} = getTestState();
let error; 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'); expect(error.stack).toContain('waittask.spec.js');
}); });
}); });
@ -480,7 +480,7 @@ describe('waittask specs', function() {
const {page, puppeteer} = getTestState(); const {page, puppeteer} = getTestState();
let error = null; 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).toBeTruthy();
expect(error.message).toContain('waiting for XPath "//div" failed: timeout'); expect(error.message).toContain('waiting for XPath "//div" failed: timeout');
expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError); expect(error).toBeInstanceOf(puppeteer.errors.TimeoutError);
@ -504,7 +504,7 @@ describe('waittask specs', function() {
await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE); await utils.attachFrame(page, 'frame1', server.EMPTY_PAGE);
const frame = page.frames()[1]; const frame = page.frames()[1];
let waitError = null; 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 utils.detachFrame(page, 'frame1');
await waitPromise; await waitPromise;
expect(waitError).toBeTruthy(); expect(waitError).toBeTruthy();

View File

@ -37,8 +37,8 @@ const fileExists = async filePath => fsAccess(filePath).then(() => true).catch((
* place. * place.
*/ */
async function compileTypeScript() { async function compileTypeScript() {
return exec('npm run tsc').catch(err => { return exec('npm run tsc').catch(error => {
console.error('Error running TypeScript', err); console.error('Error running TypeScript', error);
process.exit(1); process.exit(1);
}); });
} }

View File

@ -80,8 +80,8 @@ async function main(url) {
let json = null; let json = null;
try { try {
json = JSON.parse(text); json = JSON.parse(text);
} catch (e) { } catch (error) {
console.error(`FAILED: error parsing response - ${e.message}`); console.error(`FAILED: error parsing response - ${error.message}`);
return; return;
} }
const devicePayloads = json.extensions.filter(extension => extension.type === 'emulated-device').map(extension => extension.device); const devicePayloads = json.extensions.filter(extension => extension.type === 'emulated-device').map(extension => extension.device);