From a45981f9d0ccd08c62a9e6a7b1cedbe9565afeb7 Mon Sep 17 00:00:00 2001 From: Artem Zakharchenko Date: Thu, 19 Sep 2024 17:39:04 +0200 Subject: [PATCH] test: check `event.data` before resolving --- test/browser/ws-api/ws.clients.browser.test.ts | 2 +- .../ws-api/ws.intercept.client.browser.test.ts | 12 +++++++++--- .../ws-api/ws.intercept.server.browser.test.ts | 10 +++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/test/browser/ws-api/ws.clients.browser.test.ts b/test/browser/ws-api/ws.clients.browser.test.ts index e2eba5472..098fed76c 100644 --- a/test/browser/ws-api/ws.clients.browser.test.ts +++ b/test/browser/ws-api/ws.clients.browser.test.ts @@ -231,7 +231,7 @@ test('clears the list of clients when the page is reloaded', async ({ }) } - await enableMocking(page) + await enableMocking() expect(await page.evaluate(() => window.link.clients.size)).toBe(0) diff --git a/test/browser/ws-api/ws.intercept.client.browser.test.ts b/test/browser/ws-api/ws.intercept.client.browser.test.ts index 3b0e2a359..8fddd4e3d 100644 --- a/test/browser/ws-api/ws.intercept.client.browser.test.ts +++ b/test/browser/ws-api/ws.intercept.client.browser.test.ts @@ -59,7 +59,9 @@ test('intercepts outgoing client text message', async ({ const worker = setupWorker( service.addEventListener('connection', ({ client }) => { client.addEventListener('message', (event) => { - resolve(event.data) + if (typeof event.data === 'string') { + resolve(event.data) + } }) }), ) @@ -91,7 +93,9 @@ test('intercepts outgoing client Blob message', async ({ const worker = setupWorker( service.addEventListener('connection', ({ client }) => { client.addEventListener('message', (event) => { - resolve(event.data.text()) + if (event.data instanceof Blob) { + resolve(event.data.text()) + } }) }), ) @@ -123,7 +127,9 @@ test('intercepts outgoing client ArrayBuffer message', async ({ const worker = setupWorker( service.addEventListener('connection', ({ client }) => { client.addEventListener('message', (event) => { - resolve(new TextDecoder().decode(event.data)) + if (event.data instanceof Uint8Array) { + resolve(new TextDecoder().decode(event.data)) + } }) }), ) diff --git a/test/browser/ws-api/ws.intercept.server.browser.test.ts b/test/browser/ws-api/ws.intercept.server.browser.test.ts index 006bf17dd..34dd7c9e5 100644 --- a/test/browser/ws-api/ws.intercept.server.browser.test.ts +++ b/test/browser/ws-api/ws.intercept.server.browser.test.ts @@ -43,7 +43,9 @@ test('intercepts incoming server text message', async ({ service.addEventListener('connection', ({ server }) => { server.connect() server.addEventListener('message', (event) => { - resolve(event.data) + if (typeof event.data === 'string') { + resolve(event.data) + } }) }), ) @@ -91,7 +93,9 @@ test('intercepts incoming server Blob message', async ({ service.addEventListener('connection', ({ server }) => { server.connect() server.addEventListener('message', (event) => { - resolve(event.data.text()) + if (event.data instanceof Blob) { + resolve(event.data.text()) + } }) }), ) @@ -137,7 +141,7 @@ test('intercepts outgoing server ArrayBuffer message', async ({ service.addEventListener('connection', ({ server }) => { server.connect() server.addEventListener('message', (event) => { - resolve(new TextDecoder().decode(event.data)) + resolve(new TextDecoder().decode(event.data as Uint8Array)) }) }), )