From 65e33a89a49ff801df9ecf7e95ecae76685e66e4 Mon Sep 17 00:00:00 2001 From: Nate Date: Sat, 19 Jul 2025 19:18:58 -0700 Subject: [PATCH] attempt to fix tests on windows --- src/test-helpers/cli-helpers.ts | 52 +++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/src/test-helpers/cli-helpers.ts b/src/test-helpers/cli-helpers.ts index 3b9a9d3d3..4a6261cc4 100644 --- a/src/test-helpers/cli-helpers.ts +++ b/src/test-helpers/cli-helpers.ts @@ -84,25 +84,67 @@ export async function runCLI( timeout, reject: false, input, + // Force Windows to use the correct stdout/stderr handling + windowsVerbatimArguments: true, + // Ensure proper encoding + encoding: 'utf8' as const, + // Increase buffer size for Windows + maxBuffer: 10 * 1024 * 1024, // 10MB }; try { const result = await execaNode(context.cliPath, args, execOptions); + // Ensure stdout/stderr are always strings + const stdout = result.stdout ?? ""; + const stderr = result.stderr ?? ""; + + // Log for debugging Windows issues + if (process.env.DEBUG_CLI_TESTS) { + console.log("CLI Result:", { + stdout: stdout.substring(0, 200), + stderr: stderr.substring(0, 200), + exitCode: result.exitCode, + }); + } + return { - stdout: result.stdout, - stderr: result.stderr, + stdout, + stderr, exitCode: result.exitCode ?? 0, }; } catch (error: any) { + // Always capture stdout/stderr even on error + const stdout = error.stdout ?? ""; + const stderr = error.stderr ?? ""; + const exitCode = error.exitCode ?? 1; + if (!expectError) { + // Include more details in error for debugging + const errorDetails = { + message: error.message, + stdout: stdout.substring(0, 500), + stderr: stderr.substring(0, 500), + exitCode, + command: error.command, + cwd: execOptions.cwd, + cliPath: context.cliPath, + args, + }; + console.error("CLI execution failed:", errorDetails); + + // On Windows, if we get empty output, it might be a Node.js path issue + if (process.platform === "win32" && !stdout && !stderr) { + console.error("Windows: No output captured. This might be a Node.js execution issue."); + } + throw error; } return { - stdout: error.stdout || "", - stderr: error.stderr || "", - exitCode: error.exitCode ?? 1, + stdout, + stderr, + exitCode, error, }; }