From 6abbf542c66ffe2f9461e5a66c18476d8b2b8389 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 12 Feb 2026 20:15:51 +0100 Subject: [PATCH] fix(tests): use bodyBuffer for binary gzip data in MockServerResponse Buffer.from(string, 'binary') loses data on Windows due to encoding differences. Store raw Buffer directly for binary content like gzip. --- tests/charging-station/ui-server/UIHttpServer.test.ts | 5 +++-- tests/charging-station/ui-server/UIServerTestUtils.ts | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/charging-station/ui-server/UIHttpServer.test.ts b/tests/charging-station/ui-server/UIHttpServer.test.ts index 33803562..5df5f6d1 100644 --- a/tests/charging-station/ui-server/UIHttpServer.test.ts +++ b/tests/charging-station/ui-server/UIHttpServer.test.ts @@ -255,8 +255,9 @@ await describe('UIHttpServer test suite', async () => { 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 expect(parsedBody.status).toBe('success') expect(parsedBody.data).toBe(largeData) diff --git a/tests/charging-station/ui-server/UIServerTestUtils.ts b/tests/charging-station/ui-server/UIServerTestUtils.ts index 0c1b8f72..6a604123 100644 --- a/tests/charging-station/ui-server/UIServerTestUtils.ts +++ b/tests/charging-station/ui-server/UIServerTestUtils.ts @@ -52,6 +52,7 @@ export const createMockUIServerConfigurationWithAuth = ( export class MockServerResponse extends EventEmitter { public body?: string + public bodyBuffer?: Buffer public ended = false public headers: Record = {} public statusCode?: number @@ -61,7 +62,8 @@ export class MockServerResponse extends EventEmitter { 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') -- 2.53.0