-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
31 lines (27 loc) · 969 Bytes
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import test, { type Page } from "@playwright/test";
export const throwOnConsoleError = (page: Page): void => {
page.on("console", (message) => {
if (message.type() === "error") throw message;
if (message.type() === "warning") console.warn(message);
});
page.on("pageerror", (error) => {
throw error;
});
};
export const clientCredentials = async (page: Page): Promise<void> => {
await page.route(`${process.env.BASE_URL}/**`, async (route, request) => {
const headers = {
...request.headers(),
"CF-Access-Client-Id": process.env.E2E_CLIENT_ID,
"CF-Access-Client-Secret": process.env.E2E_CLIENT_SECRET
};
// @ts-expect-error
await route.continue({ headers });
});
};
/// NOTE: currently forced download, see https://github.com/microsoft/playwright/pull/33267
export const attachReport = (name: string, path: string): Promise<void> =>
test.info().attach(name, {
path,
contentType: "text/html"
});