From 3c2a8fa306e652eaf3fb9f1194369f9d5e7768ee Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 2 Jun 2023 21:59:12 +0200 Subject: [PATCH] chore: enable no-floating-promises ESLint rule for tests (#23376) https://github.com/microsoft/playwright/issues/23339 --- tests/.eslintrc.js | 15 ++++ tests/android/webview.spec.ts | 2 +- tests/config/debugControllerBackend.ts | 4 +- tests/config/testserver/index.ts | 8 ++- tests/electron/electron-app.spec.ts | 8 +-- tests/electron/electron-tracing.spec.ts | 4 +- tests/electron/electronTest.ts | 2 +- tests/image_tools/fixtures.spec.ts | 6 +- ...rowsercontext-fetch-happy-eyeballs.spec.ts | 6 +- .../library/browsercontext-page-event.spec.ts | 2 +- tests/library/browsercontext-route.spec.ts | 68 +++++++++---------- .../browsercontext-storage-state.spec.ts | 2 +- tests/library/browsertype-connect.spec.ts | 2 +- tests/library/capabilities.spec.ts | 4 +- tests/library/channels.spec.ts | 2 +- tests/library/chromium/chromium.spec.ts | 6 +- tests/library/chromium/oopif.spec.ts | 4 +- tests/library/download.spec.ts | 6 +- tests/library/har.spec.ts | 10 +-- tests/library/inspector/cli-codegen-2.spec.ts | 2 +- tests/library/page-event-crash.spec.ts | 2 +- tests/library/popup.spec.ts | 4 +- tests/library/trace-viewer.spec.ts | 16 ++--- tests/library/tracing.spec.ts | 6 +- tests/library/web-socket.spec.ts | 2 +- tests/page/interception.spec.ts | 6 +- tests/page/locator-frame.spec.ts | 6 +- tests/page/network-post-data.spec.ts | 2 +- tests/page/page-click.spec.ts | 2 +- tests/page/page-close.spec.ts | 2 +- tests/page/page-dialog.spec.ts | 14 ++-- tests/page/page-dispatchevent.spec.ts | 4 +- tests/page/page-drag.spec.ts | 2 +- tests/page/page-evaluate-no-stall.spec.ts | 2 +- tests/page/page-event-console.spec.ts | 4 +- tests/page/page-navigation.spec.ts | 4 +- tests/page/page-network-idle.spec.ts | 8 +-- tests/page/page-network-request.spec.ts | 6 +- tests/page/page-request-continue.spec.ts | 30 ++++---- tests/page/page-request-fallback.spec.ts | 52 +++++++------- tests/page/page-request-fulfill.spec.ts | 34 +++++----- tests/page/page-route.spec.ts | 54 +++++++-------- tests/page/page-select-option.spec.ts | 6 +- tests/page/page-wait-for-load-state.spec.ts | 2 +- tests/page/page-wait-for-request.spec.ts | 22 +++--- tests/page/page-wait-for-response.spec.ts | 22 +++--- tests/page/selectors-frame.spec.ts | 8 +-- tests/page/selectors-register.spec.ts | 20 +++--- .../ui-mode-test-output.spec.ts | 2 +- .../playwright-test/ui-mode-test-tree.spec.ts | 2 +- 50 files changed, 265 insertions(+), 244 deletions(-) create mode 100644 tests/.eslintrc.js diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js new file mode 100644 index 0000000000..719e15f986 --- /dev/null +++ b/tests/.eslintrc.js @@ -0,0 +1,15 @@ +const path = require('path'); + +module.exports = { + extends: '../.eslintrc.js', + parser: "@typescript-eslint/parser", + plugins: ["@typescript-eslint", "notice"], + parserOptions: { + ecmaVersion: 9, + sourceType: "module", + project: path.join(__dirname, 'tsconfig.json'), + }, + rules: { + '@typescript-eslint/no-floating-promises': 'error', + }, +}; diff --git a/tests/android/webview.spec.ts b/tests/android/webview.spec.ts index ccc5ebf75a..46e0e385a0 100644 --- a/tests/android/webview.spec.ts +++ b/tests/android/webview.spec.ts @@ -67,7 +67,7 @@ test('select webview from socketName', async function({ androidDevice }) { test.slow(); const context = await androidDevice.launchBrowser(); const newPage = await context.newPage(); - newPage.goto('about:blank'); + await newPage.goto('about:blank'); const webview = await androidDevice.webView({ socketName: 'webview_devtools_remote_playwright_test' }); expect(webview.pkg()).toBe(''); diff --git a/tests/config/debugControllerBackend.ts b/tests/config/debugControllerBackend.ts index f4a772da4c..2d80cb57df 100644 --- a/tests/config/debugControllerBackend.ts +++ b/tests/config/debugControllerBackend.ts @@ -168,11 +168,11 @@ export class Backend extends EventEmitter { } async resume() { - this._send('resume'); + await this._send('resume'); } async kill() { - this._send('kill'); + await this._send('kill'); } private _send(method: string, params: any = {}): Promise { diff --git a/tests/config/testserver/index.ts b/tests/config/testserver/index.ts index ded1c1c7d5..855f4ceec1 100644 --- a/tests/config/testserver/index.ts +++ b/tests/config/testserver/index.ts @@ -221,7 +221,13 @@ export class TestServer { this.serveFile(request, response); } - async serveFile(request: http.IncomingMessage, response: http.ServerResponse, filePath?: string) { + serveFile(request: http.IncomingMessage, response: http.ServerResponse, filePath?: string): void { + this._serveFile(request, response, filePath).catch(e => { + this.debugServer(`error: ${e}`); + }); + } + + private async _serveFile(request: http.IncomingMessage, response: http.ServerResponse, filePath?: string): Promise { let pathName = url.parse(request.url!).path; if (!filePath) { if (pathName === '/') diff --git a/tests/electron/electron-app.spec.ts b/tests/electron/electron-app.spec.ts index ee54cf2e2a..453283973c 100644 --- a/tests/electron/electron-app.spec.ts +++ b/tests/electron/electron-app.spec.ts @@ -66,8 +66,8 @@ test('should evaluate handle', async ({ electronApp }) => { }); test('should route network', async ({ electronApp, newWindow }) => { - await electronApp.context().route('**/empty.html', (route, request) => { - route.fulfill({ + await electronApp.context().route('**/empty.html', async (route, request) => { + await route.fulfill({ status: 200, contentType: 'text/html', body: 'Hello World', @@ -95,7 +95,7 @@ test('should expose function', async ({ electronApp, newWindow }) => { test('should wait for first window', async ({ electronApp }) => { await electronApp.evaluate(({ BrowserWindow }) => { const window = new BrowserWindow({ width: 800, height: 600 }); - window.loadURL('data:text/html,Hello World!'); + void window.loadURL('data:text/html,Hello World!'); }); const window = await electronApp.firstWindow(); expect(await window.title()).toBe('Hello World!'); @@ -126,7 +126,7 @@ test('should bypass csp', async ({ launchElectronApp, server }) => { width: 800, height: 600, }); - window.loadURL('about:blank'); + void window.loadURL('about:blank'); }); const page = await app.firstWindow(); await page.goto(server.PREFIX + '/csp.html'); diff --git a/tests/electron/electron-tracing.spec.ts b/tests/electron/electron-tracing.spec.ts index 760c400e6d..59dc2f840c 100644 --- a/tests/electron/electron-tracing.spec.ts +++ b/tests/electron/electron-tracing.spec.ts @@ -35,8 +35,8 @@ test('should record trace', async ({ newWindow, server, runAndTrace }) => { test('should support custom protocol', async ({ electronApp, newWindow, server, runAndTrace }) => { const window = await newWindow(); - await electronApp.evaluate(async ({ BrowserWindow }) => { - BrowserWindow.getAllWindows()[0].loadURL('vscode-file://index.html'); + await electronApp.evaluate(({ BrowserWindow }) => { + void BrowserWindow.getAllWindows()[0].loadURL('vscode-file://index.html'); }); const traceViewer = await runAndTrace(async () => { await window.click('button'); diff --git a/tests/electron/electronTest.ts b/tests/electron/electronTest.ts index 68261cfa16..f9d7a21da7 100644 --- a/tests/electron/electronTest.ts +++ b/tests/electron/electronTest.ts @@ -73,7 +73,7 @@ export const electronTest = baseTest.extend(traceViewerFixt // and can script them. We use that heavily in our tests. webPreferences: { sandbox: true } }); - window.loadURL('about:blank'); + await window.loadURL('about:blank'); }) ]); windows.push(window); diff --git a/tests/image_tools/fixtures.spec.ts b/tests/image_tools/fixtures.spec.ts index 11dbf1e296..d67a279715 100644 --- a/tests/image_tools/fixtures.spec.ts +++ b/tests/image_tools/fixtures.spec.ts @@ -39,11 +39,11 @@ function declareFixtureTest(fixtureRoot: string, fixtureName: string, shouldMatc fs.promises.readFile(fixtureName + '-actual.png'), fs.promises.readFile(fixtureName + '-expected.png'), ]); - testInfo.attach(fixtureName + '-actual.png', { + await testInfo.attach(fixtureName + '-actual.png', { body: actual, contentType: 'image/png', }); - testInfo.attach(fixtureName + '-expected.png', { + await testInfo.attach(fixtureName + '-expected.png', { body: expected, contentType: 'image/png', }); @@ -57,7 +57,7 @@ function declareFixtureTest(fixtureRoot: string, fixtureName: string, shouldMatc maxColorDeltaE94: 1.0, }); - testInfo.attach(fixtureName + '-diff.png', { + await testInfo.attach(fixtureName + '-diff.png', { body: PNG.sync.write(diffPNG), contentType: 'image/png', }); diff --git a/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts b/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts index c3f77b8cc2..c37859b146 100644 --- a/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts +++ b/tests/library/browsercontext-fetch-happy-eyeballs.spec.ts @@ -42,14 +42,14 @@ it.beforeEach(() => { it('get should work', async ({ context, server }) => { const response = await context.request.get(server.PREFIX + '/simple.json', { __testHookLookup } as any); expect(response.url()).toBe(server.PREFIX + '/simple.json'); - expect(response).toBeOK(); + await expect(response).toBeOK(); expect(interceptedHostnameLookup).toBe('localhost'); }); it('get should work on request fixture', async ({ request, server }) => { const response = await request.get(server.PREFIX + '/simple.json', { __testHookLookup } as any); expect(response.url()).toBe(server.PREFIX + '/simple.json'); - expect(response).toBeOK(); + await expect(response).toBeOK(); expect(interceptedHostnameLookup).toBe('localhost'); }); @@ -65,5 +65,5 @@ it('should work with ip6 and port as the host', async ({ request, server }) => { it.skip(!!process.env.INSIDE_DOCKER, 'docker does not support IPv6 by default'); const response = await request.get(`http://[::1]:${server.PORT}/simple.json`); expect(response.url()).toBe(`http://[::1]:${server.PORT}/simple.json`); - expect(response).toBeOK(); + await expect(response).toBeOK(); }); diff --git a/tests/library/browsercontext-page-event.spec.ts b/tests/library/browsercontext-page-event.spec.ts index 702cf80c7e..ed1beac27a 100644 --- a/tests/library/browsercontext-page-event.spec.ts +++ b/tests/library/browsercontext-page-event.spec.ts @@ -94,7 +94,7 @@ it('should report when a new page is created and closed', async ({ browser, serv it('should report initialized pages', async ({ browser, server }) => { const context = await browser.newContext(); const pagePromise = context.waitForEvent('page'); - context.newPage(); + void context.newPage(); const newPage = await pagePromise; expect(newPage.url()).toBe('about:blank'); diff --git a/tests/library/browsercontext-route.spec.ts b/tests/library/browsercontext-route.spec.ts index 176a40d411..a1d4a83a29 100644 --- a/tests/library/browsercontext-route.spec.ts +++ b/tests/library/browsercontext-route.spec.ts @@ -31,7 +31,7 @@ it('should intercept', async ({ browser, server }) => { expect(request.resourceType()).toBe('document'); expect(request.frame() === page.mainFrame()).toBe(true); expect(request.frame().url()).toBe('about:blank'); - route.continue(); + void route.continue(); }); const page = await context.newPage(); const response = await page.goto(server.EMPTY_PAGE); @@ -47,19 +47,19 @@ it('should unroute', async ({ browser, server }) => { let intercepted = []; await context.route('**/*', route => { intercepted.push(1); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(2); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(3); - route.fallback(); + void route.fallback(); }); const handler4 = route => { intercepted.push(4); - route.fallback(); + void route.fallback(); }; await context.route(/empty.html/, handler4); await page.goto(server.EMPTY_PAGE); @@ -81,11 +81,11 @@ it('should unroute', async ({ browser, server }) => { it('should yield to page.route', async ({ browser, server }) => { const context = await browser.newContext(); await context.route('**/empty.html', route => { - route.fulfill({ status: 200, body: 'context' }); + void route.fulfill({ status: 200, body: 'context' }); }); const page = await context.newPage(); await page.route('**/empty.html', route => { - route.fulfill({ status: 200, body: 'page' }); + void route.fulfill({ status: 200, body: 'page' }); }); const response = await page.goto(server.EMPTY_PAGE); expect(response.ok()).toBe(true); @@ -96,11 +96,11 @@ it('should yield to page.route', async ({ browser, server }) => { it('should fall back to context.route', async ({ browser, server }) => { const context = await browser.newContext(); await context.route('**/empty.html', route => { - route.fulfill({ status: 200, body: 'context' }); + void route.fulfill({ status: 200, body: 'context' }); }); const page = await context.newPage(); await page.route('**/non-empty.html', route => { - route.fulfill({ status: 200, body: 'page' }); + void route.fulfill({ status: 200, body: 'page' }); }); const response = await page.goto(server.EMPTY_PAGE); expect(response.ok()).toBe(true); @@ -112,7 +112,7 @@ it('should support Set-Cookie header', async ({ contextFactory, server, browserN const context = await contextFactory(); const page = await context.newPage(); await page.route('https://example.com/', (route, request) => { - route.fulfill({ + void route.fulfill({ headers: { 'Set-Cookie': 'name=value; domain=.example.com; Path=/' }, @@ -139,7 +139,7 @@ it('should ignore secure Set-Cookie header for insecure requests', async ({ cont const context = await contextFactory(); const page = await context.newPage(); await page.route('http://example.com/', (route, request) => { - route.fulfill({ + void route.fulfill({ headers: { 'Set-Cookie': 'name=value; domain=.example.com; Path=/; Secure' }, @@ -156,7 +156,7 @@ it('should use Set-Cookie header in future requests', async ({ contextFactory, s const page = await context.newPage(); await page.route(server.EMPTY_PAGE, (route, request) => { - route.fulfill({ + void route.fulfill({ headers: { 'Set-Cookie': 'name=value' }, @@ -199,7 +199,7 @@ it('should support the times parameter with route matching', async ({ context, p const intercepted = []; await context.route('**/empty.html', route => { intercepted.push(1); - route.continue(); + void route.continue(); }, { times: 1 }); await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE); @@ -210,7 +210,7 @@ it('should support the times parameter with route matching', async ({ context, p it('should support async handler w/ times', async ({ context, page, server }) => { await context.route('**/empty.html', async route => { await new Promise(f => setTimeout(f, 100)); - route.fulfill({ + void route.fulfill({ body: 'intercepted', contentType: 'text/html' }); @@ -223,7 +223,7 @@ it('should support async handler w/ times', async ({ context, page, server }) => it('should overwrite post body with empty string', async ({ context, server, page, browserName }) => { await context.route('**/empty.html', route => { - route.continue({ + void route.continue({ postData: '', }); }); @@ -250,15 +250,15 @@ it('should chain fallback', async ({ context, page, server }) => { const intercepted = []; await context.route('**/empty.html', route => { intercepted.push(1); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(2); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(3); - route.fallback(); + void route.fallback(); }); await page.goto(server.EMPTY_PAGE); expect(intercepted).toEqual([3, 2, 1]); @@ -268,16 +268,16 @@ it('should chain fallback w/ dynamic URL', async ({ context, page, server }) => const intercepted = []; await context.route('**/bar', route => { intercepted.push(1); - route.fallback({ url: server.EMPTY_PAGE }); + void route.fallback({ url: server.EMPTY_PAGE }); }); await context.route('**/foo', route => { intercepted.push(2); - route.fallback({ url: 'http://localhost/bar' }); + void route.fallback({ url: 'http://localhost/bar' }); }); await context.route('**/empty.html', route => { intercepted.push(3); - route.fallback({ url: 'http://localhost/foo' }); + void route.fallback({ url: 'http://localhost/foo' }); }); await page.goto(server.EMPTY_PAGE); @@ -290,10 +290,10 @@ it('should not chain fulfill', async ({ context, page, server }) => { failed = true; }); await context.route('**/empty.html', route => { - route.fulfill({ status: 200, body: 'fulfilled' }); + void route.fulfill({ status: 200, body: 'fulfilled' }); }); await context.route('**/empty.html', route => { - route.fallback(); + void route.fallback(); }); const response = await page.goto(server.EMPTY_PAGE); const body = await response.body(); @@ -307,10 +307,10 @@ it('should not chain abort', async ({ context, page, server }) => { failed = true; }); await context.route('**/empty.html', route => { - route.abort(); + void route.abort(); }); await context.route('**/empty.html', route => { - route.fallback(); + void route.fallback(); }); const e = await page.goto(server.EMPTY_PAGE).catch(e => e); expect(e).toBeTruthy(); @@ -321,27 +321,27 @@ it('should chain fallback into page', async ({ context, page, server }) => { const intercepted = []; await context.route('**/empty.html', route => { intercepted.push(1); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(2); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', route => { intercepted.push(3); - route.fallback(); + void route.fallback(); }); await page.route('**/empty.html', route => { intercepted.push(4); - route.fallback(); + void route.fallback(); }); await page.route('**/empty.html', route => { intercepted.push(5); - route.fallback(); + void route.fallback(); }); await page.route('**/empty.html', route => { intercepted.push(6); - route.fallback(); + void route.fallback(); }); await page.goto(server.EMPTY_PAGE); expect(intercepted).toEqual([6, 5, 4, 3, 2, 1]); @@ -352,17 +352,17 @@ it('should fall back async', async ({ page, context, server }) => { await context.route('**/empty.html', async route => { intercepted.push(1); await new Promise(r => setTimeout(r, 100)); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', async route => { intercepted.push(2); await new Promise(r => setTimeout(r, 100)); - route.fallback(); + void route.fallback(); }); await context.route('**/empty.html', async route => { intercepted.push(3); await new Promise(r => setTimeout(r, 100)); - route.fallback(); + void route.fallback(); }); await page.goto(server.EMPTY_PAGE); expect(intercepted).toEqual([3, 2, 1]); diff --git a/tests/library/browsercontext-storage-state.spec.ts b/tests/library/browsercontext-storage-state.spec.ts index bf64f2c074..b7ed36c87d 100644 --- a/tests/library/browsercontext-storage-state.spec.ts +++ b/tests/library/browsercontext-storage-state.spec.ts @@ -146,7 +146,7 @@ it('should not emit events about internal page', async ({ contextFactory }) => { const context = await contextFactory(); const page = await context.newPage(); await page.route('**/*', route => { - route.fulfill({ body: '' }); + void route.fulfill({ body: '' }); }); await page.goto('https://www.example.com'); await page.evaluate(() => localStorage['name1'] = 'value1'); diff --git a/tests/library/browsertype-connect.spec.ts b/tests/library/browsertype-connect.spec.ts index efdfed92c6..56b08c224a 100644 --- a/tests/library/browsertype-connect.spec.ts +++ b/tests/library/browsertype-connect.spec.ts @@ -637,7 +637,7 @@ for (const kind of ['launchServer', 'run-server'] as const) { await page.route('**/*', async route => { const request = await playwright.request.newContext(); const response = await request.get(server.PREFIX + '/simple.json'); - route.fulfill({ response }); + await route.fulfill({ response }); }); const response = await page.goto(server.EMPTY_PAGE); expect(response.status()).toBe(200); diff --git a/tests/library/capabilities.spec.ts b/tests/library/capabilities.spec.ts index 1a839932f1..f57241babb 100644 --- a/tests/library/capabilities.spec.ts +++ b/tests/library/capabilities.spec.ts @@ -257,13 +257,13 @@ it('requestFullscreen', async ({ page, server, browserName, headless, isLinux }) await page.goto(server.EMPTY_PAGE); await page.evaluate(() => { const result = new Promise(resolve => document.addEventListener('fullscreenchange', resolve)); - document.documentElement.requestFullscreen(); + void document.documentElement.requestFullscreen(); return result; }); expect(await page.evaluate(() => document.fullscreenElement === document.documentElement)).toBeTruthy(); await page.evaluate(() => { const result = new Promise(resolve => document.addEventListener('fullscreenchange', resolve)); - document.exitFullscreen(); + void document.exitFullscreen(); return result; }); expect(await page.evaluate(() => !!document.fullscreenElement)).toBeFalsy(); diff --git a/tests/library/channels.spec.ts b/tests/library/channels.spec.ts index 7162d47275..19c8133f16 100644 --- a/tests/library/channels.spec.ts +++ b/tests/library/channels.spec.ts @@ -239,7 +239,7 @@ it('should work with the domain module', async ({ browserType, server, browserNa let callback; const result = new Promise(f => callback = f); page.on('websocket', ws => ws.on('socketerror', callback)); - page.evaluate(port => { + void page.evaluate(port => { new WebSocket('ws://localhost:' + port + '/bogus-ws'); }, server.PORT); const message = await result; diff --git a/tests/library/chromium/chromium.spec.ts b/tests/library/chromium/chromium.spec.ts index ca88d866d7..8024706518 100644 --- a/tests/library/chromium/chromium.spec.ts +++ b/tests/library/chromium/chromium.spec.ts @@ -231,7 +231,7 @@ test.describe('should emit page-level network events with service worker fetch h await page.route('**', route => { if (route.request().url().endsWith('foo')) markFailureIfPageRoutesARequestAlreadyHandledByServiceWorker = true; - route.continue(); + void route.continue(); }); await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html'); await page.evaluate(() => window['activationPromise']); @@ -735,7 +735,7 @@ test.describe('PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1', () => { await page.route('**', route => { if (route.request().url().endsWith('foo')) markFailureIfPageRoutesARequestAlreadyHandledByServiceWorker = true; - route.continue(); + void route.continue(); }); await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html'); await page.evaluate(() => window['activationPromise']); @@ -761,7 +761,7 @@ test.describe('PW_EXPERIMENTAL_SERVICE_WORKER_NETWORK_EVENTS=1', () => { await page.route('**', route => { if (route.request().url().endsWith('foo')) markFailureIfPageRoutesARequestAlreadyHandledByServiceWorker = true; - route.continue(); + void route.continue(); }); await page.goto(server.PREFIX + '/serviceworkers/fetchdummy/sw.html'); await page.evaluate(() => window['activationPromise']); diff --git a/tests/library/chromium/oopif.spec.ts b/tests/library/chromium/oopif.spec.ts index 3fc4a05a31..9931f39521 100644 --- a/tests/library/chromium/oopif.spec.ts +++ b/tests/library/chromium/oopif.spec.ts @@ -140,7 +140,7 @@ it('should respect route', async ({ page, browser, server }) => { let intercepted = false; await page.route('**/digits/0.png', route => { intercepted = true; - route.continue(); + void route.continue(); }); await page.goto(server.PREFIX + '/dynamic-oopif.html'); expect(page.frames().length).toBe(2); @@ -238,7 +238,7 @@ it('should report google.com frame with headed', async ({ browserType, server }) const page = await browser.newPage(); await page.goto(server.EMPTY_PAGE); await page.route('**/*', route => { - route.fulfill({ body: 'YO, GOOGLE.COM' }); + void route.fulfill({ body: 'YO, GOOGLE.COM' }); }); await page.evaluate(() => { const frame = document.createElement('iframe'); diff --git a/tests/library/download.spec.ts b/tests/library/download.spec.ts index 176da604ac..ebd8ad13b3 100644 --- a/tests/library/download.spec.ts +++ b/tests/library/download.spec.ts @@ -279,7 +279,7 @@ it.describe('download event', () => { const page = await browser.newPage(); const onDownloadPath = new Promise(res => { page.on('download', dl => { - dl.path().then(res); + void dl.path().then(res); }); }); await page.setContent(`download`); @@ -293,7 +293,7 @@ it.describe('download event', () => { const page = await browser.newPage(); const onDownloadPath = new Promise(res => { page.on('download', dl => { - dl.path().then(res); + void dl.path().then(res); }); }); await page.goto(server.PREFIX + '/download-blob.html'); @@ -730,7 +730,7 @@ async function assertDownloadToPDF(download: Download, filePath: string) { assertBuffer(data, fs.readFileSync(filePath)); } -async function assertBuffer(expected: Buffer, actual: Buffer) { +function assertBuffer(expected: Buffer, actual: Buffer) { expect(expected.byteLength).toBe(actual.byteLength); for (let i = 0; i < expected.byteLength; i++) expect(expected[i]).toBe(actual[i]); diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.ts index 8cdce78d2b..1a5914ec44 100644 --- a/tests/library/har.spec.ts +++ b/tests/library/har.spec.ts @@ -258,8 +258,8 @@ it('should include secure set-cookies', async ({ contextFactory, httpsServer }, it('should record request overrides', async ({ contextFactory, server }, testInfo) => { const { page, getLog } = await pageWithHar(contextFactory, testInfo); - page.route('**/foo', route => { - route.fallback({ + await page.route('**/foo', route => { + void route.fallback({ url: server.EMPTY_PAGE, method: 'POST', headers: { @@ -472,7 +472,7 @@ it('should record failed request overrides', async ({ contextFactory, server }, res.socket.destroy(); }); await page.route('**/foo', route => { - route.fallback({ + void route.fallback({ url: server.EMPTY_PAGE, method: 'POST', headers: { @@ -502,7 +502,7 @@ it('should report the correct request body size', async ({ contextFactory, serve await Promise.all([ page.waitForResponse(server.PREFIX + '/api1'), page.evaluate(() => { - fetch('/api1', { + void fetch('/api1', { method: 'POST', body: 'abc123' }); @@ -519,7 +519,7 @@ it('should report the correct request body size when the bodySize is 0', async ( await Promise.all([ page.waitForResponse(server.PREFIX + '/api2'), page.evaluate(() => { - fetch('/api2', { + void fetch('/api2', { method: 'POST', body: '' }); diff --git a/tests/library/inspector/cli-codegen-2.spec.ts b/tests/library/inspector/cli-codegen-2.spec.ts index dcd27816fe..50b4be415d 100644 --- a/tests/library/inspector/cli-codegen-2.spec.ts +++ b/tests/library/inspector/cli-codegen-2.spec.ts @@ -507,7 +507,7 @@ test.describe('cli codegen', () => { const harFileName = testInfo.outputPath('har.har'); const cli = runCLI([`--save-trace=${traceFileName}`, `--save-storage=${storageFileName}`, `--save-har=${harFileName}`]); await cli.waitFor(`import { test, expect } from '@playwright/test'`); - cli.process.kill('SIGINT'); + await cli.process.kill('SIGINT'); const { exitCode } = await cli.process.exited; expect(exitCode).toBe(130); expect(fs.existsSync(traceFileName)).toBeTruthy(); diff --git a/tests/library/page-event-crash.spec.ts b/tests/library/page-event-crash.spec.ts index 0d3b000bb2..2da4ef40fc 100644 --- a/tests/library/page-event-crash.spec.ts +++ b/tests/library/page-event-crash.spec.ts @@ -19,7 +19,7 @@ import { contextTest as testBase, expect } from '../config/browserTest'; const test = testBase.extend<{ crash: () => void }, { dummy: string }>({ crash: async ({ page, toImpl, browserName }, run) => { - run(() => { + await run(() => { if (browserName === 'chromium') page.goto('chrome://crash').catch(e => {}); else if (browserName === 'webkit') diff --git a/tests/library/popup.spec.ts b/tests/library/popup.spec.ts index 9576a66e3e..8100fd28da 100644 --- a/tests/library/popup.spec.ts +++ b/tests/library/popup.spec.ts @@ -44,7 +44,7 @@ it('should respect routes from browser context', async function({ browser, serve await page.setContent('link'); let intercepted = false; await context.route('**/empty.html', route => { - route.continue(); + void route.continue(); intercepted = true; }); await Promise.all([ @@ -161,7 +161,7 @@ it('should respect routes from browser context when using window.open', async fu await page.goto(server.EMPTY_PAGE); let intercepted = false; await context.route('**/empty.html', route => { - route.continue(); + void route.continue(); intercepted = true; }); await Promise.all([ diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts index e5c3b8d40d..26bcafb2cb 100644 --- a/tests/library/trace-viewer.spec.ts +++ b/tests/library/trace-viewer.spec.ts @@ -244,13 +244,13 @@ test('should popup snapshot', async ({ page, runAndTrace, server }) => { test('should capture iframe with sandbox attribute', async ({ page, server, runAndTrace }) => { await page.route('**/empty.html', route => { - route.fulfill({ + void route.fulfill({ body: '', contentType: 'text/html' }).catch(() => {}); }); await page.route('**/iframe.html', route => { - route.fulfill({ + void route.fulfill({ body: '', contentType: 'text/html' }).catch(() => {}); @@ -273,7 +273,7 @@ test('should capture iframe with sandbox attribute', async ({ page, server, runA test('should capture data-url svg iframe', async ({ page, server, runAndTrace }) => { await page.route('**/empty.html', route => { - route.fulfill({ + void route.fulfill({ body: ``, contentType: 'text/html' }).catch(() => {}); @@ -638,7 +638,7 @@ test('should open two trace files', async ({ context, page, request, server, sho await page.locator('button').click(); { const response = await request.post(server.PREFIX + '/one-style.css'); - expect(response).toBeOK(); + await expect(response).toBeOK(); } const apiTrace = testInfo.outputPath('api.zip'); const contextTrace = testInfo.outputPath('context.zip'); @@ -676,7 +676,7 @@ test('should open two trace files', async ({ context, page, request, server, sho test('should include requestUrl in route.fulfill', async ({ page, runAndTrace, browserName }) => { await page.route('**/*', route => { - route.fulfill({ + void route.fulfill({ status: 200, headers: { 'content-type': 'text/html' @@ -711,7 +711,7 @@ test('should not crash with broken locator', async ({ page, runAndTrace, server test('should include requestUrl in route.continue', async ({ page, runAndTrace, server }) => { await page.route('**/*', route => { - route.continue({ url: server.EMPTY_PAGE }); + void route.continue({ url: server.EMPTY_PAGE }); }); const traceViewer = await runAndTrace(async () => { await page.goto('http://test.com'); @@ -727,7 +727,7 @@ test('should include requestUrl in route.continue', async ({ page, runAndTrace, test('should include requestUrl in route.abort', async ({ page, runAndTrace, server }) => { await page.route('**/*', route => { - route.abort(); + void route.abort(); }); const traceViewer = await runAndTrace(async () => { await page.goto('http://test.com').catch(() => {}); @@ -748,7 +748,7 @@ test('should serve overridden request', async ({ page, runAndTrace, server }) => res.end(`body { background: red }`); }); await page.route('**/one-style.css', route => { - route.continue({ + void route.continue({ url: server.PREFIX + '/custom.css' }); }); diff --git a/tests/library/tracing.spec.ts b/tests/library/tracing.spec.ts index 324ef088d3..34ee8d5f22 100644 --- a/tests/library/tracing.spec.ts +++ b/tests/library/tracing.spec.ts @@ -73,7 +73,7 @@ test('should use the correct apiName for event driven callbacks', async ({ conte await page.reload(); // now we do it again with a dialog event listener attached which should produce an action. page.on('dialog', dialog => { - dialog.accept('answer!'); + void dialog.accept('answer!'); }); await page.evaluate(() => alert('yo')); @@ -517,7 +517,7 @@ test('should hide internal stack frames', async ({ context, page }, testInfo) => let evalPromise; page.on('dialog', dialog => { evalPromise = page.evaluate('2+2'); - dialog.dismiss(); + void dialog.dismiss(); }); await page.setContent(`
Click me
`); await page.click('div'); @@ -537,7 +537,7 @@ test('should hide internal stack frames in expect', async ({ context, page }, te let expectPromise; page.on('dialog', dialog => { expectPromise = expect(page).toHaveTitle('Hello'); - dialog.dismiss(); + void dialog.dismiss(); }); await page.setContent(`Hello
Click me
`); await page.click('div'); diff --git a/tests/library/web-socket.spec.ts b/tests/library/web-socket.spec.ts index 041bc6f72b..92081fe892 100644 --- a/tests/library/web-socket.spec.ts +++ b/tests/library/web-socket.spec.ts @@ -140,7 +140,7 @@ it('should emit error', async ({ page, server, browserName }) => { let callback; const result = new Promise(f => callback = f); page.on('websocket', ws => ws.on('socketerror', callback)); - page.evaluate(port => { + await page.evaluate(port => { new WebSocket('ws://localhost:' + port + '/bogus-ws'); }, server.PORT); const message = await result; diff --git a/tests/page/interception.spec.ts b/tests/page/interception.spec.ts index 126cdd110d..17098269c2 100644 --- a/tests/page/interception.spec.ts +++ b/tests/page/interception.spec.ts @@ -23,7 +23,7 @@ it('should work with navigation @smoke', async ({ page, server }) => { const requests = new Map(); await page.route('**/*', route => { requests.set(route.request().url().split('/').pop(), route.request()); - route.continue(); + void route.continue(); }); server.setRedirect('/rrredirect', '/frames/one-frame.html'); await page.goto(server.PREFIX + '/rrredirect'); @@ -47,7 +47,7 @@ it('should intercept after a service worker', async ({ page, server, browserName await page.route('**/foo', route => { const slash = route.request().url().lastIndexOf('/'); const name = route.request().url().substring(slash + 1); - route.fulfill({ + void route.fulfill({ status: 200, contentType: 'text/css', body: 'responseFromInterception:' + name @@ -147,7 +147,7 @@ it('should work with regular expression passed from a different context', async expect(request.resourceType()).toBe('document'); expect(request.frame() === page.mainFrame()).toBe(true); expect(request.frame().url()).toBe('about:blank'); - route.continue(); + void route.continue(); intercepted = true; }); diff --git a/tests/page/locator-frame.spec.ts b/tests/page/locator-frame.spec.ts index 040063acfa..50151a4257 100644 --- a/tests/page/locator-frame.spec.ts +++ b/tests/page/locator-frame.spec.ts @@ -144,13 +144,13 @@ it('should click in lazy iframe', async ({ page, server }) => { // add blank iframe setTimeout(() => { - page.evaluate(() => { + void page.evaluate(() => { const iframe = document.createElement('iframe'); document.body.appendChild(iframe); }); // navigate iframe setTimeout(() => { - page.evaluate(() => document.querySelector('iframe').src = 'iframe.html'); + void page.evaluate(() => document.querySelector('iframe').src = 'iframe.html'); }, 500); }, 500); @@ -197,7 +197,7 @@ it('click should survive iframe navigation', async ({ page, server }) => { await page.goto(server.EMPTY_PAGE); const button = page.frameLocator('iframe').locator('button:has-text("Hello nested iframe")'); const promise = button.click(); - page.locator('iframe').evaluate(e => (e as HTMLIFrameElement).src = 'iframe-2.html'); + void page.locator('iframe').evaluate(e => (e as HTMLIFrameElement).src = 'iframe-2.html'); await promise; }); diff --git a/tests/page/network-post-data.spec.ts b/tests/page/network-post-data.spec.ts index bcc1f08704..6746ed07cd 100644 --- a/tests/page/network-post-data.spec.ts +++ b/tests/page/network-post-data.spec.ts @@ -94,7 +94,7 @@ it('should get post data for file/blob', async ({ page, server, browserName }) = page.evaluate(() => { const file = new File(['file-contents'], 'filename.txt'); - fetch('/data', { + void fetch('/data', { method: 'POST', headers: { 'content-type': 'application/octet-stream' diff --git a/tests/page/page-click.spec.ts b/tests/page/page-click.spec.ts index 5ccc3013e5..87fff7ff75 100644 --- a/tests/page/page-click.spec.ts +++ b/tests/page/page-click.spec.ts @@ -1041,7 +1041,7 @@ it('ensure events are dispatched in the individual tasks', async ({ page, browse console.log(`timeout ${name}`); }, 0); - Promise.resolve().then(function() { + void Promise.resolve().then(function() { console.log(`promise ${name}`); }); } diff --git a/tests/page/page-close.spec.ts b/tests/page/page-close.spec.ts index d7f40caa36..84d761d64f 100644 --- a/tests/page/page-close.spec.ts +++ b/tests/page/page-close.spec.ts @@ -21,7 +21,7 @@ it.skip(({ isWebView2 }) => isWebView2, 'Page.close() is not supported in WebVie it('should close page with active dialog', async ({ page }) => { await page.setContent(``); - page.click('button'); + void page.click('button'); await page.waitForEvent('dialog'); await page.close(); }); diff --git a/tests/page/page-dialog.spec.ts b/tests/page/page-dialog.spec.ts index 8940940a78..ca7c0d45ae 100644 --- a/tests/page/page-dialog.spec.ts +++ b/tests/page/page-dialog.spec.ts @@ -22,7 +22,7 @@ it('should fire', async ({ page, server }) => { expect(dialog.type()).toBe('alert'); expect(dialog.defaultValue()).toBe(''); expect(dialog.message()).toBe('yo'); - dialog.accept(); + void dialog.accept(); }); await page.evaluate(() => alert('yo')); }); @@ -34,7 +34,7 @@ it('should allow accepting prompts @smoke', async ({ page, isElectron }) => { expect(dialog.type()).toBe('prompt'); expect(dialog.defaultValue()).toBe('yes.'); expect(dialog.message()).toBe('question?'); - dialog.accept('answer!'); + void dialog.accept('answer!'); }); const result = await page.evaluate(() => prompt('question?', 'yes.')); expect(result).toBe('answer!'); @@ -44,7 +44,7 @@ it('should dismiss the prompt', async ({ page, isElectron }) => { it.skip(isElectron, 'prompt() is not a thing in electron'); page.on('dialog', dialog => { - dialog.dismiss(); + void dialog.dismiss(); }); const result = await page.evaluate(() => prompt('question?')); expect(result).toBe(null); @@ -52,7 +52,7 @@ it('should dismiss the prompt', async ({ page, isElectron }) => { it('should accept the confirm prompt', async ({ page }) => { page.on('dialog', dialog => { - dialog.accept(); + void dialog.accept(); }); const result = await page.evaluate(() => confirm('boolean?')); expect(result).toBe(true); @@ -60,7 +60,7 @@ it('should accept the confirm prompt', async ({ page }) => { it('should dismiss the confirm prompt', async ({ page }) => { page.on('dialog', dialog => { - dialog.dismiss(); + void dialog.dismiss(); }); const result = await page.evaluate(() => confirm('boolean?')); expect(result).toBe(false); @@ -76,7 +76,7 @@ it('should be able to close context with open alert', async ({ page }) => { it('should handle multiple alerts', async ({ page }) => { page.on('dialog', dialog => { - dialog.accept().catch(e => {}); + void dialog.accept().catch(e => {}); }); await page.setContent(`

Hello World

@@ -91,7 +91,7 @@ it('should handle multiple alerts', async ({ page }) => { it('should handle multiple confirms', async ({ page }) => { page.on('dialog', dialog => { - dialog.accept().catch(e => {}); + void dialog.accept().catch(e => {}); }); await page.setContent(`

Hello World

diff --git a/tests/page/page-dispatchevent.spec.ts b/tests/page/page-dispatchevent.spec.ts index 53a9475f26..85b928862b 100644 --- a/tests/page/page-dispatchevent.spec.ts +++ b/tests/page/page-dispatchevent.spec.ts @@ -108,13 +108,13 @@ it('should be atomic', async ({ playwright, page }) => { query(root, selector) { const result = root.querySelector(selector); if (result) - Promise.resolve().then(() => result.onclick = ''); + void Promise.resolve().then(() => result.onclick = ''); return result; }, queryAll(root: HTMLElement, selector: string) { const result = Array.from(root.querySelectorAll(selector)); for (const e of result) - Promise.resolve().then(() => (e as HTMLElement).onclick = null); + void Promise.resolve().then(() => (e as HTMLElement).onclick = null); return result; } }); diff --git a/tests/page/page-drag.spec.ts b/tests/page/page-drag.spec.ts index 78053b8182..58f82ba2d3 100644 --- a/tests/page/page-drag.spec.ts +++ b/tests/page/page-drag.spec.ts @@ -282,7 +282,7 @@ it.describe('Drag and drop', () => { await page.mouse.down(); await page.hover('#target'); await page.mouse.up(); - route.abort(); + await route.abort(); expect(await page.$eval('#target', target => target.contains(document.querySelector('#source')))).toBe(true); // could not find source in target }); diff --git a/tests/page/page-evaluate-no-stall.spec.ts b/tests/page/page-evaluate-no-stall.spec.ts index 39a50d7767..fc6359f799 100644 --- a/tests/page/page-evaluate-no-stall.spec.ts +++ b/tests/page/page-evaluate-no-stall.spec.ts @@ -28,7 +28,7 @@ test('should throw while pending navigation', async ({ page, server, toImpl }) = let error; await page.route('**/empty.html', async (route, request) => { error = await toImpl(page.mainFrame()).nonStallingRawEvaluateInExistingMainContext('2+2').catch(e => e); - route.abort(); + await route.abort(); }); await page.goto(server.EMPTY_PAGE).catch(() => {}); expect(error.message).toContain('Frame is currently attempting a navigation'); diff --git a/tests/page/page-event-console.spec.ts b/tests/page/page-event-console.spec.ts index 31f84a5045..df611dd9dd 100644 --- a/tests/page/page-event-console.spec.ts +++ b/tests/page/page-event-console.spec.ts @@ -210,8 +210,8 @@ it('do not update console count on unhandled rejections', async ({ page }) => { await page.evaluate(() => { const fail = async () => Promise.reject(new Error('error')); console.log('begin'); - fail(); - fail(); + void fail(); + void fail(); fail().catch(() => { console.log('end'); }); diff --git a/tests/page/page-navigation.spec.ts b/tests/page/page-navigation.spec.ts index a4a0942b17..01932d6b6f 100644 --- a/tests/page/page-navigation.spec.ts +++ b/tests/page/page-navigation.spec.ts @@ -40,7 +40,7 @@ it('should work with _blank target in form', async ({ page, server }) => { }); await page.goto(server.EMPTY_PAGE); - page.setContent(`
+ void page.setContent(`
`); await Promise.all([ @@ -48,7 +48,7 @@ it('should work with _blank target in form', async ({ page, server }) => { page.click('"Click me"') ]); - page.setContent(`
+ void page.setContent(`
`); await Promise.all([ diff --git a/tests/page/page-network-idle.spec.ts b/tests/page/page-network-idle.spec.ts index 9fabc42272..cd89b4fd61 100644 --- a/tests/page/page-network-idle.spec.ts +++ b/tests/page/page-network-idle.spec.ts @@ -47,7 +47,7 @@ async function networkIdleTest(frame: Frame, server: TestServer, action: () => P // Track when the action gets completed. let actionFinished = false; - actionPromise.then(() => actionFinished = true); + void actionPromise.then(() => actionFinished = true); // Wait for the frame's 'load' event. await waitForLoadPromise; @@ -98,7 +98,7 @@ it('should wait for networkidle to succeed navigation with request from previous it('should wait for networkidle in waitForNavigation', async ({ page, server }) => { await networkIdleTest(page.mainFrame(), server, () => { const promise = page.waitForNavigation({ waitUntil: 'networkidle' }); - page.goto(server.PREFIX + '/networkidle.html'); + void page.goto(server.PREFIX + '/networkidle.html'); return promise; }); }); @@ -182,7 +182,7 @@ it('should work after repeated navigations in the same page', async ({ page, ser let requestCount = 0; await page.route('**/empty.html', route => { - route.fulfill({ + void route.fulfill({ contentType: 'text/html', body: `