Skip to content

Commit

Permalink
fix access to process variable (#2201)
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko authored Jan 16, 2025
1 parent ef78e52 commit b5d2c01
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/sdk/src/create/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
import { derivePubsubTopicsFromNetworkConfig, Logger } from "@waku/utils";
import { createLibp2p } from "libp2p";

import { isTestEnvironment } from "../env.js";
import {
CreateWakuNodeOptions,
DefaultPingMaxInboundStreams,
Expand All @@ -36,7 +37,7 @@ export async function defaultLibp2p(
options?: Partial<CreateLibp2pOptions>,
userAgent?: string
): Promise<Libp2p> {
if (!options?.hideWebSocketInfo && process?.env?.NODE_ENV !== "test") {
if (!options?.hideWebSocketInfo && !isTestEnvironment()) {
/* eslint-disable no-console */
console.info(
"%cIgnore WebSocket connection failures",
Expand All @@ -54,7 +55,7 @@ export async function defaultLibp2p(
: {};

const filter =
options?.filterMultiaddrs === false || process?.env?.NODE_ENV === "test"
options?.filterMultiaddrs === false || isTestEnvironment()
? filterAll
: wss;

Expand Down
8 changes: 8 additions & 0 deletions packages/sdk/src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export function isTestEnvironment(): boolean {
try {
return process?.env?.NODE_ENV === "test";
} catch (_e) {
// process variable is not defined in PROD environment
return false;
}
}

0 comments on commit b5d2c01

Please sign in to comment.