mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-06 08:07:49 +00:00
test: stub Range layout methods once in the test setup (#53)
Root cause: jsdom has no layout and CodeMirror measures text ranges in an animation frame, sometimes after a test finished; test files that did not stub Range.getClientRects (e.g. search/codePreview) threw an unhandled TypeError that failed whole CI runs at random (seen on #41). Fix: stub Range.getClientRects / getBoundingClientRect once in src/test/setup.ts; drop the six per-file copies. Verified: vitest on editor/lsp, editor/refactor, templates, search (55 files, 458 tests, no unhandled errors). Claude-Session: https://claude.ai/code/session_01VUYsdXA2nkF5v6zsC93dpn
This commit is contained in:
@@ -239,10 +239,6 @@ describe("lookup commit characters", () => {
|
||||
});
|
||||
|
||||
describe("explicit completion", () => {
|
||||
// jsdom has no layout; CodeMirror measures text when the tooltip is positioned.
|
||||
Range.prototype.getClientRects ??= () => [] as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
function editor(labels: string[]) {
|
||||
const source: CompletionSource = (ctx) => {
|
||||
const word = ctx.matchBefore(/\w*/);
|
||||
|
||||
@@ -16,10 +16,6 @@ const { signatureExtension, acceptsParameter, argumentSpans, argumentStop, param
|
||||
);
|
||||
const { lspDoc } = await import("./lsp");
|
||||
|
||||
// jsdom has no layout; CodeMirror measures text when the tooltip is positioned.
|
||||
Range.prototype.getClientRects ??= () => [] as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
const views: EditorView[] = [];
|
||||
afterEach(() => {
|
||||
views.splice(0).forEach((v) => v.destroy());
|
||||
|
||||
@@ -35,9 +35,6 @@ const { startRename } = await import("./rename");
|
||||
const { lspDoc } = await import("./lsp");
|
||||
const { useLspPopup, closePopup } = await import("./popupStore");
|
||||
|
||||
Range.prototype.getClientRects ??= () => [] as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
const r = (line: number, col: number, endCol: number): Range => ({ start: { line, col }, end: { line, col: endCol } });
|
||||
const node = (kind: string, range: Range, field: string | null = null): SyntaxNode => ({
|
||||
kind,
|
||||
|
||||
@@ -120,10 +120,6 @@ const { clearLevelCache } = await import("./projectLevel");
|
||||
|
||||
// --- editor ---------------------------------------------------------------------
|
||||
|
||||
// jsdom has no layout; popups anchor at caret coordinates.
|
||||
Range.prototype.getClientRects ??= () => [] as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
let view: EditorView | null = null;
|
||||
|
||||
function editor(doc: string, language: string, path: string, sel: { anchor: number; head?: number }) {
|
||||
|
||||
@@ -55,10 +55,6 @@ const { lspDoc } = await import("@/editor/lsp/lsp");
|
||||
const { inplaceRenameExtension, inplaceSession } = await import("@/editor/lsp/inplaceRename");
|
||||
const { temporaryHighlights } = await import("@/editor/lsp/tempHighlight");
|
||||
|
||||
// jsdom has no layout; popups anchor at the caret.
|
||||
Range.prototype.getClientRects ??= () => [] as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
const action = (title: string, kind: string, disabledReason: string | null = null): CodeAction => ({
|
||||
title,
|
||||
kind,
|
||||
|
||||
@@ -17,11 +17,6 @@ import { closeChooser, useChooser } from "../popup/store";
|
||||
|
||||
const MODES: Record<string, string> = { typescript: "TypeScript", rust: "Rust", python: "Python", java: "Java" };
|
||||
|
||||
// jsdom has no layout; CodeMirror measures ranges when scrolling the caret into view.
|
||||
const rects = () => Object.assign([], { item: () => null }) as unknown as DOMRectList;
|
||||
Range.prototype.getClientRects ??= rects;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
|
||||
let view: EditorView | null = null;
|
||||
afterEach(() => {
|
||||
view?.destroy();
|
||||
|
||||
@@ -39,5 +39,9 @@ if (typeof window !== "undefined") {
|
||||
}) as MediaQueryList;
|
||||
}
|
||||
Element.prototype.scrollIntoView ??= function () {};
|
||||
// No layout either: CodeMirror measures text ranges when it positions the caret,
|
||||
// tooltips and line heights, sometimes in an animation frame after a test ends.
|
||||
Range.prototype.getClientRects ??= () => Object.assign([], { item: () => null }) as unknown as DOMRectList;
|
||||
Range.prototype.getBoundingClientRect ??= () => new DOMRect();
|
||||
Element.prototype.scrollTo ??= function () {} as Element["scrollTo"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user