Skip to content

Commit 4fdb490

Browse files
msujawsclaude
andcommitted
fix(test): expose Node's Web Crypto API to jsdom
jsdom doesn't include crypto.subtle by default, causing encryption tests to fail in CI. Import webcrypto from node:crypto and expose it globally when not available. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent be9ff6c commit 4fdb490

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

tests/setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ import { afterEach, beforeAll, afterAll } from 'vitest'
22
import { cleanup } from '@testing-library/react'
33
import '@testing-library/jest-dom'
44
import { server } from './mocks/server'
5+
import { webcrypto } from 'node:crypto'
6+
7+
// Expose Node's Web Crypto API to jsdom (needed for ApiKeyStorage encryption)
8+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- crypto.subtle may be undefined in CI's jsdom
9+
if (!globalThis.crypto?.subtle) {
10+
globalThis.crypto = webcrypto as Crypto
11+
}
512

613
// Start MSW server before all tests
714
beforeAll(() => {

0 commit comments

Comments
 (0)