0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 13:39:22 +01:00

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
This commit is contained in:
Paul D'Ambra 2024-01-15 07:44:43 +00:00 committed by GitHub
parent f09c76e0dd
commit f236e2513a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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')
},

View File

@ -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

View File

@ -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)