chore: enable no-floating-promises ESLint rule for tests (#23376)

https://github.com/microsoft/playwright/issues/23339
This commit is contained in:
Max Schmitt 2023-06-02 21:59:12 +02:00 committed by GitHub
parent af893a1019
commit 3c2a8fa306
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 265 additions and 244 deletions

15
tests/.eslintrc.js Normal file
View file

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

View file

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

View file

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

View file

@ -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<void> {
let pathName = url.parse(request.url!).path;
if (!filePath) {
if (pathName === '/')

View file

@ -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: '<title>Hello World</title>',
@ -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,<title>Hello World!</title>');
void window.loadURL('data:text/html,<title>Hello World!</title>');
});
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');

View file

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

View file

@ -73,7 +73,7 @@ export const electronTest = baseTest.extend<TraceViewerFixtures>(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);

View file

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

View file

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

View file

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

View file

@ -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: '<html>intercepted</html>',
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]);

View file

@ -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: '<html></html>' });
void route.fulfill({ body: '<html></html>' });
});
await page.goto('https://www.example.com');
await page.evaluate(() => localStorage['name1'] = 'value1');

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -279,7 +279,7 @@ it.describe('download event', () => {
const page = await browser.newPage();
const onDownloadPath = new Promise<string>(res => {
page.on('download', dl => {
dl.path().then(res);
void dl.path().then(res);
});
});
await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);
@ -293,7 +293,7 @@ it.describe('download event', () => {
const page = await browser.newPage();
const onDownloadPath = new Promise<string>(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]);

View file

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

View file

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

View file

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

View file

@ -44,7 +44,7 @@ it('should respect routes from browser context', async function({ browser, serve
await page.setContent('<a target=_blank rel=noopener href="empty.html">link</a>');
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([

View file

@ -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: '<iframe src="iframe.html" sandBOX="allow-scripts"></iframe>',
contentType: 'text/html'
}).catch(() => {});
});
await page.route('**/iframe.html', route => {
route.fulfill({
void route.fulfill({
body: '<html><button>Hello iframe</button></html>',
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: `<iframe src="data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' height='24px' viewBox='0 0 24 24' width='24px' fill='%23000000'%3e%3cpath d='M0 0h24v24H0z' fill='none'/%3e%3cpath d='M16.5 3c-1.74 0-3.41.81-4.5 2.09C10.91 3.81 9.24 3 7.5 3 4.42 3 2 5.42 2 8.5c0 3.78 3.4 6.86 8.55 11.54L12 21.35l1.45-1.32C18.6 15.36 22 12.28 22 8.5 22 5.42 19.58 3 16.5 3zm-4.4 15.55l-.1.1-.1-.1C7.14 14.24 4 11.39 4 8.5 4 6.5 5.5 5 7.5 5c1.54 0 3.04.99 3.57 2.36h1.87C13.46 5.99 14.96 5 16.5 5c2 0 3.5 1.5 3.5 3.5 0 2.89-3.14 5.74-7.9 10.05z'/%3e%3c/svg%3e"></iframe>`,
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'
});
});

View file

@ -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(`<div onclick='window.alert(123)'>Click me</div>`);
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(`<title>Hello</title><div onclick='window.alert(123)'>Click me</div>`);
await page.click('div');

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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(`<button onclick="setTimeout(() => alert(1))">alert</button>`);
page.click('button');
void page.click('button');
await page.waitForEvent('dialog');
await page.close();
});

View file

@ -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(`
<p>Hello World</p>
@ -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(`
<p>Hello World</p>

View file

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

View file

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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ it('should work with _blank target in form', async ({ page, server }) => {
});
await page.goto(server.EMPTY_PAGE);
page.setContent(`<form target="_blank" action="done.html" >
void page.setContent(`<form target="_blank" action="done.html" >
<input type="submit" value="Click me">
</form>`);
await Promise.all([
@ -48,7 +48,7 @@ it('should work with _blank target in form', async ({ page, server }) => {
page.click('"Click me"')
]);
page.setContent(`<form target="_blank" action="done.html" method="post">
void page.setContent(`<form target="_blank" action="done.html" method="post">
<input type="submit" value="Click me">
</form>`);
await Promise.all([

View file

@ -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: `
<script>
@ -193,7 +193,7 @@ it('should work after repeated navigations in the same page', async ({ page, ser
await page.route('**/sample', route => {
requestCount++;
route.fulfill({
void route.fulfill({
contentType: 'application/json',
body: JSON.stringify({
content: 'sample'

View file

@ -61,7 +61,7 @@ it('should not work for a redirect and interception', async ({ page, server }) =
const requests = [];
await page.route('**', route => {
requests.push(route.request());
route.continue();
void route.continue();
});
await page.goto(server.PREFIX + '/foo.html');
@ -180,7 +180,7 @@ it('should not get preflight CORS requests when intercepting', async ({ page, se
const routed = [];
await page.route('**/something', route => {
routed.push(route.request().method());
route.continue();
void route.continue();
});
const text = await page.evaluate(async url => {
@ -251,7 +251,7 @@ it('should override post data content type', async ({ page, server }) => {
await page.route('**/post', (route, request) => {
const headers = request.headers();
headers['content-type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
route.continue({
void route.continue({
headers,
postData: request.postData()
});

View file

@ -26,7 +26,7 @@ it('should amend HTTP headers', async ({ page, server }) => {
await page.route('**/*', route => {
const headers = Object.assign({}, route.request().headers());
headers['FOO'] = 'bar';
route.continue({ headers });
void route.continue({ headers });
});
await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
@ -48,7 +48,7 @@ it('should delete header with undefined value', async ({ page, server, browserNa
await page.route(server.PREFIX + '/something', async (route, request) => {
interceptedRequest = request;
const headers = await request.allHeaders();
route.continue({
void route.continue({
headers: {
...headers,
foo: undefined
@ -89,7 +89,7 @@ it('should amend method', async ({ page, server }) => {
it('should override request url', async ({ page, server }) => {
const serverRequest = server.waitForRequest('/global-var.html');
await page.route('**/foo', route => {
route.continue({ url: server.PREFIX + '/global-var.html' });
void route.continue({ url: server.PREFIX + '/global-var.html' });
});
const response = await page.goto(server.PREFIX + '/foo');
expect(response.request().url()).toBe(server.PREFIX + '/global-var.html');
@ -121,7 +121,7 @@ it('should not throw when continuing while page is closing', async ({ page, serv
let done;
await page.route('**/*', async route => {
done = Promise.all([
route.continue(),
void route.continue(),
page.close(),
]);
});
@ -146,7 +146,7 @@ it('should not throw when continuing after page is closed', async ({ page, serve
it('should override method along with url', async ({ page, server }) => {
const request = server.waitForRequest('/empty.html');
await page.route('**/foo', route => {
route.continue({
void route.continue({
url: server.EMPTY_PAGE,
method: 'POST'
});
@ -166,7 +166,7 @@ it.describe('post data', () => {
it('should amend post data', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {
route.continue({ postData: 'doggo' });
void route.continue({ postData: 'doggo' });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -182,7 +182,7 @@ it.describe('post data', () => {
await page.route('**/*', route => {
const headers = route.request().headers();
headers['content-type'] = 'application/json';
route.continue({ postData: data, headers });
void route.continue({ postData: data, headers });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -196,7 +196,7 @@ it.describe('post data', () => {
it('should amend method and post data', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {
route.continue({ method: 'POST', postData: 'doggo' });
void route.continue({ method: 'POST', postData: 'doggo' });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -209,7 +209,7 @@ it.describe('post data', () => {
it('should amend utf8 post data', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {
route.continue({ postData: 'пушкин' });
void route.continue({ postData: 'пушкин' });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -222,7 +222,7 @@ it.describe('post data', () => {
it('should amend longer post data', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
await page.route('**/*', route => {
route.continue({ postData: 'doggo-is-longer-than-birdy' });
void route.continue({ postData: 'doggo-is-longer-than-birdy' });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -236,7 +236,7 @@ it.describe('post data', () => {
await page.goto(server.EMPTY_PAGE);
const arr = Array.from(Array(256).keys());
await page.route('**/*', route => {
route.continue({ postData: Buffer.from(arr) });
void route.continue({ postData: Buffer.from(arr) });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -283,7 +283,7 @@ it('should work with Cross-Origin-Opener-Policy', async ({ page, server, browser
const intercepted = [];
await page.route('**/*', (route, req) => {
intercepted.push(req.url());
route.continue({
void route.continue({
headers: {
foo: 'bar'
}
@ -337,7 +337,7 @@ it('should delete the origin header', async ({ page, server, isAndroid, browserN
interceptedRequest = request;
const headers = await request.allHeaders();
delete headers['origin'];
route.continue({ headers });
void route.continue({ headers });
});
const [text, serverRequest] = await Promise.all([
@ -357,7 +357,7 @@ it('should continue preload link requests', async ({ page, server, browserName }
let intercepted = false;
await page.route('**/one-style.css', route => {
intercepted = true;
route.continue({
void route.continue({
headers: {
...route.request().headers(),
'custom': 'value'
@ -400,7 +400,7 @@ it('should intercept css variable with background url', async ({ page, server })
await page.route(server.PREFIX + '/pptr.png', async (route, request) => {
++interceptedRequests;
interceptCallback();
route.continue();
void route.continue();
});
await page.goto(server.PREFIX + '/test.html');
expect(await page.locator('div').textContent()).toBe('Yo!');

View file

@ -26,15 +26,15 @@ it('should fall back', async ({ page, server }) => {
const intercepted = [];
await page.route('**/empty.html', route => {
intercepted.push(1);
route.fallback();
void route.fallback();
});
await page.route('**/empty.html', route => {
intercepted.push(2);
route.fallback();
void route.fallback();
});
await page.route('**/empty.html', route => {
intercepted.push(3);
route.fallback();
void route.fallback();
});
await page.goto(server.EMPTY_PAGE);
expect(intercepted).toEqual([3, 2, 1]);
@ -45,17 +45,17 @@ it('should fall back async', async ({ page, server }) => {
await page.route('**/empty.html', async route => {
intercepted.push(1);
await new Promise(r => setTimeout(r, 100));
route.fallback();
void route.fallback();
});
await page.route('**/empty.html', async route => {
intercepted.push(2);
await new Promise(r => setTimeout(r, 100));
route.fallback();
void route.fallback();
});
await page.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]);
@ -67,10 +67,10 @@ it('should not chain fulfill', async ({ page, server }) => {
failed = true;
});
await page.route('**/empty.html', route => {
route.fulfill({ status: 200, body: 'fulfilled' });
void route.fulfill({ status: 200, body: 'fulfilled' });
});
await page.route('**/empty.html', route => {
route.fallback();
void route.fallback();
});
const response = await page.goto(server.EMPTY_PAGE);
const body = await response.body();
@ -84,10 +84,10 @@ it('should not chain abort', async ({ page, server }) => {
failed = true;
});
await page.route('**/empty.html', route => {
route.abort();
void route.abort();
});
await page.route('**/empty.html', route => {
route.fallback();
void route.fallback();
});
const e = await page.goto(server.EMPTY_PAGE).catch(e => e);
expect(e).toBeTruthy();
@ -96,13 +96,13 @@ it('should not chain abort', async ({ page, server }) => {
it('should fall back after exception', async ({ page, server }) => {
await page.route('**/empty.html', route => {
route.continue();
void route.continue();
});
await page.route('**/empty.html', async route => {
try {
await route.fulfill({ response: {} as any });
} catch (e) {
route.fallback();
void route.fallback();
}
});
await page.goto(server.EMPTY_PAGE);
@ -110,10 +110,10 @@ it('should fall back after exception', async ({ page, server }) => {
it('should chain once', async ({ page, server }) => {
await page.route('**/empty.html', route => {
route.fulfill({ status: 200, body: 'fulfilled one' });
void route.fulfill({ status: 200, body: 'fulfilled one' });
}, { times: 1 });
await page.route('**/empty.html', route => {
route.fallback();
void route.fallback();
}, { times: 1 });
const response = await page.goto(server.EMPTY_PAGE);
const body = await response.body();
@ -125,10 +125,10 @@ it('should amend HTTP headers', async ({ page, server }) => {
await page.route('**/sleep.zzz', async route => {
values.push(route.request().headers().foo);
values.push(await route.request().headerValue('FOO'));
route.continue();
void route.continue();
});
await page.route('**/*', route => {
route.fallback({ headers: { ...route.request().headers(), FOO: 'bar' } });
void route.fallback({ headers: { ...route.request().headers(), FOO: 'bar' } });
});
await page.goto(server.EMPTY_PAGE);
const [request] = await Promise.all([
@ -148,11 +148,11 @@ it('should delete header with undefined value', async ({ page, server, browserNa
let interceptedRequest;
await page.route('**/*', (route, request) => {
interceptedRequest = request;
route.continue();
void route.continue();
});
await page.route(server.PREFIX + '/something', async (route, request) => {
const headers = await request.allHeaders();
route.fallback({
void route.fallback({
headers: {
...headers,
foo: undefined
@ -185,7 +185,7 @@ it('should amend method', async ({ page, server }) => {
let method: string;
await page.route('**/*', route => {
method = route.request().method();
route.continue();
void route.continue();
});
await page.route('**/*', route => route.fallback({ method: 'POST' }));
@ -204,7 +204,7 @@ it('should override request url', async ({ page, server }) => {
let url: string;
await page.route('**/global-var.html', route => {
url = route.request().url();
route.continue();
void route.continue();
});
await page.route('**/foo', route => route.fallback({ url: server.PREFIX + '/global-var.html' }));
@ -223,10 +223,10 @@ it.describe('post data', () => {
let postData: string;
await page.route('**/*', route => {
postData = route.request().postData();
route.continue();
void route.continue();
});
await page.route('**/*', route => {
route.fallback({ postData: 'doggo' });
void route.fallback({ postData: 'doggo' });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -242,10 +242,10 @@ it.describe('post data', () => {
let postDataBuffer: Buffer;
await page.route('**/*', route => {
postDataBuffer = route.request().postDataBuffer();
route.continue();
void route.continue();
});
await page.route('**/*', route => {
route.fallback({ postData: Buffer.from(arr) });
void route.fallback({ postData: Buffer.from(arr) });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),
@ -265,10 +265,10 @@ it.describe('post data', () => {
let postData: string;
await page.route('**/*', route => {
postData = route.request().postDataJSON();
route.continue();
void route.continue();
});
await page.route('**/*', route => {
route.fallback({ postData: { foo: 'bar' } });
void route.fallback({ postData: { foo: 'bar' } });
});
const [serverRequest] = await Promise.all([
server.waitForRequest('/sleep.zzz'),

View file

@ -36,7 +36,7 @@ const it = base.extend<{
it('should work', async ({ page, server }) => {
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
status: 201,
headers: {
foo: 'bar'
@ -53,7 +53,7 @@ it('should work', async ({ page, server }) => {
it('should work with buffer as body', async ({ page, server, browserName, isLinux }) => {
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
status: 200,
contentType: 'text/plain',
body: Buffer.from('Yo, page!')
@ -66,7 +66,7 @@ it('should work with buffer as body', async ({ page, server, browserName, isLinu
it('should work with status code 422', async ({ page, server }) => {
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
status: 422,
body: 'Yo, page!'
});
@ -83,7 +83,7 @@ it('should allow mocking binary responses', async ({ page, server, browserName,
await page.route('**/*', route => {
const imageBuffer = fs.readFileSync(asset('pptr.png'));
route.fulfill({
void route.fulfill({
contentType: 'image/png',
body: imageBuffer
});
@ -104,7 +104,7 @@ it('should allow mocking svg with charset', async ({ page, server, browserName,
it.skip(isElectron, 'Protocol error (Storage.getCookies): Browser context management is not supported');
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
contentType: 'image/svg+xml ; charset=utf-8',
body: '<svg width="50" height="50" version="1.1" xmlns="http://www.w3.org/2000/svg"><rect x="10" y="10" width="30" height="30" stroke="black" fill="transparent" stroke-width="5"/></svg>'
});
@ -135,7 +135,7 @@ it('should work with file path', async ({ page, server, asset, mode, isAndroid }
it('should stringify intercepted request response headers', async ({ page, server }) => {
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
status: 200,
headers: {
'foo': 'true'
@ -170,7 +170,7 @@ it('should not modify the headers sent to the server', async ({ page, server })
expect(text).toBe('done');
await page.route(server.CROSS_PROCESS_PREFIX + '/something', (route, request) => {
route.continue({
void route.continue({
headers: {
...request.headers()
}
@ -194,7 +194,7 @@ it('should include the origin header', async ({ page, server, isAndroid }) => {
let interceptedRequest;
await page.route(server.CROSS_PROCESS_PREFIX + '/something', (route, request) => {
interceptedRequest = request;
route.fulfill({
void route.fulfill({
headers: {
'Access-Control-Allow-Origin': '*',
},
@ -216,7 +216,7 @@ it('should fulfill with global fetch result', async ({ playwright, page, server,
await page.route('**/*', async route => {
const request = await playwright.request.newContext();
const response = await request.get(rewriteAndroidLoopbackURL(server.PREFIX + '/simple.json'));
route.fulfill({ response });
void route.fulfill({ response });
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
@ -227,7 +227,7 @@ it('should fulfill with fetch result', async ({ page, server, isElectron, rewrit
it.fixme(isElectron, 'error: Browser context management is not supported.');
await page.route('**/*', async route => {
const response = await page.request.get(rewriteAndroidLoopbackURL(server.PREFIX + '/simple.json'));
route.fulfill({ response });
void route.fulfill({ response });
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.status()).toBe(200);
@ -238,7 +238,7 @@ it('should fulfill with fetch result and overrides', async ({ page, server, isEl
it.fixme(isElectron, 'error: Browser context management is not supported.');
await page.route('**/*', async route => {
const response = await page.request.get(rewriteAndroidLoopbackURL(server.PREFIX + '/simple.json'));
route.fulfill({
void route.fulfill({
response,
status: 201,
headers: {
@ -258,7 +258,7 @@ it('should fetch original request and fulfill', async ({ page, server, isElectro
it.skip(isAndroid, 'The internal Android localhost (10.0.0.2) != the localhost on the host');
await page.route('**/*', async route => {
const response = await page.request.fetch(route.request());
route.fulfill({
void route.fulfill({
response,
});
});
@ -271,7 +271,7 @@ it('should fulfill with multiple set-cookie', async ({ page, server, isElectron
it.fixme(isElectron, 'Electron 14+ is required');
const cookies = ['a=b', 'c=d'];
await page.route('**/empty.html', async route => {
route.fulfill({
void route.fulfill({
status: 200,
headers: {
'X-Header-1': 'v1',
@ -297,7 +297,7 @@ it('should fulfill with fetch response that has multiple set-cookie', async ({ p
await page.route('**/empty.html', async route => {
const request = await playwright.request.newContext();
const response = await request.fetch(route.request());
route.fulfill({ response });
void route.fulfill({ response });
});
await page.goto(server.EMPTY_PAGE);
const cookie = await page.evaluate(() => document.cookie);
@ -308,7 +308,7 @@ it('headerValue should return set-cookie from intercepted response', async ({ pa
it.fail(browserName === 'chromium', 'Set-Cookie is missing in response after interception');
it.skip(browserName === 'webkit', 'Set-Cookie with \n in intercepted response does not pass validation in WebCore, see also https://github.com/microsoft/playwright/pull/9273');
await page.route('**/empty.html', async route => {
route.fulfill({
void route.fulfill({
status: 200,
headers: {
'Set-Cookie': 'a=b',
@ -357,7 +357,7 @@ it('should fulfill preload link requests', async ({ page, server, browserName })
let intercepted = false;
await page.route('**/one-style.css', route => {
intercepted = true;
route.fulfill({
void route.fulfill({
status: 200,
headers: {
'content-type': 'text/css; charset=utf-8',
@ -380,7 +380,7 @@ it('should fulfill preload link requests', async ({ page, server, browserName })
it('should fulfill json', async ({ page, server }) => {
await page.route('**/*', route => {
route.fulfill({
void route.fulfill({
status: 201,
headers: {
foo: 'bar'

View file

@ -31,7 +31,7 @@ it('should intercept @smoke', async ({ page, 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();
intercepted = true;
});
const response = await page.goto(server.EMPTY_PAGE);
@ -43,19 +43,19 @@ it('should unroute', async ({ page, server }) => {
let intercepted = [];
await page.route('**/*', route => {
intercepted.push(1);
route.fallback();
void route.fallback();
});
await page.route('**/empty.html', route => {
intercepted.push(2);
route.fallback();
void route.fallback();
});
await page.route('**/empty.html', route => {
intercepted.push(3);
route.fallback();
void route.fallback();
});
const handler4 = route => {
intercepted.push(4);
route.fallback();
void route.fallback();
};
await page.route(/empty.html/, handler4);
await page.goto(server.EMPTY_PAGE);
@ -94,7 +94,7 @@ it('should work when header manipulation headers with redirect', async ({ page,
const headers = Object.assign({}, route.request().headers(), {
foo: 'bar'
});
route.continue({ headers });
void route.continue({ headers });
});
await page.goto(server.PREFIX + '/rrredirect');
});
@ -105,7 +105,7 @@ it('should be able to remove headers', async ({ page, server }) => {
await page.route('**/*', async route => {
const headers = { ...route.request().headers() };
delete headers['foo'];
route.continue({ headers });
void route.continue({ headers });
});
const [serverRequest] = await Promise.all([
@ -119,7 +119,7 @@ it('should contain referer header', async ({ page, server }) => {
const requests = [];
await page.route('**/*', route => {
requests.push(route.request());
route.continue();
void route.continue();
});
await page.goto(server.PREFIX + '/one-style.html');
expect(requests[1].url()).toContain('/one-style.css');
@ -151,7 +151,7 @@ it('should override cookie header', async ({ page, server, browserName }) => {
const headers = await route.request().allHeaders();
cookieValueInRoute = headers['cookie'];
headers['cookie'] = 'overridden=value';
route.continue({ headers });
void route.continue({ headers });
});
const [serverReq] = await Promise.all([
server.waitForRequest('/empty.html'),
@ -168,7 +168,7 @@ it('should show custom HTTP headers', async ({ page, server }) => {
});
await page.route('**/*', route => {
expect(route.request().headers()['foo']).toBe('bar');
route.continue();
void route.continue();
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
@ -248,7 +248,7 @@ it('should work with custom referer headers', async ({ page, server, browserName
expect(route.request().headers()['referer']).toBe(server.EMPTY_PAGE + ', ' + server.EMPTY_PAGE);
else
expect(route.request().headers()['referer']).toBe(server.EMPTY_PAGE);
route.continue();
void route.continue();
});
const response = await page.goto(server.EMPTY_PAGE);
expect(response.ok()).toBe(true);
@ -311,7 +311,7 @@ it('should fail navigation when aborting main resource', async ({ page, server,
it('should not work with redirects', async ({ page, server }) => {
const intercepted = [];
await page.route('**/*', route => {
route.continue();
void route.continue();
intercepted.push(route.request());
});
server.setRedirect('/non-existing-page.html', '/non-existing-page-2.html');
@ -347,16 +347,16 @@ it('should chain fallback w/ dynamic URL', async ({ page, server }) => {
const intercepted = [];
await page.route('**/bar', route => {
intercepted.push(1);
route.fallback({ url: server.EMPTY_PAGE });
void route.fallback({ url: server.EMPTY_PAGE });
});
await page.route('**/foo', route => {
intercepted.push(2);
route.fallback({ url: 'http://localhost/bar' });
void route.fallback({ url: 'http://localhost/bar' });
});
await page.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);
@ -366,7 +366,7 @@ it('should chain fallback w/ dynamic URL', async ({ page, server }) => {
it('should work with redirects for subresources', async ({ page, server }) => {
const intercepted = [];
await page.route('**/*', route => {
route.continue();
void route.continue();
intercepted.push(route.request());
});
server.setRedirect('/one-style.css', '/two-style.css');
@ -399,7 +399,7 @@ it('should work with equal requests', async ({ page, server }) => {
let spinner = false;
// Cancel 2nd request.
await page.route('**/*', route => {
spinner ? route.abort() : route.continue();
void (spinner ? route.abort() : route.continue());
spinner = !spinner;
});
const results = [];
@ -412,7 +412,7 @@ it('should navigate to dataURL and not fire dataURL requests', async ({ page, se
const requests = [];
await page.route('**/*', route => {
requests.push(route.request());
route.continue();
void route.continue();
});
const dataURL = 'data:text/html,<div>yo</div>';
const response = await page.goto(dataURL);
@ -425,7 +425,7 @@ it('should be able to fetch dataURL and not fire dataURL requests', async ({ pag
const requests = [];
await page.route('**/*', route => {
requests.push(route.request());
route.continue();
void route.continue();
});
const dataURL = 'data:text/html,<div>yo</div>';
const text = await page.evaluate(url => fetch(url).then(r => r.text()), dataURL);
@ -437,7 +437,7 @@ it('should navigate to URL with hash and and fire requests without hash', async
const requests = [];
await page.route('**/*', route => {
requests.push(route.request());
route.continue();
void route.continue();
});
const response = await page.goto(server.EMPTY_PAGE + '#hash');
expect(response.status()).toBe(200);
@ -466,7 +466,7 @@ it('should work with encoded server - 2', async ({ page, server, browserName, br
// report encoded URL for stylesheet. @see crbug.com/759388
const requests = [];
await page.route('**/*', route => {
route.continue();
void route.continue();
requests.push(route.request());
});
const response = await page.goto(`data:text/html,<link rel="stylesheet" href="${server.PREFIX}/fonts?helvetica|arial"/>`);
@ -482,7 +482,7 @@ it('should not throw "Invalid Interception Id" if the request was cancelled', as
await page.setContent('<iframe></iframe>');
let route = null;
await page.route('**/*', async r => route = r);
page.$eval('iframe', (frame, url) => frame.src = url, server.EMPTY_PAGE);
void page.$eval('iframe', (frame, url) => frame.src = url, server.EMPTY_PAGE);
// Wait for request interception.
await page.waitForEvent('request');
// Delete frame to cause request to be canceled.
@ -497,7 +497,7 @@ it('should intercept main resource during cross-process navigation', async ({ pa
let intercepted = false;
await page.route(server.CROSS_PROCESS_PREFIX + '/empty.html', route => {
intercepted = true;
route.continue();
void route.continue();
});
const response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
expect(response.ok()).toBe(true);
@ -868,7 +868,7 @@ it('should support the times parameter with route matching', async ({ page, serv
const intercepted = [];
await page.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);
@ -879,7 +879,7 @@ it('should support the times parameter with route matching', async ({ page, serv
it('should support async handler w/ times', async ({ page, server }) => {
await page.route('**/empty.html', async route => {
await new Promise(f => setTimeout(f, 100));
route.fulfill({
await route.fulfill({
body: '<html>intercepted</html>',
contentType: 'text/html'
});
@ -894,7 +894,7 @@ it('should contain raw request header', async ({ page, server }) => {
let headers: any;
await page.route('**/*', async route => {
headers = await route.request().allHeaders();
route.continue();
void route.continue();
});
await page.goto(server.PREFIX + '/empty.html');
expect(headers.accept).toBeTruthy();
@ -904,7 +904,7 @@ it('should contain raw response header', async ({ page, server }) => {
let request: any;
await page.route('**/*', async route => {
request = route.request();
route.continue();
void route.continue();
});
await page.goto(server.PREFIX + '/empty.html');
const response = await request.response();

View file

@ -239,7 +239,7 @@ it('should wait for option to be present', async ({ page, server }) => {
await page.goto(server.PREFIX + '/input/select.html');
const selectPromise = page.selectOption('select', 'scarlet');
let didSelect = false;
selectPromise.then(() => didSelect = true);
void selectPromise.then(() => didSelect = true);
await giveItAChanceToResolve(page);
expect(didSelect).toBe(false);
await page.$eval('select', select => {
@ -257,7 +257,7 @@ it('should wait for option index to be present', async ({ page, server }) => {
const len = await page.$eval('select', select => select.options.length);
const selectPromise = page.selectOption('select', { index: len });
let didSelect = false;
selectPromise.then(() => didSelect = true);
void selectPromise.then(() => didSelect = true);
await giveItAChanceToResolve(page);
expect(didSelect).toBe(false);
await page.$eval('select', select => {
@ -275,7 +275,7 @@ it('should wait for multiple options to be present', async ({ page, server }) =>
await page.evaluate(() => window['makeMultiple']());
const selectPromise = page.selectOption('select', ['green', 'scarlet']);
let didSelect = false;
selectPromise.then(() => didSelect = true);
void selectPromise.then(() => didSelect = true);
await giveItAChanceToResolve(page);
expect(didSelect).toBe(false);
await page.$eval('select', select => {

View file

@ -177,7 +177,7 @@ it('should work for frame', async ({ page, server }) => {
// give the promise a chance to resolve, even though it shouldn't
await page.evaluate('1');
expect(resolved).toBe(false);
request.continue();
await request.continue();
await loadPromise;
});

View file

@ -23,9 +23,9 @@ it('should work', async ({ page, server }) => {
const [request] = await Promise.all([
page.waitForRequest(server.PREFIX + '/digits/2.png'),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
})
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
@ -36,9 +36,9 @@ it('should work with predicate', async ({ page, server }) => {
const [request] = await Promise.all([
page.waitForEvent('request', request => request.url() === server.PREFIX + '/digits/2.png'),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
})
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
@ -71,9 +71,9 @@ it('should work with no timeout', async ({ page, server }) => {
const [request] = await Promise.all([
page.waitForRequest(server.PREFIX + '/digits/2.png', { timeout: 0 }),
page.evaluate(() => setTimeout(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
}, 50))
]);
expect(request.url()).toBe(server.PREFIX + '/digits/2.png');
@ -84,7 +84,7 @@ it('should work with url match', async ({ page, server }) => {
const [request] = await Promise.all([
page.waitForRequest(/digits\/\d\.png/),
page.evaluate(() => {
fetch('/digits/1.png');
void fetch('/digits/1.png');
})
]);
expect(request.url()).toBe(server.PREFIX + '/digits/1.png');
@ -98,7 +98,7 @@ it('should work with url match regular expression from a different context', asy
const [request] = await Promise.all([
page.waitForRequest(regexp),
page.evaluate(() => {
fetch('/digits/1.png');
void fetch('/digits/1.png');
})
]);
expect(request.url()).toBe(server.PREFIX + '/digits/1.png');

View file

@ -22,9 +22,9 @@ it('should work', async ({ page, server }) => {
const [response] = await Promise.all([
page.waitForResponse(server.PREFIX + '/digits/2.png'),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
})
]);
expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
@ -58,9 +58,9 @@ it('should work with predicate', async ({ page, server }) => {
const [response] = await Promise.all([
page.waitForEvent('response', response => response.url() === server.PREFIX + '/digits/2.png'),
page.evaluate(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
})
]);
expect(response.url()).toBe(server.PREFIX + '/digits/2.png');
@ -78,8 +78,8 @@ it('should work with async predicate', async ({ page, server }) => {
return text.includes('bar');
}),
page.evaluate(() => {
fetch('/simple.json').then(r => r.json());
fetch('/file-to-upload.txt').then(r => r.text());
void fetch('/simple.json').then(r => r.json());
void fetch('/file-to-upload.txt').then(r => r.text());
})
]);
expect(response1.url()).toBe(server.PREFIX + '/file-to-upload.txt');
@ -109,9 +109,9 @@ it('should work with no timeout', async ({ page, server }) => {
const [response] = await Promise.all([
page.waitForResponse(server.PREFIX + '/digits/2.png', { timeout: 0 }),
page.evaluate(() => setTimeout(() => {
fetch('/digits/1.png');
fetch('/digits/2.png');
fetch('/digits/3.png');
void fetch('/digits/1.png');
void fetch('/digits/2.png');
void fetch('/digits/3.png');
}, 50))
]);
expect(response.url()).toBe(server.PREFIX + '/digits/2.png');

View file

@ -219,13 +219,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);
@ -272,7 +272,7 @@ it('waitForSelector should survive iframe navigation (handle)', async ({ page, s
await page.goto(server.EMPTY_PAGE);
const body = await page.$('body');
const promise = body.waitForSelector('iframe >> internal:control=enter-frame >> button:has-text("Hello nested iframe")');
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;
});
@ -295,7 +295,7 @@ it('click should survive iframe navigation', async ({ page, server }) => {
await page.goto(server.EMPTY_PAGE);
const button = page.locator('iframe >> internal:control=enter-frame >> 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;
});

View file

@ -24,13 +24,13 @@ it('textContent should be atomic', async ({ playwright, page }) => {
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
void Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root: HTMLElement, selector: string) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
void Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
});
@ -46,13 +46,13 @@ it('innerText should be atomic', async ({ playwright, page }) => {
query(root: HTMLElement, selector: string) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
void Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root: HTMLElement, selector: string) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
void Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
});
@ -68,13 +68,13 @@ it('innerHTML should be atomic', async ({ playwright, page }) => {
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.textContent = 'modified');
void Promise.resolve().then(() => result.textContent = 'modified');
return result;
},
queryAll(root: HTMLElement, selector: string) {
const result = Array.from(root.querySelectorAll(selector));
for (const e of result)
Promise.resolve().then(() => e.textContent = 'modified');
void Promise.resolve().then(() => e.textContent = 'modified');
return result;
}
});
@ -90,13 +90,13 @@ it('getAttribute should be atomic', async ({ playwright, page }) => {
query(root: HTMLElement, selector: string) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.setAttribute('foo', 'modified'));
void Promise.resolve().then(() => result.setAttribute('foo', 'modified'));
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).setAttribute('foo', 'modified'));
void Promise.resolve().then(() => (e as HTMLElement).setAttribute('foo', 'modified'));
return result;
}
});
@ -112,13 +112,13 @@ it('isVisible should be atomic', async ({ playwright, page }) => {
query(root, selector) {
const result = root.querySelector(selector);
if (result)
Promise.resolve().then(() => result.style.display = 'none');
void Promise.resolve().then(() => result.style.display = 'none');
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).style.display = 'none');
void Promise.resolve().then(() => (e as HTMLElement).style.display = 'none');
return result;
}
});

View file

@ -45,7 +45,7 @@ test('should work after theme switch', async ({ runUITest, writeFiles }) => {
await expect(page.getByTestId('output')).toContainText(`Hello world 1`);
await page.getByTitle('Toggle color mode').click();
writeFiles({
await writeFiles({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('syntax error', async () => {

View file

@ -200,7 +200,7 @@ test('should update parametrized tests', async ({ runUITest, writeFiles }) => {
test LT
`);
writeFiles({
await writeFiles({
'a.test.ts': `
import { test } from '@playwright/test';
test.describe('cookies', () => {