Instrument authentication for e2e tests

This commit is contained in:
Sebastian Martinez
2024-11-21 10:29:14 +01:00
parent 7cdf6544ad
commit f23206b83d
6 changed files with 27 additions and 9 deletions
+2 -1
View File
@@ -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,
},
],
+4 -1
View File
@@ -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({
+1 -1
View File
@@ -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") {
+8 -5
View File
@@ -12,11 +12,14 @@ export async function invoke<T = null>(
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;
});
}
}
+1 -1
View File
@@ -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");
+11
View File
@@ -235,6 +235,17 @@ export class RadiclePeer {
});
}
/**
Removes the peers identity file from the `ssh-agent`
**/
public async logOut(): Promise<void> {
await this.spawn("ssh-add", ["-d", `${this.#radHome}/keys/radicle.pub`]);
}
public async authenticate(): Promise<void> {
await this.spawn("rad", ["auth"]);
}
public async startHttpd(port?: number): Promise<void> {
if (!port) {
port = await getPort();