MCPcopy
hub / github.com/promptfoo/promptfoo / mockProcessEnv

Function mockProcessEnv

test/util/utils.ts:95–116  ·  view source on GitHub ↗
(
  overrides: Record<string, string | undefined> = {},
  options: { clear?: boolean } = {},
)

Source from the content-addressed store, hash-verified

93}
94
95export function mockProcessEnv(
96 overrides: Record<string, string | undefined> = {},
97 options: { clear?: boolean } = {},
98): () => void {
99 const originalEnv = { ...process.env };
100
101 if (options.clear) {
102 replaceProcessEnv({});
103 }
104
105 for (const [key, value] of Object.entries(overrides)) {
106 if (value === undefined) {
107 Reflect.deleteProperty(process.env, key);
108 } else {
109 Object.assign(process.env, { [key]: value });
110 }
111 }
112
113 return () => {
114 replaceProcessEnv(originalEnv);
115 };
116}
117
118export const PROXY_ENV_KEYS = [
119 'HTTP_PROXY',

Callers 15

vitest.setup.tsFile · 0.90
mockFetchTestEnvFunction · 0.90
fetch.test.tsFile · 0.90
setupTelemetryEnvFunction · 0.90
restoreTelemetryEnvFunction · 0.90
telemetry.test.tsFile · 0.90
envars.test.tsFile · 0.90
updates.test.tsFile · 0.90
constants.test.tsFile · 0.90

Calls 1

replaceProcessEnvFunction · 0.85

Tested by 10

mockFetchTestEnvFunction · 0.72
setupTelemetryEnvFunction · 0.72
restoreTelemetryEnvFunction · 0.72
restoreTraceFetchEnvFunction · 0.72
restoreEnvVarFunction · 0.72
mockAbliterationEnvFunction · 0.72
clearBedrockEnvFunction · 0.72
setTestEnvFunction · 0.72
restoreTestEnvFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…