Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

test(markdown-editor): extract shared jsdom setup + roundTrip helper

Sergey Kozyrenko8c67ed29fe20
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts
index 3a487462..34d09c88 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-content-integrity.test.ts
@@ -1,23 +1,9 @@
-import { Editor } from '@tiptap/core';
import { beforeAll, describe, expect, it } from 'vitest';
-import { createMarkdownExtensions } from './markdown-editor-extensions';
+import { roundTrip, setupEditorJsdom } from './markdown-editor-test-setup';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
-
-const roundTrip = (md: string): string => {
- const editor = new Editor({ content: md, contentType: 'markdown', extensions: createMarkdownExtensions() });
- const out = editor.getMarkdown();
- editor.destroy();
- return out;
-};
+beforeAll(setupEditorJsdom);
const mulberry32 = (seed: number) => () => {
seed = (seed + 0x6d2b79f5) | 0;
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts
index 76ddf729..e477c119 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-corpus.test.ts
@@ -1,27 +1,11 @@
-import { Editor } from '@tiptap/core';
import { readdirSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
import { beforeAll, describe, expect, it } from 'vitest';
-import { createMarkdownExtensions } from './markdown-editor-extensions';
+import { roundTrip, setupEditorJsdom } from './markdown-editor-test-setup';
-// The editor's Placeholder extension tracks the viewport via document.elementFromPoint +
-// Range.getClientRects, which jsdom lacks — stub them or every editor mount throws.
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
-
-const roundTrip = (content: string): string => {
- const editor = new Editor({ content, contentType: 'markdown', extensions: createMarkdownExtensions() });
- const out = editor.getMarkdown();
- editor.destroy();
- return out;
-};
+beforeAll(setupEditorJsdom);
const variables = (s: string) => s.match(/\{\{[^{}]*\}\}/g) ?? [];
const words = (s: string) => s.match(/[\p{L}\p{N}]+/gu) ?? [];
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts
index 779df673..ec5462c5 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-extensions.test.ts
@@ -2,23 +2,10 @@ import { Editor } from '@tiptap/core';
import { beforeAll, describe, expect, it } from 'vitest';
import { createMarkdownExtensions } from './markdown-editor-extensions';
+import { roundTrip, setupEditorJsdom } from './markdown-editor-test-setup';
import { findVariableOccurrences } from './markdown-editor-variable-highlight';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
-
-const roundTrip = (content: string): string => {
- const editor = new Editor({ content, contentType: 'markdown', extensions: createMarkdownExtensions() });
- const out = editor.getMarkdown();
- editor.destroy();
-
- return out;
-};
+beforeAll(setupEditorJsdom);
const words = (s: string): string[] => s.match(/[\p{L}\p{N}]+/gu) ?? [];
const sameWords = (a: string, b: string) => expect(words(b).sort()).toEqual(words(a).sort());
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-handle.test.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor-handle.test.tsx
index 0b7b1bd0..6b65a1a3 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-handle.test.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-handle.test.tsx
@@ -3,14 +3,9 @@ import { createRef } from 'react';
import { beforeAll, describe, expect, it, vi } from 'vitest';
import { MarkdownEditor, type MarkdownEditorHandle } from './markdown-editor';
+import { setupEditorJsdom } from './markdown-editor-test-setup';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
+beforeAll(setupEditorJsdom);
const proseMirror = (c: HTMLElement) => c.querySelector('.ProseMirror');
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-history.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-history.test.ts
index 104123ac..01f3ec5e 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-history.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-history.test.ts
@@ -4,14 +4,9 @@ import { beforeAll, expect, it } from 'vitest';
import { resetUndoHistory } from './markdown-editor';
import { createMarkdownExtensions } from './markdown-editor-extensions';
+import { setupEditorJsdom } from './markdown-editor-test-setup';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
+beforeAll(setupEditorJsdom);
// Reproduces the production-only crash class: `view.updateState` inside resetUndoHistory can synchronously
// advance `view.state` (a plugin view dispatching during reconfigure), so a poke transaction built from the
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-indented-fence.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-indented-fence.test.ts
index cdf9b50e..17b0d943 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-indented-fence.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-indented-fence.test.ts
@@ -2,14 +2,9 @@ import { Editor } from '@tiptap/core';
import { beforeAll, describe, expect, it } from 'vitest';
import { createMarkdownExtensions } from './markdown-editor-extensions';
+import { setupEditorJsdom } from './markdown-editor-test-setup';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
+beforeAll(setupEditorJsdom);
const load = (md: string) => {
const editor = new Editor({ content: md, contentType: 'markdown', extensions: createMarkdownExtensions() });
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
index 78da1f11..f24a0aef 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-paste.test.ts
@@ -4,14 +4,9 @@ import { beforeAll, describe, expect, it } from 'vitest';
import { createMarkdownExtensions } from './markdown-editor-extensions';
import { shouldParseMarkdownOnPaste } from './markdown-editor-paste';
+import { setupEditorJsdom } from './markdown-editor-test-setup';
-beforeAll(() => {
- document.elementFromPoint = () => null;
- const r = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
- Range.prototype.getBoundingClientRect = () => r as DOMRect;
- Range.prototype.getClientRects = () =>
- ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
-});
+beforeAll(setupEditorJsdom);
describe('shouldParseMarkdownOnPaste — markdown-parse plain text, defer rich sources', () => {
it('parses plain-text markdown (no HTML on the clipboard)', () => {
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts
new file mode 100644
index 00000000..9be179b9
--- /dev/null
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-test-setup.ts
@@ -0,0 +1,22 @@
+import { Editor } from '@tiptap/core';
+
+import { createMarkdownExtensions } from './markdown-editor-extensions';
+
+// jsdom has no layout engine, so a mounted tiptap/ProseMirror view throws when it reads coordinates. Stub the
+// three surfaces it touches (elementFromPoint + Range rects). Call from a test's beforeAll.
+export const setupEditorJsdom = (): void => {
+ document.elementFromPoint = () => null;
+ const rect = { bottom: 0, height: 0, left: 0, right: 0, toJSON: () => ({}), top: 0, width: 0, x: 0, y: 0 };
+ Range.prototype.getBoundingClientRect = () => rect as DOMRect;
+ Range.prototype.getClientRects = () =>
+ ({ item: () => null, length: 0, [Symbol.iterator]: [][Symbol.iterator] }) as unknown as DOMRectList;
+};
+
+// The folder's standard load↔save round-trip: parse markdown into a headless editor and re-serialize.
+export const roundTrip = (markdown: string): string => {
+ const editor = new Editor({ content: markdown, contentType: 'markdown', extensions: createMarkdownExtensions() });
+ const out = editor.getMarkdown();
+ editor.destroy();
+
+ return out;
+};