Skip to content

Commit 329eae2

Browse files
authored
chore: fix tests (#44)
1 parent 7718d37 commit 329eae2

File tree

9 files changed

+173
-204
lines changed

9 files changed

+173
-204
lines changed

bun.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"name": "@cmux/ghostty-terminal",
66
"devDependencies": {
77
"@biomejs/biome": "^1.9.4",
8+
"@happy-dom/global-registrator": "^15.11.0",
89
"@types/bun": "^1.3.2",
9-
"happy-dom": "^20.0.10",
1010
"prettier": "^3.6.2",
1111
"typescript": "^5.9.3",
1212
"vite": "^4.5.0",
@@ -85,6 +85,8 @@
8585

8686
"@esbuild/win32-x64": ["@esbuild/win32-x64@0.18.20", "", { "os": "win32", "cpu": "x64" }, "sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ=="],
8787

88+
"@happy-dom/global-registrator": ["@happy-dom/global-registrator@15.11.7", "", { "dependencies": { "happy-dom": "^15.11.7" } }, "sha512-mfOoUlIw8VBiJYPrl5RZfMzkXC/z7gbSpi2ecycrj/gRWLq2CMV+Q+0G+JPjeOmuNFgg0skEIzkVFzVYFP6URw=="],
89+
8890
"@isaacs/balanced-match": ["@isaacs/balanced-match@4.0.1", "", {}, "sha512-yzMTt9lEb8Gv7zRioUilSglI0c0smZ9k5D65677DLWLtWJaXIS3CqcGyUFByYKlnUj6TkjLVs54fBl6+TiGQDQ=="],
8991

9092
"@isaacs/brace-expansion": ["@isaacs/brace-expansion@5.0.0", "", { "dependencies": { "@isaacs/balanced-match": "^4.0.1" } }, "sha512-ZT55BDLV0yv0RBm2czMiZ+SqCGO7AvmOM3G/w2xhVPH+te0aKgFjmBvGlL1dH+ql2tgGO3MVrbb3jCKyvpgnxA=="],
@@ -121,8 +123,6 @@
121123

122124
"@types/react": ["@types/react@19.2.2", "", { "dependencies": { "csstype": "^3.0.2" } }, "sha512-6mDvHUFSjyT2B2yeNx2nUgMxh9LtOWvkhIU3uePn2I2oyNymUAX1NIsdgviM4CH+JSrp2D2hsMvJOkxY+0wNRA=="],
123125

124-
"@types/whatwg-mimetype": ["@types/whatwg-mimetype@3.0.2", "", {}, "sha512-c2AKvDT8ToxLIOUlN51gTiHXflsfIFisS4pO7pDPoKouJCESkhZnEy623gwP9laCy5lnLDAw1vAzu2vM2YLOrA=="],
125-
126126
"@volar/language-core": ["@volar/language-core@2.4.23", "", { "dependencies": { "@volar/source-map": "2.4.23" } }, "sha512-hEEd5ET/oSmBC6pi1j6NaNYRWoAiDhINbT8rmwtINugR39loROSlufGdYMF9TaKGfz+ViGs1Idi3mAhnuPcoGQ=="],
127127

128128
"@volar/source-map": ["@volar/source-map@2.4.23", "", {}, "sha512-Z1Uc8IB57Lm6k7q6KIDu/p+JWtf3xsXJqAX/5r18hYOTpJyBn0KXUR8oTJ4WFYOcDzWC9n3IflGgHowx6U6z9Q=="],
@@ -187,7 +187,7 @@
187187

188188
"graceful-fs": ["graceful-fs@4.2.11", "", {}, "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="],
189189

190-
"happy-dom": ["happy-dom@20.0.10", "", { "dependencies": { "@types/node": "^20.0.0", "@types/whatwg-mimetype": "^3.0.2", "whatwg-mimetype": "^3.0.0" } }, "sha512-6umCCHcjQrhP5oXhrHQQvLB0bwb1UzHAHdsXy+FjtKoYjUhmNZsQL8NivwM1vDvNEChJabVrUYxUnp/ZdYmy2g=="],
190+
"happy-dom": ["happy-dom@15.11.7", "", { "dependencies": { "entities": "^4.5.0", "webidl-conversions": "^7.0.0", "whatwg-mimetype": "^3.0.0" } }, "sha512-KyrFvnl+J9US63TEzwoiJOQzZBJY7KgBushJA8X61DMbNsH+2ONkDuLDnCnwUiPTF42tLoEmrPyoqbenVA5zrg=="],
191191

192192
"has-flag": ["has-flag@4.0.0", "", {}, "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="],
193193

@@ -283,6 +283,8 @@
283283

284284
"vscode-uri": ["vscode-uri@3.1.0", "", {}, "sha512-/BpdSx+yCQGnCvecbyXdxHDkuk55/G3xwnC0GqY4gmQ3j+A+g8kzzgB4Nk/SINjqn6+waqw3EgbVF2QKExkRxQ=="],
285285

286+
"webidl-conversions": ["webidl-conversions@7.0.0", "", {}, "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g=="],
287+
286288
"whatwg-mimetype": ["whatwg-mimetype@3.0.0", "", {}, "sha512-nt+N2dzIutVRxARx1nghPKGv1xHikU7HKdfafKkLNLindmPU/ch3U31NOCGGA/dmPcmb1VlofO0vnKAcsm0o/Q=="],
287289

288290
"yallist": ["yallist@4.0.0", "", {}, "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="],

bunfig.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Bun Configuration
2+
# https://bun.sh/docs/runtime/bunfig
3+
4+
[test]
5+
# Preload Happy DOM before running tests to provide browser-like globals
6+
# (window, document, HTMLElement, etc.)
7+
preload = "./happydom.ts"

happydom.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* Happy DOM Setup for Tests
3+
*
4+
* This file is preloaded by Bun before running tests (configured in bunfig.toml).
5+
* It registers Happy DOM's global objects (window, document, HTMLElement, etc.)
6+
* so that tests requiring DOM APIs can run successfully.
7+
*
8+
* @see bunfig.toml - test.preload configuration
9+
* @see https://bun.sh/docs/test/dom
10+
*/
11+
12+
import { GlobalRegistrator } from '@happy-dom/global-registrator';
13+
14+
// Register Happy DOM globals (window, document, etc.)
15+
GlobalRegistrator.register();
16+
17+
// Mock Canvas 2D Context
18+
// Happy DOM doesn't provide canvas rendering APIs, so we mock them for testing.
19+
// This provides enough functionality for terminal tests to run without actual rendering.
20+
const originalGetContext = HTMLCanvasElement.prototype.getContext;
21+
HTMLCanvasElement.prototype.getContext = function (contextType: string, options?: any) {
22+
if (contextType === '2d') {
23+
// Return a minimal mock of CanvasRenderingContext2D
24+
return {
25+
canvas: this,
26+
fillStyle: '#000000',
27+
strokeStyle: '#000000',
28+
font: '12px monospace',
29+
textAlign: 'start',
30+
textBaseline: 'alphabetic',
31+
globalAlpha: 1,
32+
globalCompositeOperation: 'source-over',
33+
imageSmoothingEnabled: true,
34+
lineWidth: 1,
35+
lineCap: 'butt',
36+
lineJoin: 'miter',
37+
miterLimit: 10,
38+
shadowBlur: 0,
39+
shadowColor: 'rgba(0, 0, 0, 0)',
40+
shadowOffsetX: 0,
41+
shadowOffsetY: 0,
42+
43+
// Drawing methods (no-ops for tests)
44+
fillRect: () => {},
45+
strokeRect: () => {},
46+
clearRect: () => {},
47+
fillText: () => {},
48+
strokeText: () => {},
49+
measureText: (text: string) => ({ width: text.length * 8 }),
50+
drawImage: () => {},
51+
save: () => {},
52+
restore: () => {},
53+
scale: () => {},
54+
rotate: () => {},
55+
translate: () => {},
56+
transform: () => {},
57+
setTransform: () => {},
58+
resetTransform: () => {},
59+
createLinearGradient: () => ({
60+
addColorStop: () => {},
61+
}),
62+
createRadialGradient: () => ({
63+
addColorStop: () => {},
64+
}),
65+
createPattern: () => null,
66+
beginPath: () => {},
67+
closePath: () => {},
68+
moveTo: () => {},
69+
lineTo: () => {},
70+
bezierCurveTo: () => {},
71+
quadraticCurveTo: () => {},
72+
arc: () => {},
73+
arcTo: () => {},
74+
ellipse: () => {},
75+
rect: () => {},
76+
fill: () => {},
77+
stroke: () => {},
78+
clip: () => {},
79+
isPointInPath: () => false,
80+
isPointInStroke: () => false,
81+
getTransform: () => ({}),
82+
getImageData: () => ({
83+
data: new Uint8ClampedArray(0),
84+
width: 0,
85+
height: 0,
86+
}),
87+
putImageData: () => {},
88+
createImageData: () => ({
89+
data: new Uint8ClampedArray(0),
90+
width: 0,
91+
height: 0,
92+
}),
93+
} as any;
94+
}
95+
return originalGetContext.call(this, contextType, options);
96+
};

0 commit comments

Comments
 (0)