From: Jérôme Benoit Date: Thu, 12 Feb 2026 19:15:51 +0000 (+0100) Subject: fix(tests): use bodyBuffer for binary gzip data in MockServerResponse X-Git-Tag: ocpp-server@v2.3.0~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=6abbf542c66ffe2f9461e5a66c18476d8b2b8389;p=e-mobility-charging-stations-simulator.git 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. --- 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')