Radish alpha
r
Radicle desktop app
Radicle
Git (anonymous pull)
Log in to clone via SSH
Instrument authentication for e2e tests
Sebastian Martinez committed 1 year ago
commit f23206b83dfa95c9962a351e5826ed49882a74da
parent 7cdf6544ad1b4b5949f3d322fe82c4369a9cf6dc
6 files changed +27 -9
modified 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,
    },
  ],
modified 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({
modified 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") {
modified src/lib/invoke.ts
@@ -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;
+
    });
  }
}

modified 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");
modified tests/support/peerManager.ts
@@ -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();