Skip to content

Commit f1169c0

Browse files
committed
fix(tests): omit env option when no custom env vars provided
The spawn function might be spreading or manipulating the env parameter internally. By not passing the env option at all when no custom environment variables are needed, we allow the spawn function to use process.env directly, preserving Windows proxy behavior. Only pass env when spawnEnv is provided for custom environment variables.
1 parent 14bb554 commit f1169c0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

packages/cli/test/utils.mts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,22 @@ export async function spawnSocketCli(
266266
const commandArgs = isJsFile ? [entryPath, ...args] : args
267267

268268
try {
269-
// Build env without spreading process.env to preserve Windows proxy behavior.
269+
// Build options conditionally to avoid passing env when not needed.
270+
// This preserves Windows process.env proxy behavior.
270271
// Spreading process.env breaks case-insensitive env var access on Windows.
271-
const env = spawnEnv ? { ...constants.processEnv, ...spawnEnv } : constants.processEnv
272-
273-
const output = await spawn(command, commandArgs, {
272+
const spawnOptions = {
274273
cwd,
275-
env,
276274
...restOptions,
277275
// Close stdin to prevent tests from hanging
278276
// when commands wait for input. Must be after restOptions
279277
// to ensure it's not overridden.
280278
stdio: restOptions.stdio ?? ['ignore', 'pipe', 'pipe'],
281-
})
279+
// Only add env if custom environment variables are provided.
280+
// This avoids breaking Windows process.env proxy behavior.
281+
...(spawnEnv ? { env: { ...constants.processEnv, ...spawnEnv } } : {}),
282+
}
283+
284+
const output = await spawn(command, commandArgs, spawnOptions)
282285
return {
283286
status: true,
284287
code: 0,

0 commit comments

Comments
 (0)