test(setup): observe promises in the ClipboardItem stub - #202
Merged
Merged
Conversation
jsdom's user agent makes Monaco install its WebKit clipboard workaround, which passes a pending promise into a new ClipboardItem on every click and cancels the previous one. The stub stored those promises without observing them, so each cancellation became an unhandled rejection that failed the vitest run even when every test passed, as on the main push after the last merge. - the stub observes the promises it receives, like a real ClipboardItem, while getType still awaits the original so a reader sees a rejection - a regression test covers a promise rejected after the item is built, a reader of a rejected type, resolved and inline values, and three clicks with Monaco initialised, asserting that the workaround wrote to the clipboard and that no rejection went unhandled - with Monaco initialised up front in UtilityToolbarApply.test.tsx, the old stub produced six unhandled Canceled rejections and the new one none Changelog: none
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
Fixes the unhandled
Canceledrejection that failed the Unit job on the main push after #201, while all 8,089 tests passed. The cause is theClipboardItemstub intests/setup.ts: it stores the promises it is given without observing them. It now observes them the way a realClipboardItemdoes, and a regression test pins the behavior.Root cause
new ClipboardItem({ 'text/plain': promise }), and the next click cancels the previous one.ClipboardItemobserves those promises. The stub only reads them ingetType(), which nothing calls, so every cancellation became an unhandled rejection. Vitest fails the run on it even when every test passes.JsonSyntaxOutput, which imports it without awaiting and gives up if the component has already unmounted. On a fast machine the tests finish first. On a slow runner the component is still mounted, Monaco initialises, and later clicks in the same file hit the workaround.The CI run (35143874393) reported the rejection at
monaco-editor/.../clipboardService.js:74, originating intests/components/UtilityToolbarApply.test.tsx. The failed smoke artifact upload was only a consequence: the test step stopped before writing the smoke summary. Production is unaffected, because browsers use their realClipboardItem.Changes
tests/setup.ts. The stub's constructor attaches a no-op rejection handler to each promise-like value.getType()still awaits the original promise, so a reader of a rejected type still sees the rejection; types,getType,supportsand the writable global are unchanged.tests/clipboardItemStub.test.tsx(new).JsonSyntaxOutputdoes it, and the test clicks three times withuser-event. It asserts that the workaround wrote to the clipboard, so the guard fails loudly if Monaco ever drops it, and that no rejection went unhandled.Type of change
How was this tested?
Error: write cancelledand the Monaco case with twoCanceledrejections. With the fix, all four cases pass.UtilityToolbarApply.test.tsxinitialises Monaco in abeforeAll, which is what a slow runner ends up doing.Canceledrejections, the CI signature.qrCode.test.ts,QrCodePanel.test.tsx,UtilityToolbarApply.test.tsxandDeveloperUtilitiesModal.test.tsxpass 77 tests.pnpm test -- --runpasses 732 files and 8,095 tests with no unhandled errors: the counts on main plus the new file.tsc --noEmit,typecheck:tests, lint including the telemetry audit andchangelog:checkpass. The new test andtests/setup.tsalso type-check clean under a scratch config.knipreports only the existing website test dependencies.Checklist
pnpm test -- --runpassespnpm exec tsc --noEmitpassespnpm run lintpassespnpm run check:i18nandpnpm run check:i18n:copypass (if UI/i18n touched) — no UI or i18n in this diffRisk and review notes
ClipboardItemwould.