fix tests

This commit is contained in:
Max Schmitt 2024-06-26 11:17:51 +02:00
parent af035e9ff9
commit f10eefe714
3 changed files with 12 additions and 12 deletions

View file

@ -319,7 +319,7 @@ export class Chromium extends BrowserType {
if (process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW) if (process.env.PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW)
chromeArguments.push('--headless=new'); chromeArguments.push('--headless=new');
else else
chromeArguments.push('--headless'); chromeArguments.push('--headless=old');
chromeArguments.push( chromeArguments.push(
'--hide-scrollbars', '--hide-scrollbars',

View file

@ -37,7 +37,7 @@ export function getExceptionMessage(exceptionDetails: Protocol.Runtime.Exception
} }
export async function releaseObject(client: CRSession, objectId: string) { export async function releaseObject(client: CRSession, objectId: string) {
await client.send('Runtime.releaseObject', { objectId }).catch(error => {}); await client.send('Runtime.releaseObject', { objectId }).catch(error => { });
} }
export async function saveProtocolStream(client: CRSession, handle: string, path: string) { export async function saveProtocolStream(client: CRSession, handle: string, path: string) {
@ -91,7 +91,8 @@ export function exceptionToError(exceptionDetails: Protocol.Runtime.ExceptionDet
const err = new Error(message); const err = new Error(message);
err.stack = stack; err.stack = stack;
err.name = name; const nameOverride = exceptionDetails.exception?.preview?.properties.find(o => o.name === 'name');
err.name = nameOverride ? nameOverride.value ?? 'Error' : name;
return err; return err;
} }

View file

@ -139,15 +139,14 @@ it('should not crash on showDirectoryPicker', async ({ page, server, browserName
it.skip(browserName === 'chromium' && browserMajorVersion < 99, 'Fixed in Chromium r956769'); it.skip(browserName === 'chromium' && browserMajorVersion < 99, 'Fixed in Chromium r956769');
it.skip(browserName !== 'chromium', 'showDirectoryPicker is only available in Chromium'); it.skip(browserName !== 'chromium', 'showDirectoryPicker is only available in Chromium');
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
await Promise.race([ page.evaluate(async () => {
page.evaluate(async () => { const dir = await (window as any).showDirectoryPicker();
const dir = await (window as any).showDirectoryPicker(); return dir.name;
return dir.name; // In headless it throws (aborted), in headed it stalls (Test ended) and waits for the picker to be accepted.
}).catch(e => expect(e.message).toContain('DOMException: The user aborted a request')), }).catch(e => expect(e.message).toMatch(/((DOMException|AbortError): The user aborted a request|Test ended)/));
// The dialog will not be accepted, so we just wait for some time to // The dialog will not be accepted, so we just wait for some time to
// to give the browser a chance to crash. // to give the browser a chance to crash.
new Promise(r => setTimeout(r, 1000)) await page.waitForTimeout(3_000);
]);
}); });
it('should not crash on storage.getDirectory()', async ({ page, server, browserName, isMac }) => { it('should not crash on storage.getDirectory()', async ({ page, server, browserName, isMac }) => {