-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathsetup.ts
More file actions
39 lines (33 loc) · 1.28 KB
/
setup.ts
File metadata and controls
39 lines (33 loc) · 1.28 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
import { toContainGraph } from '../custom-matchers/toContainGraph'
import { toEqualGraph } from '../custom-matchers/toEqualGraph'
import 'isomorphic-fetch'
import { TextEncoder, TextDecoder } from 'util'
import { TransformStream, ReadableStream, WritableStream } from 'stream/web'
// https://stackoverflow.com/questions/52612122/how-to-use-jest-to-test-functions-using-crypto-or-window-mscrypto
import crypto from 'crypto'
global.crypto = {
getRandomValues: function (buffer) {
return crypto.randomFillSync(buffer)
}
}
global.TextEncoder = TextEncoder
global.TextDecoder = TextDecoder
global.TransformStream = TransformStream
global.ReadableStream = ReadableStream
global.WritableStream = WritableStream
// Node provides MessagePort via worker_threads; jsdom/undici expects it in global scope
try {
// Intentionally require worker_threads in Jest setup to expose MessagePort globals.
const { MessageChannel, MessagePort } = require('worker_threads')
global.MessageChannel = MessageChannel
global.MessagePort = MessagePort
} catch (err) {
// worker_threads not available (older Node), ignore
}
// Mock external dependencies that solid-logic expects
jest.mock('$rdf', () => require('rdflib'), { virtual: true })
// adding custom matchers
expect.extend({
toContainGraph,
toEqualGraph
})