chore: supress websocket warning in tests (#1797)

This commit is contained in:
Sasha 2024-01-17 15:37:09 +01:00 committed by GitHub
parent 00bd51a42e
commit 7a8ef875dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 7 deletions

View File

@ -212,8 +212,7 @@ export async function defaultLibp2p(
options?: Partial<CreateLibp2pOptions>,
userAgent?: string
): Promise<Libp2p> {
// 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",

View File

@ -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 () => {
[
["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: true }
libp2p: { hideWebSocketInfo: !!hideWebSocketInfo }
});
expect(consoleInfoSpy.callCount).to.be.equal(0);
});
});
});