Skip to content

Commit 1dbee0d

Browse files
test(init): use try/finally for process.stdout.columns cleanup
Ensures terminal width is restored even if test assertions fail.
1 parent 2b72e63 commit 1dbee0d

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

test/lib/init/wizard-runner.test.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -562,20 +562,23 @@ describe("runWizard", () => {
562562
};
563563
mockResumeResults = [{ status: "success" }];
564564

565-
await runWizard(makeOptions());
566-
567-
Object.defineProperty(process.stdout, "columns", {
568-
value: origColumns,
569-
configurable: true,
570-
});
571-
572-
// 40 columns - 4 reserved = 36 max, truncated with "…"
573-
const call = spinnerMock.message.mock.calls.find((c: string[]) =>
574-
c[0]?.includes("npm install")
575-
);
576-
expect(call).toBeDefined();
577-
expect(call[0].length).toBeLessThanOrEqual(36);
578-
expect(call[0].endsWith("…")).toBe(true);
565+
try {
566+
await runWizard(makeOptions());
567+
568+
// 40 columns - 4 reserved = 36 max, truncated with "…"
569+
const call = spinnerMock.message.mock.calls.find((c: string[]) =>
570+
c[0]?.includes("npm install")
571+
) as string[] | undefined;
572+
expect(call).toBeDefined();
573+
const msg = call?.[0] ?? "";
574+
expect(msg.length).toBeLessThanOrEqual(36);
575+
expect(msg.endsWith("…")).toBe(true);
576+
} finally {
577+
Object.defineProperty(process.stdout, "columns", {
578+
value: origColumns,
579+
configurable: true,
580+
});
581+
}
579582
});
580583

581584
test("dispatches interactive payload to handleInteractive", async () => {

0 commit comments

Comments
 (0)