Files
radicle-explorer/tests/support/globalSetup.ts
T
Thomas Scholtes 999adff9c1 Ensure correct order when setting up fixtures
When setting up the global fixtures we need to ensure that the peers
that create changes sync their changes to the seed (palm). The only
thing necessary is for the peer to discover palm as the seed for the
project. Then `git push rad --all` will sync all changes to palm.

It’s not necessary to listen for any other event and we remove the
corresponding calls to `waitForEvent` or `waitForRoutes`.

In fact, these calls never did anything besides sleep since the
implementation of `waitForEvent` was faulty. We fix that, too.

Signed-off-by: Thomas Scholtes <geigerzaehler@axiom.fm>
2023-11-25 06:40:30 +01:00

76 lines
2.3 KiB
TypeScript

import * as FsSync from "node:fs";
import * as Path from "node:path";
import {
assertRadInstalled,
removeWorkspace,
tmpDir,
} from "@tests/support/support.js";
import {
createCobsFixture,
createMarkdownFixture,
createSourceBrowsingFixture,
defaultHttpdPort,
gitOptions,
startPalmHttpd,
} from "@tests/support/fixtures.js";
import { createPeerManager } from "@tests/support/peerManager.js";
import { killAllProcesses } from "@tests/support/process.js";
export default async function globalSetup(): Promise<() => void> {
try {
await assertRadInstalled();
} catch (error) {
console.error(error);
console.log("");
console.log("To download the required test binaries, run:");
console.log(" 👉 ./scripts/install-binaries");
console.log("");
process.exit(1);
}
if (!process.env.SKIP_FIXTURE_CREATION) {
console.log("Setting up global test environment");
await removeWorkspace();
// Workaround for fixing MaxListenersExceededWarning.
// Since every prefixOutput stream adds stream listeners that don't autoClose.
// TODO: We still seem to have some descriptors left open when running vitest, which we should handle.
const peerManager = await createPeerManager({
dataDir: Path.resolve(Path.join(tmpDir, "peers")),
outputLog: FsSync.createWriteStream(
Path.join(tmpDir, "globalSetup.log"),
).setMaxListeners(16),
});
const palm = await peerManager.startPeer({
name: "palm",
gitOptions: gitOptions["alice"],
});
await palm.startHttpd(defaultHttpdPort);
await palm.startNode({ policy: "track", scope: "all", alias: "palm" });
try {
await createSourceBrowsingFixture(peerManager, palm);
console.log("Creating source-browsing fixture");
await createMarkdownFixture(palm);
console.log("Creating markdown fixture");
await createCobsFixture(palm);
console.log("Creating cobs fixture");
} catch (error) {
console.log("");
console.log("Not able to create the required fixtures.");
console.log("Make sure you are not using binaries compiled for release.");
console.log("");
console.log(error);
console.log("");
process.exit(1);
}
console.log("Running tests");
await palm.stopNode();
} else {
await startPalmHttpd(defaultHttpdPort);
}
return () => killAllProcesses();
}