From f62c2b5e9127d5985d307032572583867439ab1b Mon Sep 17 00:00:00 2001 From: Tadeu Tupinamba Date: Tue, 3 Mar 2026 19:46:02 -0300 Subject: [PATCH] fix(test): stabilize flaky cleanUpParagraphWithAnnotations tests Add missing vi.resetModules() to the first describe block and remove a duplicate PMNode.prototype.children monkey-patch. Every test uses vi.doMock + dynamic await import() to swap mocks per-test. The first describe block was missing vi.resetModules() in its beforeEach, so under heavy parallel load (688 test files) a Vitest worker could serve a cached unmocked module from a previous test, causing assertion failures. --- .../cleanUpParagraphWithAnnotation.test.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/super-editor/src/extensions/field-annotation/cleanup-commands/cleanUpParagraphWithAnnotation.test.js b/packages/super-editor/src/extensions/field-annotation/cleanup-commands/cleanUpParagraphWithAnnotation.test.js index 1c475245f8..d215a004f2 100644 --- a/packages/super-editor/src/extensions/field-annotation/cleanup-commands/cleanUpParagraphWithAnnotation.test.js +++ b/packages/super-editor/src/extensions/field-annotation/cleanup-commands/cleanUpParagraphWithAnnotation.test.js @@ -27,6 +27,10 @@ const textContent = (docNode) => docNode.textContent; const mockHelperPath = '../fieldAnnotationHelpers/index.js'; describe('cleanUpParagraphWithAnnotations - test range error crash', () => { + beforeEach(() => { + vi.resetModules(); + }); + /** Test to fix error in position out of range in original */ it('throws RangeError "Position … out of range" on single-paragraph doc', async () => { const doc = schema.node('doc', null, [p.createAndFill(null, [text('A')])]); @@ -49,15 +53,6 @@ describe('cleanUpParagraphWithAnnotations - test range error crash', () => { }); }); -if (!Object.getOwnPropertyDescriptor(PMNode.prototype, 'children')) { - Object.defineProperty(PMNode.prototype, 'children', { - get() { - return { length: this.childCount }; - }, - configurable: true, - }); -} - describe('cleanUpParagraphWithAnnotations – original behavior', () => { beforeEach(() => { vi.resetModules();