diff --git a/src/e2e.test.ts b/src/e2e.test.ts index e8c41612c..f185b4238 100644 --- a/src/e2e.test.ts +++ b/src/e2e.test.ts @@ -43,7 +43,16 @@ describe("CLI E2E Tests", () => { describe("invalid commands", () => { it("should show error for unknown command", async () => { try { - await $(["unknown-command"]); + // Add explicit timeout for Windows CI + const result = await execaNode( + path.resolve("dist/index.js"), + ["unknown-command"], + { + timeout: 5000, // 5 second timeout instead of default 10 + reject: true, + windowsHide: true, // Prevent console window on Windows + } + ); fail("Should have thrown an error"); } catch (error: any) { expect(error.exitCode).not.toBe(0); @@ -51,11 +60,20 @@ describe("CLI E2E Tests", () => { const errorOutput = error.message || error.stderr || error.stdout || ""; expect(errorOutput.length).toBeGreaterThan(0); } - }); + }, 8000); // Increase test timeout to 8 seconds it("should show help on invalid flag", async () => { try { - await $(["--invalid-flag"]); + // Add explicit timeout for Windows CI + const result = await execaNode( + path.resolve("dist/index.js"), + ["--invalid-flag"], + { + timeout: 5000, // 5 second timeout instead of default 10 + reject: true, + windowsHide: true, // Prevent console window on Windows + } + ); fail("Should have thrown an error"); } catch (error: any) { expect(error.exitCode).not.toBe(0); @@ -63,6 +81,6 @@ describe("CLI E2E Tests", () => { const errorOutput = error.message || error.stderr || error.stdout || ""; expect(errorOutput.length).toBeGreaterThan(0); } - }); + }, 8000); // Increase test timeout to 8 seconds }); }); diff --git a/src/index.ts b/src/index.ts index f5a7eec13..206b92866 100644 --- a/src/index.ts +++ b/src/index.ts @@ -64,4 +64,17 @@ program await logout(); }); -program.parse(); +// Handle unknown commands +program.on("command:*", () => { + console.error(`Error: Unknown command '${program.args.join(" ")}'\n`); + program.outputHelp(); + process.exit(1); +}); + +// Parse arguments and handle errors +try { + program.parse(); +} catch (error) { + console.error(error); + process.exit(1); +}