forked from Prompt-Hash-Stellar/prompt-hash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ts
More file actions
44 lines (40 loc) · 1.24 KB
/
Copy pathsetup.ts
File metadata and controls
44 lines (40 loc) · 1.24 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
import '@testing-library/jest-dom';
import { vi } from 'vitest';
import { Buffer } from 'buffer';
import * as nodeCrypto from 'node:crypto';
// 1. Force Buffer Polyfill
globalThis.Buffer = Buffer;
// 2. Force Crypto Polyfill (The proper way to bypass "getter-only" restriction)
Object.defineProperty(globalThis, 'crypto', {
value: nodeCrypto.webcrypto,
configurable: true,
writable: true,
});
// 3. Mock window features for JSDOM
if (typeof window !== 'undefined') {
if (!Element.prototype.hasPointerCapture) {
Element.prototype.hasPointerCapture = () => false;
}
if (!Element.prototype.setPointerCapture) {
Element.prototype.setPointerCapture = () => undefined;
}
if (!Element.prototype.releasePointerCapture) {
Element.prototype.releasePointerCapture = () => undefined;
}
if (!Element.prototype.scrollIntoView) {
Element.prototype.scrollIntoView = () => undefined;
}
Object.defineProperty(window, 'matchMedia', {
writable: true,
value: vi.fn().mockImplementation(query => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
})),
});
}