|
1 | 1 | import '@testing-library/jest-dom'; |
2 | 2 | import './src/i18n/config'; |
| 3 | +import { installIndexedDBMock } from './test-utils/indexeddb-mock'; |
| 4 | + |
| 5 | +// Polyfill crypto.subtle and TextEncoder/TextDecoder for jsdom |
| 6 | +if (typeof globalThis.crypto !== 'undefined' && !globalThis.crypto.subtle) { |
| 7 | + const { webcrypto } = require('crypto'); |
| 8 | + Object.defineProperty(globalThis, 'crypto', { |
| 9 | + value: webcrypto, |
| 10 | + writable: false, |
| 11 | + configurable: true, |
| 12 | + }); |
| 13 | +} |
| 14 | +const { TextEncoder, TextDecoder } = require('util'); |
| 15 | +if (typeof globalThis.TextEncoder === 'undefined') { |
| 16 | + globalThis.TextEncoder = TextEncoder; |
| 17 | +} |
| 18 | +if (typeof globalThis.TextDecoder === 'undefined') { |
| 19 | + globalThis.TextDecoder = TextDecoder; |
| 20 | +} |
| 21 | + |
| 22 | +// Mock File System Access API (showSaveFilePicker) |
| 23 | +if (typeof globalThis.window === 'undefined') { |
| 24 | + // running in node - provide a minimal window and document |
| 25 | + globalThis.window = globalThis; |
| 26 | +} |
| 27 | + |
| 28 | +if (!('showSaveFilePicker' in globalThis)) { |
| 29 | + globalThis.showSaveFilePicker = async (options = {}) => { |
| 30 | + const chunks = []; |
| 31 | + return { |
| 32 | + createWritable: async () => ({ |
| 33 | + write: async (data) => { |
| 34 | + // accept Blob or write request |
| 35 | + if (data instanceof Blob) { |
| 36 | + const array = new Uint8Array(await data.arrayBuffer()); |
| 37 | + chunks.push(array); |
| 38 | + } else if (data && data.data instanceof Blob) { |
| 39 | + const array = new Uint8Array(await data.data.arrayBuffer()); |
| 40 | + chunks.push(array); |
| 41 | + } |
| 42 | + }, |
| 43 | + close: async () => {}, |
| 44 | + }), |
| 45 | + }; |
| 46 | + }; |
| 47 | +} |
| 48 | + |
| 49 | +// Install enhanced IndexedDB mock for tests |
| 50 | +try { |
| 51 | + installIndexedDBMock(); |
| 52 | +} catch (e) { |
| 53 | + // ignore if already installed or environment prevents it |
| 54 | +} |
0 commit comments