diff --git a/app/entry.client.tsx b/app/entry.client.tsx index 07cdbdb..3d3d630 100644 --- a/app/entry.client.tsx +++ b/app/entry.client.tsx @@ -9,7 +9,7 @@ import { startTransition, StrictMode } from "react"; import { hydrateRoot } from "react-dom/client"; async function prepareApp() { - if (ENV.MOCKS) { + if (process.env.NODE_ENV !== "production" && process.env.MOCKS === "true") { const { worker } = await import("../tests/mocks/browser"); return worker.start(); } diff --git a/app/entry.server.tsx b/app/entry.server.tsx index 4f0e49d..8a43a85 100644 --- a/app/entry.server.tsx +++ b/app/entry.server.tsx @@ -10,7 +10,6 @@ import { RemixServer } from "@remix-run/react"; import isbot from "isbot"; import { PassThrough } from "node:stream"; import { renderToPipeableStream } from "react-dom/server"; -import { server } from "../tests/mocks/node"; import { getEnv, init } from "./utils/env.server"; // Initialize typesafe environment variables and global ENV object. @@ -18,10 +17,12 @@ init(); global.ENV = getEnv(); // Enable API mocking. -if (ENV.MOCKS) { +if (process.env.NODE_ENV !== "production" && process.env.MOCKS === "true") { + const { server } = await import("../tests/mocks/node"); server.listen(); console.info("[MSW] Mocking enabled."); - if (ENV.MODE === "development") { + if (process.env.NODE_ENV === "development") { + // Only log mocked requests in development mode. server.events.on("request:start", ({ request }) => { console.info(request.method, "[MSW]", request.url); });