// jest setup: polyfill structuredClone for fake-indexeddb if (typeof globalThis.structuredClone !== 'function') { globalThis.structuredClone = (obj) => JSON.parse(JSON.stringify(obj)); } // polyfill TextEncoder/TextDecoder for jsdom environment if (typeof globalThis.TextEncoder === 'undefined') { const { TextEncoder: TE, TextDecoder: TD } = require('util'); globalThis.TextEncoder = TE; globalThis.TextDecoder = TD; } if (typeof globalThis.TextDecoder === 'undefined') { const { TextDecoder: TD } = require('util'); globalThis.TextDecoder = TD; } // polyfill WebCrypto (crypto.subtle) — jsdom 仅提供 getRandomValues if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle === 'undefined') { const { webcrypto } = require('crypto'); globalThis.crypto = webcrypto; // jsdom 环境暴露 getRandomValues 的旧引用可能被覆盖,统一替换 Object.defineProperty(globalThis, 'crypto', { value: webcrypto, writable: true, configurable: true, }); }