mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-08 00:33:12 +00:00
fix: remove comments and console.logs from tests
This commit is contained in:
parent
3ef6ad237d
commit
ff6287fd3d
@ -25,16 +25,13 @@ let nwakuNodes: ServiceNodesFleet;
|
||||
let baseUrl: string;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
// Create nwaku network using shared utility
|
||||
nwakuNodes = await createTwoNodeNetwork();
|
||||
|
||||
// Get Docker-accessible multiaddr for the lightpush node
|
||||
const lightPushPeerAddr = await getDockerAccessibleMultiaddr(nwakuNodes.nodes[0]);
|
||||
|
||||
// Start browser-tests container with nwaku peer configuration
|
||||
const result = await startBrowserTestsContainer({
|
||||
environment: ENV_BUILDERS.withLocalLightPush(lightPushPeerAddr),
|
||||
networkMode: "waku", // Connect to nwaku network
|
||||
networkMode: "waku",
|
||||
});
|
||||
|
||||
container = result.container;
|
||||
@ -42,7 +39,6 @@ test.beforeAll(async () => {
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
// Clean shutdown using shared utilities (following waku/tests patterns)
|
||||
await Promise.all([
|
||||
stopContainer(container),
|
||||
stopNwakuNodes(nwakuNodes?.nodes || []),
|
||||
@ -55,37 +51,23 @@ test("WakuHeadless can discover nwaku peer and use it for light push", async ()
|
||||
const contentTopic = TEST_CONFIG.DEFAULT_CONTENT_TOPIC;
|
||||
const testMessage = TEST_CONFIG.DEFAULT_TEST_MESSAGE;
|
||||
|
||||
// Wait for WakuHeadless initialization
|
||||
console.log("Waiting for WakuHeadless initialization...");
|
||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.WAKU_INIT_DELAY));
|
||||
|
||||
// Verify server health using shared assertion
|
||||
console.log("Checking server health...");
|
||||
const healthResponse = await axios.get(`${baseUrl}/`, { timeout: 5000 });
|
||||
ASSERTIONS.serverHealth(healthResponse);
|
||||
console.log("✅ Server health check passed");
|
||||
|
||||
// Wait for peers with timeout and error handling
|
||||
console.log("Waiting for peers...");
|
||||
try {
|
||||
await axios.post(`${baseUrl}/waku/v1/wait-for-peers`, {
|
||||
timeoutMs: 10000,
|
||||
protocols: ["lightpush"],
|
||||
}, { timeout: 15000 });
|
||||
console.log("✅ Found lightpush peers");
|
||||
} catch (error) {
|
||||
console.log("⚠️ Wait-for-peers failed or timed out:", error.message);
|
||||
// Continue with test anyway
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
|
||||
// Verify peer info using shared assertion
|
||||
console.log("Getting peer info...");
|
||||
const peerInfoResponse = await axios.get(`${baseUrl}/waku/v1/peer-info`);
|
||||
ASSERTIONS.peerInfo(peerInfoResponse);
|
||||
console.log("✅ WakuHeadless peer ID:", peerInfoResponse.data.peerId);
|
||||
|
||||
// Setup nwaku nodes for message reception
|
||||
console.log("Setting up nwaku nodes for message reception...");
|
||||
const routingInfo = DefaultTestRoutingInfo;
|
||||
|
||||
const subscriptionResults = await Promise.all([
|
||||
@ -95,13 +77,9 @@ test("WakuHeadless can discover nwaku peer and use it for light push", async ()
|
||||
|
||||
expect(subscriptionResults[0]).toBe(true);
|
||||
expect(subscriptionResults[1]).toBe(true);
|
||||
console.log("✅ Subscription setup complete");
|
||||
|
||||
// Wait for subscription establishment
|
||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.SUBSCRIPTION_DELAY));
|
||||
|
||||
// Send message via lightpush
|
||||
console.log("Sending message via lightpush...");
|
||||
const base64Payload = btoa(testMessage);
|
||||
|
||||
const pushResponse = await axios.post(`${baseUrl}/lightpush/v3/message`, {
|
||||
@ -113,36 +91,23 @@ test("WakuHeadless can discover nwaku peer and use it for light push", async ()
|
||||
},
|
||||
});
|
||||
|
||||
// Verify lightpush success using shared assertion
|
||||
ASSERTIONS.lightPushV3Success(pushResponse);
|
||||
console.log("✅ Message sent successfully via lightpush");
|
||||
|
||||
// Wait for message propagation
|
||||
console.log("Waiting for message propagation...");
|
||||
await new Promise((r) => setTimeout(r, TEST_CONFIG.MESSAGE_PROPAGATION_DELAY));
|
||||
|
||||
// Verify message reception on nwaku nodes
|
||||
console.log("Checking message reception on nwaku nodes...");
|
||||
const [node1Messages, node2Messages] = await Promise.all([
|
||||
nwakuNodes.nodes[0].messages(contentTopic),
|
||||
nwakuNodes.nodes[1].messages(contentTopic)
|
||||
]);
|
||||
|
||||
console.log(`Node 1 (lightpush) received ${node1Messages.length} message(s)`);
|
||||
console.log(`Node 2 (relay) received ${node2Messages.length} message(s)`);
|
||||
|
||||
// Verify message propagation
|
||||
const totalMessages = node1Messages.length + node2Messages.length;
|
||||
expect(totalMessages).toBeGreaterThanOrEqual(1);
|
||||
console.log("✅ Message propagated through relay network");
|
||||
|
||||
// Verify message content using shared assertion
|
||||
const receivedMessages = [...node1Messages, ...node2Messages];
|
||||
expect(receivedMessages.length).toBeGreaterThan(0);
|
||||
|
||||
const receivedMessage = receivedMessages[0];
|
||||
ASSERTIONS.messageContent(receivedMessage, testMessage, contentTopic);
|
||||
console.log("✅ Message content verified");
|
||||
|
||||
console.log("🎉 Test passed: WakuHeadless successfully discovered nwaku peer and sent message via light push");
|
||||
});
|
||||
@ -27,18 +27,14 @@ test.beforeAll(async () => {
|
||||
});
|
||||
|
||||
test.afterAll(async () => {
|
||||
// Stop Waku node with retry logic (following waku/tests patterns)
|
||||
if (wakuNode) {
|
||||
console.log("Stopping Waku node...");
|
||||
try {
|
||||
await wakuNode.stop();
|
||||
console.log("Waku node stopped successfully");
|
||||
} catch (error) {
|
||||
console.warn("Waku node stop had issues:", (error as any).message);
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
// Stop container using shared utility
|
||||
await stopContainer(container);
|
||||
});
|
||||
|
||||
@ -75,17 +71,12 @@ test("cross-network message delivery: SDK light node receives server lightpush",
|
||||
const messages: any[] = [];
|
||||
const decoder = wakuNode.createDecoder({ contentTopic });
|
||||
|
||||
try {
|
||||
if (
|
||||
!(await wakuNode.filter.subscribe([decoder], (message) => {
|
||||
messages.push(message);
|
||||
}))
|
||||
) {
|
||||
throw new Error("Failed to subscribe to Filter");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("❌ Failed to subscribe to Filter:", error);
|
||||
throw error;
|
||||
if (
|
||||
!(await wakuNode.filter.subscribe([decoder], (message) => {
|
||||
messages.push(message);
|
||||
}))
|
||||
) {
|
||||
throw new Error("Failed to subscribe to Filter");
|
||||
}
|
||||
|
||||
await new Promise((r) => setTimeout(r, 2000));
|
||||
@ -120,7 +111,6 @@ test("cross-network message delivery: SDK light node receives server lightpush",
|
||||
},
|
||||
});
|
||||
|
||||
// Note: integration test uses different response format than e2e test
|
||||
expect(pushResponse.status).toBe(200);
|
||||
expect(pushResponse.data.success).toBe(true);
|
||||
|
||||
|
||||
@ -15,22 +15,18 @@ test.describe("Server Tests", () => {
|
||||
|
||||
test.beforeAll(async () => {
|
||||
const serverPath = join(__dirname, "..", "dist", "src", "server.js");
|
||||
console.log("Starting server from:", serverPath);
|
||||
|
||||
serverProcess = spawn("node", [serverPath], {
|
||||
stdio: "pipe",
|
||||
env: { ...process.env, PORT: "3000" }
|
||||
});
|
||||
|
||||
serverProcess.stdout?.on("data", (data: Buffer) => {
|
||||
console.log("[Server]", data.toString().trim());
|
||||
serverProcess.stdout?.on("data", (_data: Buffer) => {
|
||||
});
|
||||
|
||||
serverProcess.stderr?.on("data", (data: Buffer) => {
|
||||
console.error("[Server Error]", data.toString().trim());
|
||||
serverProcess.stderr?.on("data", (_data: Buffer) => {
|
||||
});
|
||||
|
||||
console.log("Waiting for server to start...");
|
||||
await new Promise((resolve) => setTimeout(resolve, 3000));
|
||||
|
||||
let serverReady = false;
|
||||
@ -38,14 +34,11 @@ test.describe("Server Tests", () => {
|
||||
try {
|
||||
const res = await axios.get(`${baseUrl}/`, { timeout: 2000 });
|
||||
if (res.status === 200) {
|
||||
console.log(`Server is ready after ${i + 1} attempts`);
|
||||
serverReady = true;
|
||||
break;
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (i % 5 === 0) {
|
||||
console.log(`Attempt ${i + 1}/30 failed:`, error.code || error.message);
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 1000));
|
||||
}
|
||||
@ -55,7 +48,6 @@ test.describe("Server Tests", () => {
|
||||
|
||||
test.afterAll(async () => {
|
||||
if (serverProcess) {
|
||||
console.log("Stopping server...");
|
||||
serverProcess.kill("SIGTERM");
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
@ -84,7 +76,6 @@ test.describe("Server Tests", () => {
|
||||
expect(infoRes.data.peerId).toBeDefined();
|
||||
expect(infoRes.data.multiaddrs).toBeDefined();
|
||||
} catch (error: any) {
|
||||
console.log("Waku node test failed (expected if browser not initialized):", error.response?.data?.error || error.message);
|
||||
expect(error.response?.status).toBe(400);
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user