Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add `peerManager` to e2e tests fixture
Sebastian Martinez committed 2 years ago
commit 277c8d23fd97ebcdf43e512211cd946c578c4b4a
parent 7c71ff9ad67e7f9de4e664aa0884b25d8bd3822d
3 files changed +90 -12
modified tests/e2e/project/commits.spec.ts
@@ -4,6 +4,7 @@ import {
  projectFixtureUrl,
  bobRemote,
  aliceRemote,
+
  gitOptions,
} from "@tests/support/fixtures.js";

test("peer and branch switching", async ({ page }) => {
@@ -115,3 +116,23 @@ test("relative timestamps", async ({ page }) => {
    "Alice Liddell committed last month",
  );
});
+

+
test("pushing changes while viewing history", async ({ page, peerManager }) => {
+
  const alice = await peerManager.startPeer({
+
    name: "alice",
+
    gitOptions: gitOptions["alice"],
+
  });
+
  await alice.startHttpd(8090);
+
  await alice.startNode();
+
  const { rid, projectFolder } = await alice.createProject("alice-project");
+
  await page.goto(`/seeds/127.0.0.1:8090/${rid}`);
+
  await page.locator('role=link[name="1 commit"]').click();
+

+
  alice.setCwd(projectFolder);
+
  await alice.git(["commit", "--allow-empty", "--message", "first change"]);
+
  await alice.git(["push", "rad", "main"]);
+
  await page.reload();
+
  await expect(page).toHaveURL(`/seeds/127.0.0.1:8090/${rid}/history/main`);
+
  await page.locator('role=link[name="2 commits"]').click();
+
  await expect(page.getByTitle("Current branch")).toContainText("main 516fa74");
+
});
modified tests/support/fixtures.ts
@@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import type * as Stream from "node:stream";
+
import type { PeerManager } from "./peerManager.js";

import * as Fs from "node:fs/promises";
import * as FsSync from "node:fs";
@@ -24,6 +25,7 @@ export const test = base.extend<{
  forAllTests: void;
  customAppConfig: boolean;
  stateDir: string;
+
  peerManager: PeerManager;
  outputLog: Stream.Writable;
}>({
  customAppConfig: [false, { option: true }],
@@ -129,11 +131,26 @@ export const test = base.extend<{
    await logFile.close();
  },

+
  peerManager: async ({ stateDir, outputLog }, use) => {
+
    const peerManager = await createPeerManager({
+
      dataDir: Path.resolve(Path.join(stateDir, "peers")),
+
      outputLog,
+
    });
+
    await use(peerManager);
+
  },
+

  // eslint-disable-next-line no-empty-pattern
  stateDir: async ({}, use, testInfo) => {
-
    const stateDir = testInfo.outputDir;
+
    // Ok, we're moving the state dir to /tmp to avoid hitting the SUN_LEN limit, due to socket files.
+
    // We still create a symlink in the testInfo.outputDir, so that we can easily find the state dir.
+
    const stateDir = Path.join(
+
      "/tmp",
+
      Path.basename(testInfo.testId.substring(0, 8)),
+
    );
    await Fs.rm(stateDir, { recursive: true, force: true });
+
    await Fs.rm(testInfo.outputDir, { recursive: true, force: true });
    await Fs.mkdir(stateDir, { recursive: true });
+
    await Fs.symlink(stateDir, testInfo.outputDir);

    await use(stateDir);
    if (
@@ -141,6 +158,7 @@ export const test = base.extend<{
      (testInfo.status === "passed" || testInfo.status === "skipped")
    ) {
      await Fs.rm(stateDir, { recursive: true });
+
      await Fs.rm(testInfo.outputDir, { recursive: true });
    }
  },
});
@@ -235,6 +253,7 @@ export async function createSeedFixture() {
  await bob.connect(palm);

  await alice.git(["clone", sourceBrowsingDir], { cwd: alice.checkoutPath });
+
  alice.setCwd(Path.join(alice.checkoutPath, "source-browsing"));
  await alice.git(["checkout", "feature/branch"]);
  await alice.git(["checkout", "orphaned-branch"]);
  await alice.git(["checkout", "main"]);
@@ -266,6 +285,7 @@ export async function createSeedFixture() {
    Path.join(bob.checkoutPath, "source-browsing", "README.md"),
    "Updated readme",
  );
+
  bob.setCwd(Path.join(bob.checkoutPath, "source-browsing"));
  await bob.git(["add", "README.md"]);
  await bob.git([
    "commit",
modified tests/support/peerManager.ts
@@ -109,6 +109,7 @@ export class RadiclePeer {

  #seed: string;
  #radHome: string;
+
  #cwd?: string;
  #eventRecords: NodeEvent[] = [];
  #outputLog: Stream.Writable;
  #gitOptions?: Record<string, string>;
@@ -171,12 +172,12 @@ export class RadiclePeer {
    });
  }

-
  public async startHttpd() {
+
  public async startHttpd(port = 8080) {
    // eslint-disable-next-line @typescript-eslint/no-floating-promises
-
    this.spawn("radicle-httpd");
+
    this.spawn("radicle-httpd", ["--listen", `0.0.0.0:${port}`]);

    await waitOn({
-
      resources: ["tcp:127.0.0.1:8080"],
+
      resources: [`tcp:0.0.0.0:${port}`],
      timeout: 7000,
    });
  }
@@ -230,6 +231,43 @@ export class RadiclePeer {
    );
  }

+
  // Create a project using the rad CLI.
+
  public async createProject(
+
    name: string,
+
    description = "",
+
    defaultBranch = "main",
+
  ): Promise<{ rid: string; projectFolder: string }> {
+
    const projectFolder = Path.join(this.checkoutPath, name);
+

+
    await this.git(["init", name, "--initial-branch", defaultBranch], {
+
      cwd: this.checkoutPath,
+
    });
+
    await this.git(["commit", "--allow-empty", "--message", "initial commit"], {
+
      cwd: projectFolder,
+
    });
+
    await this.rad(
+
      [
+
        "init",
+
        "--name",
+
        name,
+
        "--default-branch",
+
        defaultBranch,
+
        "--description",
+
        description,
+
        "--announce",
+
      ],
+
      {
+
        cwd: projectFolder,
+
      },
+
    );
+

+
    const { stdout: rid } = await this.rad(["inspect"], {
+
      cwd: projectFolder,
+
    });
+

+
    return { rid, projectFolder };
+
  }
+

  public async waitForRoutes(rid: string, ...nodes: string[]) {
    let remaining = nodes;

@@ -285,18 +323,16 @@ export class RadiclePeer {
    return `/seeds/127.0.0.1:8080/${rid}`;
  }

+
  public setCwd(cwd: string) {
+
    this.#cwd = cwd;
+
  }
+

  public git(args: string[] = [], opts?: Options): ExecaChildProcess {
-
    return this.spawn("git", args, {
-
      cwd: Path.join(this.checkoutPath, "source-browsing"),
-
      ...opts,
-
    });
+
    return this.spawn("git", args, { ...opts });
  }

  public rad(args: string[] = [], opts?: Options): ExecaChildProcess {
-
    return this.spawn("rad", args, {
-
      cwd: Path.join(this.checkoutPath, "source-browsing"),
-
      ...opts,
-
    });
+
    return this.spawn("rad", args, { ...opts });
  }

  public spawn(
@@ -305,6 +341,7 @@ export class RadiclePeer {
    opts?: Options,
  ): ExecaChildProcess {
    opts = {
+
      cwd: this.#cwd,
      ...opts,
      env: {
        ...opts?.env,