|
1 | | -import { describe, expect, test } from "bun:test"; |
| 1 | +import { afterEach, describe, expect, test } from "bun:test"; |
2 | 2 |
|
3 | | -import { createHarness, type Harness } from "./harness.js"; |
| 3 | +import { createHarness as createRawHarness, type Harness } from "./harness.js"; |
4 | 4 | import { |
5 | 5 | addProviderSelectorChoices, |
6 | 6 | connectedAccountCount, |
@@ -41,6 +41,20 @@ const EMPTY: ProviderFormValues = { |
41 | 41 | oauthProfile: "", |
42 | 42 | }; |
43 | 43 |
|
| 44 | +// This file mounts a fresh renderer per test; track every one so a single |
| 45 | +// afterEach can free them regardless of which assertion in a test fails. |
| 46 | +const activeHarnesses: Harness[] = []; |
| 47 | + |
| 48 | +async function createHarness(opts: { width: number; height: number }): Promise<Harness> { |
| 49 | + const harness = await createRawHarness(opts); |
| 50 | + activeHarnesses.push(harness); |
| 51 | + return harness; |
| 52 | +} |
| 53 | + |
| 54 | +afterEach(() => { |
| 55 | + while (activeHarnesses.length > 0) activeHarnesses.pop()!.destroy(); |
| 56 | +}); |
| 57 | + |
44 | 58 | describe("provider setup pure helpers", () => { |
45 | 59 | test("only the API key may be left blank", () => { |
46 | 60 | expect(stepReady("name", "")).toBe(false); |
@@ -1047,23 +1061,19 @@ describe("runProviderSetup paste", () => { |
1047 | 1061 | const { done, harness } = await mountSetup(async (values) => { |
1048 | 1062 | seen = values; |
1049 | 1063 | }); |
1050 | | - try { |
1051 | | - await pickRow(harness, PROVIDER_IDS, "openai"); |
1052 | | - await flush(harness); |
1053 | | - harness.pressKey("Enter"); |
1054 | | - await harness.renderOnce(); |
1055 | | - await harness.mockInput.pasteBracketedText(key); |
1056 | | - await harness.renderOnce(); |
1057 | | - const frame = harness.captureCharFrame(); |
1058 | | - harness.pressKey("Enter"); |
1059 | | - await harness.renderOnce(); |
1060 | | - harness.pressKey("Enter"); |
1061 | | - await harness.renderOnce(); |
1062 | | - await done; |
1063 | | - return { values: seen, frame }; |
1064 | | - } finally { |
1065 | | - harness.destroy(); |
1066 | | - } |
| 1064 | + await pickRow(harness, PROVIDER_IDS, "openai"); |
| 1065 | + await flush(harness); |
| 1066 | + harness.pressKey("Enter"); |
| 1067 | + await harness.renderOnce(); |
| 1068 | + await harness.mockInput.pasteBracketedText(key); |
| 1069 | + await harness.renderOnce(); |
| 1070 | + const frame = harness.captureCharFrame(); |
| 1071 | + harness.pressKey("Enter"); |
| 1072 | + await harness.renderOnce(); |
| 1073 | + harness.pressKey("Enter"); |
| 1074 | + await harness.renderOnce(); |
| 1075 | + await done; |
| 1076 | + return { values: seen, frame }; |
1067 | 1077 | } |
1068 | 1078 |
|
1069 | 1079 | test("a pasted key lands in the field, never echoed in the clear", async () => { |
|
0 commit comments