Buffer.from(string, 'binary') loses data on Windows due to encoding
differences. Store raw Buffer directly for binary content like gzip.
setTimeout(resolve, 50)
})
- expect(res.body).toBeDefined()
- const decompressed = gunzipSync(Buffer.from(res.body ?? '', 'binary')).toString('utf8')
+ expect(res.bodyBuffer).toBeDefined()
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+ const decompressed = gunzipSync(res.bodyBuffer!).toString('utf8')
const parsedBody = JSON.parse(decompressed) as Record<string, unknown>
expect(parsedBody.status).toBe('success')
expect(parsedBody.data).toBe(largeData)
export class MockServerResponse extends EventEmitter {
public body?: string
+ public bodyBuffer?: Buffer
public ended = false
public headers: Record<string, string> = {}
public statusCode?: number
if (data != null) {
this.body = data
} else if (this.chunks.length > 0) {
- this.body = Buffer.concat(this.chunks).toString()
+ this.bodyBuffer = Buffer.concat(this.chunks)
+ this.body = this.bodyBuffer.toString('binary')
}
this.ended = true
this.emit('finish')