From f23206b83dfa95c9962a351e5826ed49882a74da Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 21 Nov 2024 10:29:14 +0100 Subject: [PATCH] Instrument authentication for e2e tests --- playwright.config.ts | 3 ++- src/App.svelte | 5 ++++- src/lib/auth.ts | 2 +- src/lib/invoke.ts | 13 ++++++++----- tests/e2e/repos.spec.ts | 2 +- tests/support/peerManager.ts | 11 +++++++++++ 6 files changed, 27 insertions(+), 9 deletions(-) diff --git a/playwright.config.ts b/playwright.config.ts index 4f3d80b45..14ea6abb4 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -32,7 +32,8 @@ const config: PlaywrightTestConfig = { webServer: [ { - command: "npm run start -- --strictPort --port 3001", + command: + "VITE_AUTH_LONG_DELAY=1000 npm run start -- --strictPort --port 3001", port: 3001, }, ], diff --git a/src/App.svelte b/src/App.svelte index 383397b8b..4cd783006 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -39,7 +39,10 @@ try { await invoke("authenticate"); void router.loadFromLocation(); - void dynamicInterval(checkAuth, 30_000); + void dynamicInterval( + checkAuth, + import.meta.env.VITE_AUTH_LONG_DELAY || 30_000, + ); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { void router.push({ diff --git a/src/lib/auth.ts b/src/lib/auth.ts index 9df85daf4..bf64ee130 100644 --- a/src/lib/auth.ts +++ b/src/lib/auth.ts @@ -26,7 +26,7 @@ export async function checkAuth() { if (get(activeRouteStore).resource === "authenticationError") { window.history.back(); } - dynamicInterval(checkAuth, 30_000); + dynamicInterval(checkAuth, import.meta.env.VITE_AUTH_LONG_DELAY || 30_000); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { if (get(activeRouteStore).resource !== "authenticationError") { diff --git a/src/lib/invoke.ts b/src/lib/invoke.ts index 36c8b76bd..db153929b 100644 --- a/src/lib/invoke.ts +++ b/src/lib/invoke.ts @@ -12,11 +12,14 @@ export async function invoke( method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(args), - }) - .then(data => data.json()) - .catch(() => { - throw Error(`Issue with HTTP Route: ${JSON.stringify({ cmd, args })}`); - }); + }).then(async response => { + const json = await response.json(); + if (!response.ok) { + throw json; + } + + return json; + }); } } diff --git a/tests/e2e/repos.spec.ts b/tests/e2e/repos.spec.ts index 512f45c47..2cf5cfb9c 100644 --- a/tests/e2e/repos.spec.ts +++ b/tests/e2e/repos.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from "@playwright/test"; +import { expect, test } from "@tests/support/fixtures.js"; test("navigate to repo issues", async ({ page }) => { await page.goto("/repos"); diff --git a/tests/support/peerManager.ts b/tests/support/peerManager.ts index 0b354bc34..f19af4f56 100644 --- a/tests/support/peerManager.ts +++ b/tests/support/peerManager.ts @@ -235,6 +235,17 @@ export class RadiclePeer { }); } + /** + Removes the peers identity file from the `ssh-agent` + **/ + public async logOut(): Promise { + await this.spawn("ssh-add", ["-d", `${this.#radHome}/keys/radicle.pub`]); + } + + public async authenticate(): Promise { + await this.spawn("rad", ["auth"]); + } + public async startHttpd(port?: number): Promise { if (!port) { port = await getPort();