Skip to content

Commit 9e9db0a

Browse files
committed
feat: add createIsolatedTerminal() test helper
Created a reusable test helper that ensures complete test isolation by creating a fresh Ghostty WASM instance for each terminal. Benefits: - Single pattern for all tests: await createIsolatedTerminal() - No manual Ghostty instance management in test files - Clean slate guarantee - each test has isolated WASM memory - Parallel-ready - no shared state between tests - Simpler test code - just one function call Updated all test files: - lib/test-helpers.ts: New helper function - lib/buffer.test.ts: Uses createIsolatedTerminal() - lib/terminal.test.ts: Uses createIsolatedTerminal() - lib/scrolling.test.ts: Uses createIsolatedTerminal() - lib/selection-manager.test.ts: Uses createIsolatedTerminal() - lib/input-handler.test.ts: Uses fresh Ghostty per test All 283 tests pass with complete isolation.
1 parent e30cce7 commit 9e9db0a

6 files changed

Lines changed: 280 additions & 255 deletions

File tree

lib/buffer.test.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,23 @@
22
* Buffer API tests
33
*
44
* Test Isolation Pattern:
5-
* Each test creates its own Ghostty WASM instance to ensure complete isolation.
6-
* This allows tests to run in parallel without shared state, and ensures a
7-
* clean slate for each test without worrying about previous test side effects.
5+
* Uses createIsolatedTerminal() to ensure each test gets its own WASM instance.
86
*/
97

108
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
11-
import { Ghostty } from './ghostty';
12-
import { Terminal } from './terminal';
9+
import type { Terminal } from './terminal';
10+
import { createIsolatedTerminal } from './test-helpers';
1311

1412
describe('Buffer API', () => {
1513
let term: Terminal | null = null;
1614
let container: HTMLElement | null = null;
17-
let ghostty: Ghostty | null = null;
1815

1916
beforeEach(async () => {
20-
// Create a fresh Ghostty WASM instance for complete test isolation.
21-
// This ensures no shared state between tests and allows parallel execution.
22-
ghostty = await Ghostty.load();
23-
2417
// Create a container element if document is available
2518
if (typeof document !== 'undefined') {
2619
container = document.createElement('div');
2720
document.body.appendChild(container);
28-
term = new Terminal({ cols: 80, rows: 24, ghostty });
21+
term = await createIsolatedTerminal({ cols: 80, rows: 24 });
2922
term.open(container);
3023
}
3124
});

lib/input-handler.test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Unit tests for InputHandler
33
*/
44

5-
import { beforeAll, beforeEach, describe, expect, mock, test } from 'bun:test';
5+
import { beforeEach, describe, expect, mock, test } from 'bun:test';
66
import { Ghostty } from './ghostty';
77
import { InputHandler } from './input-handler';
88
import { Key, KeyAction, Mods } from './types';
@@ -127,13 +127,10 @@ describe('InputHandler', () => {
127127
let dataReceived: string[];
128128
let bellCalled: boolean;
129129

130-
beforeAll(async () => {
131-
// Load WASM once for all tests (expensive operation)
132-
// wasmPath is now optional - auto-detected
130+
beforeEach(async () => {
131+
// Create a fresh Ghostty WASM instance for complete test isolation
133132
ghostty = await Ghostty.load();
134-
});
135133

136-
beforeEach(() => {
137134
// Create mock container for each test
138135
container = createMockContainer();
139136

0 commit comments

Comments
 (0)