From 7a8ef875ddc7f1014e80f2a6e97b4c86f1bd5802 Mon Sep 17 00:00:00 2001 From: Sasha <118575614+weboko@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:37:09 +0100 Subject: [PATCH] chore: supress websocket warning in tests (#1797) --- packages/sdk/src/create.ts | 3 +-- packages/tests/tests/create.optional.spec.ts | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/packages/sdk/src/create.ts b/packages/sdk/src/create.ts index 4265fb6f4b..a383388d60 100644 --- a/packages/sdk/src/create.ts +++ b/packages/sdk/src/create.ts @@ -212,8 +212,7 @@ export async function defaultLibp2p( options?: Partial, userAgent?: string ): Promise { - // Log the info log unless we are running tests or the user has disabled it - if (!options?.hideWebSocketInfo || process.env.NODE_ENV !== "test") { + if (!options?.hideWebSocketInfo && process.env.NODE_ENV !== "test") { /* eslint-disable no-console */ console.info( "%cIgnore WebSocket connection failures", diff --git a/packages/tests/tests/create.optional.spec.ts b/packages/tests/tests/create.optional.spec.ts index a09a01d16b..d098487a52 100644 --- a/packages/tests/tests/create.optional.spec.ts +++ b/packages/tests/tests/create.optional.spec.ts @@ -14,18 +14,27 @@ describe("Create node", () => { afterEach(async () => { consoleInfoSpy.restore(); + sinon.restore(); await tearDownNodes([], waku); }); - it("should log info about WebSocket failures to console when hideWebSocketInfo disabled", async () => { + it("should log info about WebSocket failures to console when hideWebSocketInfo disabled and NODE_ENV is not test", async () => { + sinon.stub(process.env, "NODE_ENV").value("undefined"); waku = await createLightNode(); expect(consoleInfoSpy.callCount).to.be.equal(2); }); - it("should not log info about WebSocket failures to console when hideWebSocketInfo enabled", async () => { - waku = await createLightNode({ - libp2p: { hideWebSocketInfo: true } + [ + ["test", false], + ["test", true], + [undefined, true] + ].map(([env, hideWebSocketInfo]) => { + it(`should not log info about WebSocket failures to console when NODE_ENV=${env} and hideWebSocketInfo=${hideWebSocketInfo}`, async () => { + sinon.stub(process.env, "NODE_ENV").value(env); + waku = await createLightNode({ + libp2p: { hideWebSocketInfo: !!hideWebSocketInfo } + }); + expect(consoleInfoSpy.callCount).to.be.equal(0); }); - expect(consoleInfoSpy.callCount).to.be.equal(0); }); });