mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-02 13:53:12 +00:00
* feat(browser-tests): simplify, refactor, update dockerized browser node * Update packages/browser-tests/web/index.ts * fix: remove comments and console.logs from tests * fix: add temporary logging * fix: debugging static sharding * fix: replace console with logger * fix: remove use of any * fix: log dial error * fix: replace any with libp2p options * fix: remove unused logic around sourcing address.env * fix: uncomment log * fix: add more logging and fix tests * feat: add types for test-config * fix: add types to server.ts * fix: remove more uses of any * fix: remove use of any in endpoint handlers
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { test, expect } from "@playwright/test";
|
|
import axios from "axios";
|
|
import { spawn, ChildProcess } from "child_process";
|
|
import { fileURLToPath } from "url";
|
|
import { dirname, join } from "path";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
test.describe.configure({ mode: "serial" });
|
|
|
|
test.describe("Server Tests", () => {
|
|
let serverProcess: ChildProcess;
|
|
let baseUrl = "http://localhost:3000";
|
|
|
|
test.beforeAll(async () => {
|
|
const serverPath = join(__dirname, "..", "dist", "src", "server.js");
|
|
|
|
serverProcess = spawn("node", [serverPath], {
|
|
stdio: "pipe",
|
|
env: { ...process.env, PORT: "3000" }
|
|
});
|
|
|
|
serverProcess.stdout?.on("data", (_data: Buffer) => {
|
|
});
|
|
|
|
serverProcess.stderr?.on("data", (_data: Buffer) => {
|
|
});
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
|
|
let serverReady = false;
|
|
for (let i = 0; i < 30; i++) {
|
|
try {
|
|
const res = await axios.get(`${baseUrl}/`, { timeout: 2000 });
|
|
if (res.status === 200) {
|
|
serverReady = true;
|
|
break;
|
|
}
|
|
} catch {
|
|
// Ignore errors
|
|
}
|
|
await new Promise((r) => setTimeout(r, 1000));
|
|
}
|
|
|
|
expect(serverReady).toBe(true);
|
|
});
|
|
|
|
test.afterAll(async () => {
|
|
if (serverProcess) {
|
|
serverProcess.kill("SIGTERM");
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
}
|
|
});
|
|
|
|
test("server health endpoint", async () => {
|
|
const res = await axios.get(`${baseUrl}/`);
|
|
expect(res.status).toBe(200);
|
|
expect(res.data.status).toBe("Waku simulation server is running");
|
|
});
|
|
|
|
test("static files are served", async () => {
|
|
const htmlRes = await axios.get(`${baseUrl}/app/index.html`);
|
|
expect(htmlRes.status).toBe(200);
|
|
expect(htmlRes.data).toContain("Waku Test Environment");
|
|
|
|
const jsRes = await axios.get(`${baseUrl}/app/index.js`);
|
|
expect(jsRes.status).toBe(200);
|
|
expect(jsRes.data).toContain("WakuHeadless");
|
|
});
|
|
|
|
test("Waku node auto-started", async () => {
|
|
try {
|
|
const infoRes = await axios.get(`${baseUrl}/waku/v1/peer-info`);
|
|
expect(infoRes.status).toBe(200);
|
|
expect(infoRes.data.peerId).toBeDefined();
|
|
expect(infoRes.data.multiaddrs).toBeDefined();
|
|
} catch (error) {
|
|
expect(error.response?.status).toBe(400);
|
|
}
|
|
});
|
|
});
|