diff --git a/packages/react/src/components/code-block-view.test.tsx b/packages/react/src/components/code-block-view.test.tsx index 4001ddc4..ea69ff71 100644 --- a/packages/react/src/components/code-block-view.test.tsx +++ b/packages/react/src/components/code-block-view.test.tsx @@ -1,6 +1,5 @@ import '../testing/index.ts' -import { isSafari } from '@meowdown/vitest/helpers' import { createRef } from 'react' import { describe, expect, it, vi } from 'vitest' import { render } from 'vitest-browser-react' @@ -70,10 +69,7 @@ describe('code block language selector', () => { }) }) - it.skipIf( - // Safari doesn't support `navigator.clipboard.readText()` - isSafari(), - )('copies the code block contents to the clipboard', async () => { + it('copies the code block contents to the clipboard', async () => { await render() await expect.element(copyButton).toBeInTheDocument() diff --git a/packages/vitest/src/config.ts b/packages/vitest/src/config.ts index f4a2c14d..fed0b3da 100644 --- a/packages/vitest/src/config.ts +++ b/packages/vitest/src/config.ts @@ -16,6 +16,15 @@ export function defineSharedConfig() { return 'chromium' })() + // WebKit and Chromium reject navigator.clipboard.readText() unless 'clipboard-read' + // is granted. Chromium also needs 'clipboard-write'. Firefox reads without a grant. + const clipboardPermissions = + browserName === 'chromium' + ? ['clipboard-read', 'clipboard-write'] + : browserName === 'webkit' + ? ['clipboard-read'] + : undefined + return defineProject({ plugins: [playwrightCommands()], oxc: @@ -39,8 +48,7 @@ export function defineSharedConfig() { reducedMotion: 'reduce', hasTouch: true, // A list of permissions to grant to all pages in this context. See https://playwright.dev/docs/api/class-browsercontext#browser-context-grant-permissions - permissions: - browserName === 'chromium' ? ['clipboard-read', 'clipboard-write'] : undefined, + permissions: clipboardPermissions, }, }), headless: true,