diff options
| author | Somhairle H. Marisol <[email protected]> | 2026-09-17 14:32:37 +0800 |
|---|---|---|
| committer | Somhairle H. Marisol <[email protected]> | 2026-09-17 14:32:37 +0800 |
| commit | 5c0ba37eda80d39e6ceca59bb1d5f4942f858995 (patch) | |
| tree | 948723f9cedf7ccb0707fa6ee516bd30fe20fd10 /frontend/src/test-setup.ts | |
| download | strategy-lab-5c0ba37eda80d39e6ceca59bb1d5f4942f858995.tar.gz | |
chore: establish Strategy Lab source baseline (development, not release)
Diffstat (limited to 'frontend/src/test-setup.ts')
| -rw-r--r-- | frontend/src/test-setup.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/frontend/src/test-setup.ts b/frontend/src/test-setup.ts new file mode 100644 index 0000000..cdd6071 --- /dev/null +++ b/frontend/src/test-setup.ts @@ -0,0 +1,36 @@ + +// jsdom does not implement Range.getClientRects, which CodeMirror's +// measurement layer calls for drawing decorations (diagnostics markers). +// Without it the suite emits an unhandled +// `textRange(...).getClientRects is not a function` TypeError even though +// assertions pass. Narrow geometry shim ONLY for the missing API; it returns +// one empty rect, from which CodeMirror derives null geometry — no other +// errors are suppressed. +if (typeof Range !== 'undefined' && !Range.prototype.getClientRects) { + const EMPTY_RECT = { left: 0, right: 0, top: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0, toJSON() { return {}; } }; + Range.prototype.getClientRects = function getClientRects() { + return [EMPTY_RECT] as unknown as DOMRectList; + }; +} + +// jsdom ships no canvas backend: HTMLCanvasElement.prototype.getContext exists +// but throws "Not implemented". Charts render with ECharts' SVG renderer; the +// only canvas user in tests is zrender's text-metrics helper (measureText +// paints into a hidden canvas). Replace getContext ONLY when the native +// implementation is the throwing stub, and provide just the measurement +// approximation — SVG chart rendering itself (the part regressions inspect) +// is untouched and fully real. +if (typeof HTMLCanvasElement !== 'undefined') { + HTMLCanvasElement.prototype.getContext = function getContext(this: HTMLCanvasElement, contextId: string) { + if (contextId === '2d') { + return { + canvas: this, + font: '', + measureText(text: string) { + return { width: String(text).length * 7, actualBoundingBoxAscent: 7, actualBoundingBoxDescent: 1 }; + } + } as unknown as CanvasRenderingContext2D; + } + return null; + } as unknown as typeof HTMLCanvasElement.prototype.getContext; +} |
