]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix(tests): use bodyBuffer for binary gzip data in MockServerResponse
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 12 Feb 2026 19:15:51 +0000 (20:15 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 12 Feb 2026 19:15:51 +0000 (20:15 +0100)
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
tests/charging-station/ui-server/UIServerTestUtils.ts

index 3380356293ef10a100c78db5e3d052843e18ad8b..5df5f6d1d2a174b08817feeb28478593a74b05ca 100644 (file)
@@ -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<string, unknown>
       expect(parsedBody.status).toBe('success')
       expect(parsedBody.data).toBe(largeData)
index 0c1b8f720e7c1bfc053865c9e5990b750dbcd7aa..6a604123654ae169ac5093398f9010f492e7bcd0 100644 (file)
@@ -52,6 +52,7 @@ export const createMockUIServerConfigurationWithAuth = (
 
 export class MockServerResponse extends EventEmitter {
   public body?: string
+  public bodyBuffer?: Buffer
   public ended = false
   public headers: Record<string, string> = {}
   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')