…pboard mock
createClipboard's 'reads clipboard items after refetch' failed intermittently in CI
(expected 'a' to be 'InitialValue'). Test files share a worker (isolate: false) and both
clipboard test files use the same module-level mock from setup.ts; copy-status spied on
writeText/write but called through, so whatever it copied last stayed in the mock and
index.test.ts read it when it ran second. Reproduced with a forced file order; the spies
now resolve without calling through.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Summary
Fixes an intermittent CI failure:
createClipboard > reads clipboard items after refetchfails withexpected 'a' to be 'InitialValue'(seen on #1144 and #1152, neither touches clipboard, and once locally).Cause
The vitest config uses
isolate: false, so test files that land in the same worker share module state. Both clipboard test files import./setup, whosenavigator.clipboardmock keeps its last written value in a module-level variable.copy-status.test.tsspied onwriteText/writebut called through, so whatever it copied last ('a') stayed in the mock, andindex.test.tsread it when it ran second. Whether that happens depends on how the files are scheduled onto workers, which is why it only fails sometimes.The leak was introduced by the
createCopyToClipboardtests from #1140.Fix
The
copy-statusspies now resolve without calling through, so they can't change the shared mock.Verification
pnpm exec vitest run packages/clipboard: 17/17.🤖 Generated with Claude Code
Summary by CodeRabbit