Skip to content

Commit

Permalink
fix(e2e): send client credentials only to base url
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhirn committed Dec 23, 2024
1 parent 8902146 commit ac222cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion e2e/index.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { expect, test } from "@playwright/test";

import { throwOnConsoleError } from "./utils.js";
import { clientCredentials, throwOnConsoleError } from "./utils";

test.describe("e2e", () => {
test("title", async ({ page }) => {
throwOnConsoleError(page);
await clientCredentials(page);

await page.goto("/");
await expect(page).toHaveTitle(/Solid Pages/);
Expand Down
14 changes: 13 additions & 1 deletion e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type Page } from "@playwright/test";

export const throwOnConsoleError = (page: Page) => {
export const throwOnConsoleError = (page: Page): void => {
page.on("console", (message) => {
if (message.type() === "error") throw message;
if (message.type() === "warning") console.warn(message);
Expand All @@ -10,3 +10,15 @@ export const throwOnConsoleError = (page: Page) => {
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 });
});
};
8 changes: 1 addition & 7 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ export default defineConfig({
use: {
baseURL: process.env.BASE_URL ?? "http://localhost:3000",
trace: "on-first-retry",
viewport: { width: 1920, height: 1080 },
extraHTTPHeaders: {
// @ts-expect-error
"CF-Access-Client-Id": process.env.E2E_CLIENT_ID,
// @ts-expect-error
"CF-Access-Client-Secret": process.env.E2E_CLIENT_SECRET
}
viewport: { width: 1920, height: 1080 }
},
reporter: [
["html", { open: "never", outputFolder: "reports/e2e" }],
Expand Down

0 comments on commit ac222cd

Please sign in to comment.