From 04136f79fc21052d6f9d1e73ab17de8c3fc29b71 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 7 Jan 2026 10:06:25 +0000 Subject: [PATCH] fix(test): add WebSocket polyfill for Node.js test environment nostr-tools relay code requires WebSocket which isn't available in Node.js by default. Adding the ws package polyfill prevents "ReferenceError: WebSocket is not defined" errors in tests. --- src/test/setup.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/setup.ts b/src/test/setup.ts index eba54c2..fb2c703 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -1,7 +1,13 @@ /** * Vitest setup file * - * Polyfills IndexedDB for Node.js test environment. - * This allows Dexie to work in tests without a browser. + * Polyfills browser APIs for Node.js test environment. */ + +// Polyfill IndexedDB - allows Dexie to work in tests import "fake-indexeddb/auto"; + +// Polyfill WebSocket - required by nostr-tools relay code +import { WebSocket } from "ws"; +// @ts-expect-error - polyfilling global WebSocket for Node.js +globalThis.WebSocket = WebSocket;