From f236e2513a1b917d76d64c10dd51761d93bb90dd Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Mon, 15 Jan 2024 07:44:43 +0000 Subject: [PATCH] fix: cannot read body twice (#19750) * fix: cannot read body twice * only read it once no matter what * fix tests but yucky * nicer * does this mean backend checks won't incorrectly run * comment --- .github/workflows/ci-backend.yml | 4 +++- frontend/src/lib/api.ts | 7 ++++--- .../player/sessionRecordingDataLogic.test.ts | 1 + jest.setup.ts | 6 ++++++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-backend.yml b/.github/workflows/ci-backend.yml index a1a38a751c6..f62f5879353 100644 --- a/.github/workflows/ci-backend.yml +++ b/.github/workflows/ci-backend.yml @@ -61,8 +61,10 @@ jobs: # the dependencies more clear if we separated the backend/frontend # code completely # really we should ignore ee/frontend/** but dorny doesn't support that + # - '!ee/frontend/**' + # including the negated rule appears to work + # but makes it always match because the checked file always isn't `ee/frontend/**` 🙈 - 'ee/**/*' - - '!ee/frontend/**' - 'posthog/**/*' - 'bin/*.py' - requirements.txt diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 502946a9a07..854e5b657e4 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -1555,17 +1555,18 @@ const api = { .withQueryString(toParams({ source: 'blob', blob_key: blobKey, version: '2' })) .getResponse() + const contentBuffer = new Uint8Array(await response.arrayBuffer()) try { - const textLines = await response.text() + const textDecoder = new TextDecoder() + const textLines = textDecoder.decode(contentBuffer) if (textLines) { return textLines.split('\n') } } catch (e) { - // Must be gzipped + // we assume it is gzipped, swallow the error, and carry on below } - const contentBuffer = new Uint8Array(await response.arrayBuffer()) return strFromU8(decompressSync(contentBuffer)).trim().split('\n') }, diff --git a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts index adf0e836d45..e75910bb916 100644 --- a/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts +++ b/frontend/src/scenes/session-recordings/player/sessionRecordingDataLogic.test.ts @@ -127,6 +127,7 @@ describe('sessionRecordingDataLogic', () => { }) resumeKeaLoadersErrors() }) + it('fetch metadata success and snapshots error', async () => { silenceKeaLoadersErrors() // Unmount and remount the logic to trigger fetching the data again after the mock change diff --git a/jest.setup.ts b/jest.setup.ts index 847624fd022..cab389d3d46 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1,6 +1,12 @@ import 'whatwg-fetch' import 'jest-canvas-mock' +import { TextEncoder, TextDecoder } from 'util' +// Jest/JSDom don't know about TextEncoder but the browsers we support do +// https://github.com/jsdom/jsdom/issues/2524 +global.TextDecoder = TextDecoder +global.TextEncoder = TextEncoder + window.scrollTo = jest.fn() window.matchMedia = jest.fn( () => ({ matches: false, addListener: jest.fn(), removeListener: jest.fn() } as MediaQueryList)