Files
radicle-explorer/tests/support/globalSetup.ts
T
xphoniexandRūdolfs Ošiņš f72405a3e4 Add support for Heartwood
Co-authored-by: Rūdolfs Ošiņš <rudolfs@osins.org>
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
2023-01-04 11:20:14 +01:00

40 lines
1.3 KiB
TypeScript

import type { FullConfig } from "@playwright/test";
import { seedPort, seedRemote } from "@tests/support/fixtures.js";
export default async function globalSetup(_config: FullConfig): Promise<void> {
assertHttpApiRunning();
}
// Assert that the test http-api is running. If it is not running, throw an
// error that explains how to run it.
async function assertHttpApiRunning(): Promise<void> {
const notRunningMessage =
"The http-api server with test fixtures needs to be running.\n" +
(process.env.HEARTWOOD
? "👉 You can start it with `./scripts/run-httpd-with-fixtures`\n"
: "👉 You can start it with `./scripts/run-http-api-with-fixtures`\n");
let peerId: string | undefined = undefined;
try {
if (process.env.HEARTWOOD) {
const response = await fetch(`http://0.0.0.0:${seedPort}/api`);
const data = await response.json();
peerId = data.node.id;
} else {
const response = await fetch(`http://0.0.0.0:${seedPort}`);
const data = await response.json();
peerId = data.peer.id;
}
} catch (err) {
console.error(err);
throw new Error(notRunningMessage);
}
if (peerId !== seedRemote) {
const wrongSeedMessage = `The server on port ${seedPort} doesn't have the right fixtures.\n`;
throw new Error(wrongSeedMessage + notRunningMessage);
}
}