Files
radicle-explorer/httpd-client/tests/support/fixtures.ts
T
Sebastian Martinez 3d4e1bbfd9 Add httpd test fixture to vitest httpd-api tests
This fixture is simil to the way Playwright handles fixtures, which are
being setup and teardown for each test.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-07-12 10:58:45 +02:00

33 lines
1.0 KiB
TypeScript

import * as FsSync from "node:fs";
import * as Path from "node:path";
import { test } from "vitest";
import { HttpdClient } from "@httpd-client";
import { RadiclePeer, createPeerManager } from "@tests/support/peerManager.js";
import { gitOptions } from "@tests/support/fixtures.js";
import { tmpDir } from "@tests/support/support.js";
interface TestFixtures {
httpd: { api: HttpdClient; peer: RadiclePeer };
}
export const testFixture = test.extend<TestFixtures>({
// eslint-disable-next-line no-empty-pattern
httpd: async ({}, use) => {
const peerManager = await createPeerManager({
dataDir: Path.resolve(Path.join(tmpDir, "peers")),
outputLog: FsSync.createWriteStream(
Path.join(tmpDir, "peerManager.log"),
).setMaxListeners(16),
});
const peer = await peerManager.startPeer({
name: "palm",
gitOptions: gitOptions["alice"],
});
await peer.startHttpd();
const api = new HttpdClient(peer.httpdBaseUrl);
await use({ api, peer });
await peer.stopHttpd();
},
});