From 1ccfbcb684af30f0fa2fe45acef5f35c49074c20 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Tue, 28 Apr 2020 14:16:28 +0100 Subject: [PATCH] chore: enforce naming of errors in catch blocks (#5763) --- .eslintrc.js | 8 ++- package.json | 1 + src/BrowserFetcher.ts | 2 +- src/Coverage.ts | 8 +-- src/DOMWorld.js | 6 +-- src/ExecutionContext.ts | 12 ++--- src/Launcher.js | 8 +-- src/Page.js | 10 ++-- src/helper.ts | 12 ++--- test/CDPSession.spec.js | 4 +- test/browsercontext.spec.js | 4 +- test/chromiumonly.spec.js | 4 +- test/click.spec.js | 4 +- test/cookies.spec.js | 12 ++--- test/elementhandle.spec.js | 10 ++-- test/emulation.spec.js | 10 ++-- test/evaluation.spec.js | 22 ++++----- test/frame.spec.js | 2 +- test/headful.spec.js | 2 +- test/ignorehttpserrors.spec.js | 2 +- test/input.spec.js | 14 +++--- test/jshandle.spec.js | 4 +- test/keyboard.spec.js | 6 +-- test/launcher.spec.js | 22 ++++----- test/navigation.spec.js | 32 ++++++------ test/network.spec.js | 6 +-- test/page.spec.js | 84 ++++++++++++++++---------------- test/queryselector.spec.js | 2 +- test/requestinterception.spec.js | 20 ++++---- test/screenshot.spec.js | 2 +- test/target.spec.js | 2 +- test/tracing.spec.js | 2 +- test/waittask.spec.js | 30 ++++++------ typescript-if-required.js | 4 +- utils/fetch_devices.js | 4 +- 35 files changed, 191 insertions(+), 186 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 23f02e38..527cb9ff 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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": [ { diff --git a/package.json b/package.json index 2b13a5e3..71e28c58 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/BrowserFetcher.ts b/src/BrowserFetcher.ts index f2fb815b..b2b2b9ca 100644 --- a/src/BrowserFetcher.ts +++ b/src/BrowserFetcher.ts @@ -429,7 +429,7 @@ function installDMG(dmgPath: string, folderPath: string): Promise { }); } - return new Promise(mountAndCopy).catch(err => { console.error(err); }).finally(unmount); + return new Promise(mountAndCopy).catch(error => { console.error(error); }).finally(unmount); } function httpRequest(url: string, method: string, response: (x: http.IncomingMessage) => void): http.ClientRequest { diff --git a/src/Coverage.ts b/src/Coverage.ts index 4e46464f..cee70a8a 100644 --- a/src/Coverage.ts +++ b/src/Coverage.ts @@ -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); } } diff --git a/src/DOMWorld.js b/src/DOMWorld.js index 40580546..a7835312 100644 --- a/src/DOMWorld.js +++ b/src/DOMWorld.js @@ -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; } diff --git a/src/ExecutionContext.ts b/src/ExecutionContext.ts index d7e09676..021f6504 100644 --- a/src/ExecutionContext.ts +++ b/src/ExecutionContext.ts @@ -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) diff --git a/src/Launcher.js b/src/Launcher.js index 88f7d0d9..330e0aea 100644 --- a/src/Launcher.js +++ b/src/Launcher.js @@ -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; }); } diff --git a/src/Page.js b/src/Page.js index 71bde110..6b91be9e 100644 --- a/src/Page.js +++ b/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; } } diff --git a/src/helper.ts b/src/helper.ts index a874bf50..52beda63 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -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(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; diff --git a/test/CDPSession.spec.js b/test/CDPSession.spec.js index ad3b2cfb..e2682c2f 100644 --- a/test/CDPSession.spec.js +++ b/test/CDPSession.spec.js @@ -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.'); }); diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.js index fbaa8d09..c394a084 100644 --- a/test/browsercontext.spec.js +++ b/test/browsercontext.spec.js @@ -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(); }); diff --git a/test/chromiumonly.spec.js b/test/chromiumonly.spec.js index 0d8d60a9..b14d25d4 100644 --- a/test/chromiumonly.spec.js +++ b/test/chromiumonly.spec.js @@ -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(); }); diff --git a/test/click.spec.js b/test/click.spec.js index 786819e3..f2ac1e9a 100644 --- a/test/click.spec.js +++ b/test/click.spec.js @@ -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 diff --git a/test/cookies.spec.js b/test/cookies.spec.js index ac92b3f9..16a67328 100644 --- a/test/cookies.spec.js +++ b/test/cookies.spec.js @@ -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'); }); diff --git a/test/elementhandle.spec.js b/test/elementhandle.spec.js index b17bc528..4ec76ca0 100644 --- a/test/elementhandle.spec.js +++ b/test/elementhandle.spec.js @@ -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
elements', async() => { @@ -219,7 +219,7 @@ describe('ElementHandle specs', function() { await page.setContent('hello
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'); }); }); diff --git a/test/emulation.spec.js b/test/emulation.spec.js index 61bef334..e25eee21 100644 --- a/test/emulation.spec.js +++ b/test/emulation.spec.js @@ -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'); }); }); diff --git a/test/evaluation.spec.js b/test/evaluation.spec.js index 094ab688..fedf248c 100644 --- a/test/evaluation.spec.js +++ b/test/evaluation.spec.js @@ -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); }); }); diff --git a/test/frame.spec.js b/test/frame.spec.js index 453e1759..00e857c0 100644 --- a/test/frame.spec.js +++ b/test/frame.spec.js @@ -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'); }); }); diff --git a/test/headful.spec.js b/test/headful.spec.js index 8361a173..cd1192dc 100644 --- a/test/headful.spec.js +++ b/test/headful.spec.js @@ -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 diff --git a/test/ignorehttpserrors.spec.js b/test/ignorehttpserrors.spec.js index a3d85be9..f549d246 100644 --- a/test/ignorehttpserrors.spec.js +++ b/test/ignorehttpserrors.spec.js @@ -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); }); diff --git a/test/input.spec.js b/test/input.spec.js index 6291cc97..a70a2002 100644 --- a/test/input.spec.js +++ b/test/input.spec.js @@ -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!'); }); }); diff --git a/test/jshandle.spec.js b/test/jshandle.spec.js index e96bdff6..c5860e24 100644 --- a/test/jshandle.spec.js +++ b/test/jshandle.spec.js @@ -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 diff --git a/test/keyboard.spec.js b/test/keyboard.spec.js index 13e0372f..67df6385 100644 --- a/test/keyboard.spec.js +++ b/test/keyboard.spec.js @@ -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() => { diff --git a/test/launcher.spec.js b/test/launcher.spec.js index 05303aa1..a9d05a8d 100644 --- a/test/launcher.spec.js +++ b/test/launcher.spec.js @@ -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); diff --git a/test/navigation.spec.js b/test/navigation.spec.js index 8ab5c55a..0e0c1a1e 100644 --- a/test/navigation.spec.js +++ b/test/navigation.spec.js @@ -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') diff --git a/test/network.spec.js b/test/network.spec.js index 6de2bcd8..b75d4925 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -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.'); }); diff --git a/test/page.spec.js b/test/page.spec.js index 4ce562f6..ca7b3d49 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -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(``, {timeout: 1}).catch(e => error = e); + await page.setContent(``, {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(``).catch(e => error = e); + await page.setContent(``).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, '); 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