Skip to content

Commit f03dfbb

Browse files
authored
Merge pull request #5407 from Tyriar/tyriar/bd09_copilot_instructions
Improve Copilot instructions and add test guidelines
2 parents ab43a3b + 5b4b93a commit f03dfbb

File tree

2 files changed

+81
-31
lines changed

2 files changed

+81
-31
lines changed

.github/copilot-instructions.md

Lines changed: 73 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,90 @@
1-
This is a TypeScript-based repository with a Ruby client for certain API endpoints. It includes several sub projects called addons which are built separately. It contains a demo application which showcases the functionality of the project.
1+
# xterm.js Copilot Instructions
22

3-
Please follow these guidelines when contributing:
3+
## Architecture Overview
44

5-
## Development Flow
5+
**Core Structure**: xterm.js is a multi-target terminal emulator with three main distributions:
6+
- `src/browser/`: Full-featured browser terminal with DOM rendering
7+
- `src/headless/`: Server-side terminal for Node.js (no DOM)
8+
- `src/common/`: Shared core logic (parsing, buffer management, terminal state)
69

7-
- Install dependencies: `npm install && npm run setup`
8-
- Build and bundle demo: `npm run build && npm run esbuild`
10+
**Key Classes**:
11+
- `Terminal` (browser/headless): Public API wrapper
12+
- `CoreTerminal` (common): Core terminal logic and state
13+
- `CoreBrowserTerminal` (browser): Browser-specific terminal implementation
914

10-
## Unit tests
15+
## Development Workflow
1116

12-
Unit tests are run with `yarn test-unit`:
17+
**Build System**:
18+
```bash
19+
npm run build && npm run esbuild # Build all TypeScript and bundle
20+
```
21+
22+
**Testing**:
23+
- Unit tests: `npm run test-unit` (Mocha)
24+
- Per-addon unit tests: `npm run test-unit addons/addon-image/out-esbuild/*.test.js`
25+
- Integration tests: `npm run test-integration` (Playwright across Chrome/Firefox/WebKit)
26+
- Per-addon integration tests: `npm run test-integration --suite=addon-search`
27+
28+
## Addon Development Pattern
29+
30+
All addons follow this structure:
31+
```typescript
32+
export class MyAddon implements ITerminalAddon {
33+
activate(terminal: Terminal): void {
34+
// Called when loaded via terminal.loadAddon()
35+
// Register handlers, access terminal APIs
36+
}
37+
dispose(): void {
38+
// Cleanup when addon is disposed
39+
}
40+
}
41+
```
1342

14-
```sh
15-
# All unit tests
16-
yarn test-unit
43+
**Key Examples**:
44+
- `addons/addon-fit/`: Terminal sizing
45+
- `addons/addon-webgl/`: GPU-accelerated rendering
46+
- `addons/addon-search/`: Text search functionality
1747

18-
# Absolute file path
19-
yarn test-unit out-esbuild/browser/Terminal.test.js
48+
## Project-Specific Conventions
2049

21-
# Filter by wildcard
22-
yarn test-unit out-esbuild/**/Terminal.test.js
50+
**TypeScript Project Structure**: Uses TypeScript project references (`tsconfig.all.json`) for incremental builds across browser/headless/addons.
2351

24-
# Specific addon unit tests tests
25-
yarn test-unit addons/addon-image/out-esbuild/*.test.js
52+
**API Design**:
53+
- Browser and headless terminals share the same public API
54+
- Proposed APIs require `allowProposedApi: true` option
55+
- Constructor-only options (cols, rows) cannot be changed after instantiation
2656

27-
# Multiple files
28-
yarn test-unit out-esbuild/**/Terminal.test.js out-esbuild/**/InputHandler.test.js
29-
```
57+
**Testing Utilities**: Use `TestUtils.ts` helpers:
58+
- `openTerminal(ctx, options)` for setup
59+
- `pollFor(page, fn, expectedValue)` for async assertions
60+
- `writeSync(page, data)` for terminal input
3061

31-
These use mocha to run all `.test.js` files within the esbuild output (`out-esbuild/`).
62+
## Common Patterns
3263

33-
## Integration tests
64+
**Parser Integration**: Register custom escape sequence handlers:
65+
```typescript
66+
terminal.parser.registerCsiHandler('m', params => {
67+
// Handle SGR sequences
68+
return true; // Handled
69+
});
70+
```
71+
72+
**Buffer Access**: Read terminal content via buffer API:
73+
```typescript
74+
const line = terminal.buffer.active.getLine(0);
75+
const cell = line?.getCell(0);
76+
```
3477

35-
Integration tests are run with `yarn test-integration`:
78+
**Events**: All terminals emit standard events (onData, onResize, onRender) plus platform-specific ones.
3679

37-
```sh
38-
# All integration tests
39-
yarn test-integration
80+
## Critical Implementation Details
4081

41-
# Core integration tests
42-
yarn test-integration --suite=core
82+
- Terminal rendering uses either DOM or WebGL renderers
83+
- Buffer lines are immutable; create new instances for modifications
84+
- Character width handling supports Unicode 11+ and grapheme clustering
85+
- Mouse events translate web events to terminal protocols (X10, VT200, etc.)
86+
- Color theming supports both palette and true color modes
4387

44-
# Specific addon integration tests
45-
yarn test-integration --suite=addon-search
46-
```
88+
## Writing unit tests
4789

48-
These use `@playwright/test` to run all tests within the esbuild test output (`out-esbuild-test/`).
90+
- Unit tests live alongside the source code file of the thing it's testing with a .test.ts suffix.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
applyTo: '**/*.test.ts'
3+
---
4+
When writing unit tests follow these rules:
5+
6+
- When writing unit tests for addons, always create a real xterm.js instance instead of mocking it.
7+
- Prefer `assert.ok` over `assert.notStrictEqual` when checking something is undefined or not.
8+
- Avoid comments as most tests should be self-documenting.

0 commit comments

Comments
 (0)