diff --git a/src/editor/lsp/completion.test.ts b/src/editor/lsp/completion.test.ts index 50698082..047dcf47 100644 --- a/src/editor/lsp/completion.test.ts +++ b/src/editor/lsp/completion.test.ts @@ -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*/); diff --git a/src/editor/lsp/signature.test.ts b/src/editor/lsp/signature.test.ts index 51cd1d97..99cfc7ef 100644 --- a/src/editor/lsp/signature.test.ts +++ b/src/editor/lsp/signature.test.ts @@ -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()); diff --git a/src/editor/lsp/syntaxFallback.test.ts b/src/editor/lsp/syntaxFallback.test.ts index 8170d893..5ad76d98 100644 --- a/src/editor/lsp/syntaxFallback.test.ts +++ b/src/editor/lsp/syntaxFallback.test.ts @@ -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, diff --git a/src/editor/refactor/introduce.test.ts b/src/editor/refactor/introduce.test.ts index 04f6bfd8..181c6f9a 100644 --- a/src/editor/refactor/introduce.test.ts +++ b/src/editor/refactor/introduce.test.ts @@ -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 }) { diff --git a/src/editor/refactor/refactorThis.test.ts b/src/editor/refactor/refactorThis.test.ts index 280b603b..fbe7b802 100644 --- a/src/editor/refactor/refactorThis.test.ts +++ b/src/editor/refactor/refactorThis.test.ts @@ -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, diff --git a/src/features/templates/__tests__/editor.test.ts b/src/features/templates/__tests__/editor.test.ts index af6980e6..e17c9e9b 100644 --- a/src/features/templates/__tests__/editor.test.ts +++ b/src/features/templates/__tests__/editor.test.ts @@ -17,11 +17,6 @@ import { closeChooser, useChooser } from "../popup/store"; const MODES: Record = { 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(); diff --git a/src/test/setup.ts b/src/test/setup.ts index 2dfbc6b6..066875e3 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -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"]; }