Initial Commit
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { webcrypto } from "node:crypto";
|
||||
|
||||
type WritableGlobal = {
|
||||
crypto?: Crypto;
|
||||
WebSocket?: unknown;
|
||||
};
|
||||
const g = globalThis as WritableGlobal;
|
||||
|
||||
if (g.crypto === undefined) {
|
||||
g.crypto = webcrypto as unknown as Crypto;
|
||||
}
|
||||
|
||||
// SurrealDB v2 client (`new WebSocketImpl(...)`) reads `globalThis.WebSocket`.
|
||||
// Vitest's Node environment does not expose Bun's built-in WebSocket; polyfill
|
||||
// using the `ws` package (already a transitive dep) so the live integration
|
||||
// suite can open WebSockets to the test container.
|
||||
if (g.WebSocket === undefined) {
|
||||
const { WebSocket } = require("ws") as { WebSocket: unknown };
|
||||
g.WebSocket = WebSocket;
|
||||
}
|
||||
Reference in New Issue
Block a user