Repository navigation
test(muya): de-flake heading-locale + backspace regression specs (#4434 review) - #4436
Merged
Merged
Conversation
… review) Post-merge Copilot review on #4434 flagged real timing-dependence in two regression specs now on develop. Harden both so they deterministically exercise their bug guards: headingLocaleCrash.spec.ts - afterEach now clears the document-global Selection (window.getSelection()?.removeAllRanges()) so a stale Range can't point into a removed host node and break a later test's setCursor. - Every test that queries the HeadingCopyLink affordance / its aria-label / dispatches its click now `await flush()` after typeHeading(), since the paragraph->atx-heading conversion and the attachment render land on the next animation frame. - The "every shipped locale" test now actually loops all nine shipped locales (de, en, es, fr, ja, ko, pt, zh-CN, zh-TW) instead of just [en, zhCN], so typing `#` is proven crash-safe under every locale — the whole point of the guard. backspaceUnwrap.spec.ts - The caret/join-point assertion now `await flush()` before reading the merged tree, since the merge op flushes on the next frame; without it contentByText('alphabeta')/getCursor() could observe the pre-merge state. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens Muya regression specs introduced in #4434 by removing timing-related flakiness (next-animation-frame flush races) and by ensuring test isolation across runs. It keeps the original regression intent while making assertions deterministic.
Changes:
- Await a next-frame
flush()after heading conversion / backspace merge operations before asserting on DOM/state/cursor. - Clear the document-global
SelectioninafterEachto prevent staleRangereferences from affecting later tests. - Expand the “shipped locales” heading guard to exercise the conversion path across all bundled locales (9 total).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/muya/src/tests/headingLocaleCrash.spec.ts | De-flakes heading-locale regression tests via flush(), clears global selection in afterEach, and broadens locale coverage. |
| packages/muya/src/block/content/paragraphContent/tests/backspaceUnwrap.spec.ts | De-flakes caret/join-point assertion by awaiting the merge flush before reading merged content/cursor. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix-forward for #4434. After that PR merged, Copilot posted 6 review comments flagging genuine timing-flakiness in the two regression specs it added (now on
develop). This PR hardens both so they deterministically exercise their bug guards rather than racing the engine's next-animation-frame flush.What changed
packages/muya/src/__tests__/headingLocaleCrash.spec.tsafterEachnow clears the document-global Selection (window.getSelection()?.removeAllRanges()) — matching several other Muya specs — so a staleRangecan't point into a removed host node and break a later test'ssetCursor.await flush()aftertypeHeading(). The paragraph→atx-heading conversion and theHeadingCopyLinkattachment render flush on the next animation frame, so querying the affordance / reading itsaria-label/ dispatching its click immediately aftertypeHeading()could seenull. Affected: the zh-CN render test, the per-locale (en vs zh-CN) test, the click test, and the all-locale test.de, en, es, fr, ja, ko, pt, zh-CN, zh-TW(9) instead of just[en, zhCN]. Typing#must not crash under any locale, which is the whole point of the guard.packages/muya/src/block/content/paragraphContent/__tests__/backspaceUnwrap.spec.tsawait flush()before reading the merged tree. The merge op flushes on the next frame; without awaiting it,contentByText('alphabeta')/getCursor()could observe the pre-merge state.Test intent is preserved — each spec still genuinely exercises its original bug guard (the
#-crash-under-non-en-locale guard especially, now broadened to all 9 shipped locales).Verification
pnpm -C packages/muya lint— 0 errors (only pre-existing warnings in untouched files); the two changed files lint clean.pnpm -C packages/muya lint:types— clean.pnpm -C packages/muya test— 671 passed.pnpm -C packages/muya test:spec— 1347 passed.madgecircular check — no circular deps.Related: #4434
🤖 Generated with Claude Code