-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjest-setup.js
More file actions
34 lines (32 loc) · 955 Bytes
/
jest-setup.js
File metadata and controls
34 lines (32 loc) · 955 Bytes
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
// Jest setup provided by Grafana scaffolding
import './.config/jest-setup';
// React 19 requires additional globals for Jest environment
// Polyfill MessageChannel for scheduling
if (typeof MessageChannel === 'undefined') {
global.MessageChannel = class MessageChannel {
constructor() {
this.port1 = {
postMessage: (message) => {
if (this.port2.onmessage) {
setTimeout(() => this.port2.onmessage({ data: message }), 0);
}
},
onmessage: null,
};
this.port2 = {
postMessage: (message) => {
if (this.port1.onmessage) {
setTimeout(() => this.port1.onmessage({ data: message }), 0);
}
},
onmessage: null,
};
}
};
}
// Polyfill TextEncoder/TextDecoder
if (typeof TextEncoder === 'undefined') {
const util = require('util');
global.TextEncoder = util.TextEncoder;
global.TextDecoder = util.TextDecoder;
}