Skip to content

[lexical] Chore: Migrate LexicalSelection tests to buildEditorFromExtensions - #8865

Merged
etrepum merged 3 commits into
facebook:mainfrom
mayrang:chore/selection-test-modernize
Jul 20, 2026
Merged

[lexical] Chore: Migrate LexicalSelection tests to buildEditorFromExtensions#8865
etrepum merged 3 commits into
facebook:mainfrom
mayrang:chore/selection-test-modernize

Conversation

@mayrang

@mayrang mayrang commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Description

LexicalSelection.test.ts still used the legacy initializeUnitTest pattern — a React-rendering harness with testEnv.editor, a wrapper <div>, and implicit beforeEach/afterEach. This PR replaces all 15 initializeUnitTest blocks with the headless buildEditorFromExtensions + using pattern (or shared let editor + beforeEach/afterEach where tests need common state).

Along the way, several stale patterns got cleaned up:

  • expect($isFoo(x)).toBe(true)assert($isFoo(x)) (vitest type-narrowing assert)
  • Manual anchor.set / focus.set pairs → setTextNodeRange() or node.select()
  • $assertRangeSelection($getSelection())assert($isRangeSelection(selection))
  • 3-line $createRangeSelection() + setTextNodeRange() + $setSelection()node.select(0, 0).setTextNodeRange()
  • Duplicate beforeEach setup between getNodes() and extract() → shared parent describe
  • createEditor in the Bug: Pasting into custom inline ElementNode fails #6701 regression test → buildEditorFromExtensions
  • Nested ternary in inline-element setup → object lookup
  • Redundant await on {discrete: true} updates

Net −92 lines. All 78 tests pass unchanged.

Test plan

  • pnpm test-unit -- LexicalSelection.test.ts — 78 pass
  • Full unit suite — 3971 pass
  • e2e (chromium) — 770 pass
  • tsc / prettier / eslint clean

mayrang added 3 commits July 20, 2026 21:24
…ensions

Convert all 15 initializeUnitTest blocks in LexicalSelection.test.ts to the modern buildEditorFromExtensions + using pattern. No behavioral change — pure infrastructure modernization.

- Replace React-rendered test editors with headless buildEditorFromExtensions
- Create shared selectionTestExtension (LinkExtension + ListExtension + test nodes)
- Simplify insertText helpers to capture editor/container from closure scope
- Adjust innerHTML assertions to remove the React wrapper div
- Use LexicalEditorWithDispose for describe blocks that call Symbol.dispose
- Replace expect($isXxx(...)).toBe(true) with assert($isXxx(...)) for type narrowing (6 instances)
- Convert text-type anchor.set/focus.set pairs to setTextNodeRange (12 cross-node pairs)
- Simplify same-node selections to node.select(start, end) (8 instances)
- Element-type and mixed anchor/focus points remain as-is (no replacement API)
- Replace LexicalEditor type with LexicalEditorWithDispose + Symbol.dispose in top-level describe
- Convert nested ternary to object lookup in inline element setup
- Add {discrete: true} to insertText() test
- Modernize facebook#6701 regression test to use buildEditorFromExtensions
- Replace  with assert() pattern (15 instances)
- Unify all invariant() calls to vitest assert() for consistency (44 instances)
- Simplify cross-node selection creation: node.select(0,0).setTextNodeRange() (9 instances)
- Extract shared setup for getNodes()/extract() into parent describe
- Remove redundant await on {discrete: true} updates
@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Jul 20, 2026 1:33pm
lexical-playground Ready Ready Preview Jul 20, 2026 1:33pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2026
@etrepum
etrepum added this pull request to the merge queue Jul 20, 2026
Merged via the queue into facebook:main with commit 385a93c Jul 20, 2026
46 checks passed
@etrepum etrepum mentioned this pull request Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants