Files
bitvid/scripts/agent/setup-test-env.js
T
google-labs-jules[bot] b52396b6f7 feat: add protocol interop tests script
- Added `scripts/agent/interop-test.mjs` to verify Nostr protocol compatibility (Video Post, View Event, DM) using ephemeral keys.
- Added `scripts/agent/setup-test-env.js` to polyfill browser globals for Node.js execution.
- Ensures events are constructed via schema builders and published to test relays.
2026-01-20 07:16:20 +00:00

43 lines
1.1 KiB
JavaScript

import WebSocket from 'ws';
import { webcrypto } from 'node:crypto';
// Polyfill WebSocket
if (typeof globalThis.WebSocket === 'undefined') {
globalThis.WebSocket = WebSocket;
}
// Polyfill window and self
if (typeof globalThis.window === 'undefined') {
globalThis.window = globalThis;
}
if (typeof globalThis.self === 'undefined') {
globalThis.self = globalThis;
}
// Polyfill crypto
if (typeof globalThis.crypto === 'undefined') {
globalThis.crypto = webcrypto;
}
// Polyfill localStorage
if (typeof globalThis.localStorage === 'undefined') {
const storage = new Map();
globalThis.localStorage = {
getItem: (k) => storage.get(k) || null,
setItem: (k, v) => storage.set(String(k), String(v)),
removeItem: (k) => storage.delete(k),
clear: () => storage.clear(),
key: (i) => Array.from(storage.keys())[i] || null,
get length() { return storage.size; }
};
}
if (typeof globalThis.window.localStorage === 'undefined') {
globalThis.window.localStorage = globalThis.localStorage;
}
// Mock navigator
if (typeof globalThis.navigator === 'undefined') {
globalThis.navigator = { userAgent: 'node' };
}