From 00daa14dcde0e95c6a67e4ebc8bfffd53d1b68b0 Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Tue, 28 Apr 2026 14:25:25 +0200 Subject: [PATCH] test(sounds): use realm-safe Uint8Array check (TextEncoder vs jsdom) vitest+jsdom puts test code in a different realm than Node's TextEncoder, so `toBeInstanceOf(Uint8Array)` rejects the encoder's return value even though it is structurally a Uint8Array. `Object.prototype.toString.call` checks the @@toStringTag tag, which is realm-safe. --- packages/web/src/utils/streamWatchProtocol.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/web/src/utils/streamWatchProtocol.test.ts b/packages/web/src/utils/streamWatchProtocol.test.ts index 19074092..f04586c7 100644 --- a/packages/web/src/utils/streamWatchProtocol.test.ts +++ b/packages/web/src/utils/streamWatchProtocol.test.ts @@ -9,9 +9,9 @@ describe('streamWatchProtocol', () => { it('round-trips an encoded payload', () => { const payload = { type: 'stream_watch' as const, target: 'user-1', watching: true }; const encoded = encodeStreamWatch(payload); - // Verify contract: TextEncoder.encode always returns Uint8Array with buffer + byteLength - expect(encoded.buffer).toBeDefined(); - expect(encoded.byteLength).toBeGreaterThan(0); + // Realm-safe Uint8Array check — TextEncoder returns a Uint8Array from Node's + // realm, which `toBeInstanceOf(Uint8Array)` rejects under vitest+jsdom. + expect(Object.prototype.toString.call(encoded)).toBe('[object Uint8Array]'); const parsed = parseStreamWatch(encoded); expect(parsed).toEqual(payload); });