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