Skip to content

Commit dda0b24

Browse files
committed
fix(isenabled): add isEnabled
1 parent af5a157 commit dda0b24

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/client/batch-mock-collector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
type BatchMockResponseMessage,
77
type MockRequestDescriptor,
88
} from "../types.js";
9+
import { isEnabled } from "./util.js";
910

1011
type Logger = Pick<Console, "log" | "warn" | "error"> & {
1112
debug?: (...args: unknown[]) => void;
@@ -171,6 +172,9 @@ export class BatchMockCollector {
171172
* created after this method is called are not included.
172173
*/
173174
async waitForPendingRequests(): Promise<void> {
175+
if (!isEnabled()) {
176+
return;
177+
}
174178
const pendingCompletions = Array.from(this.pendingRequests.values()).map(
175179
(pending) => pending.completion
176180
);

src/client/connect.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BatchMockCollector } from "./batch-mock-collector.js";
22
import type { BatchMockCollectorOptions } from "./batch-mock-collector.js";
3+
import { isEnabled } from "./util.js";
34

45
export type ConnectOptions = number | BatchMockCollectorOptions | undefined;
56

@@ -10,10 +11,7 @@ export type ConnectOptions = number | BatchMockCollectorOptions | undefined;
1011
export const connect = async (
1112
options?: ConnectOptions
1213
): Promise<BatchMockCollector | void> => {
13-
const isEnabled =
14-
process.env.MOCK_MCP !== undefined && process.env.MOCK_MCP !== "0";
15-
16-
if (!isEnabled) {
14+
if (!isEnabled()) {
1715
console.log("[mock-mcp] Skipping (set MOCK_MCP=1 to enable)");
1816
return;
1917
}

src/client/util.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const isEnabled = () => {
2+
return process.env.MOCK_MCP !== undefined && process.env.MOCK_MCP !== "0";
3+
};

0 commit comments

Comments
 (0)