From 5c0ba37eda80d39e6ceca59bb1d5f4942f858995 Mon Sep 17 00:00:00 2001 From: "Somhairle H. Marisol" Date: Thu, 17 Sep 2026 14:32:37 +0800 Subject: chore: establish Strategy Lab source baseline (development, not release) --- frontend/src/test-setup.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 frontend/src/test-setup.ts (limited to 'frontend/src/test-setup.ts') 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; +} -- cgit v1.2.3