]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
test(cli): fix lifecycle test structure — single top-level describe
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 15 Apr 2026 18:06:40 +0000 (20:06 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 15 Apr 2026 18:06:40 +0000 (20:06 +0200)
ui/cli/src/client/ws-adapter.ts
ui/cli/tests/lifecycle.test.ts
ui/common/tests/WebSocketClient.test.ts

index 8a8354ce8262d6d024901b970ffa037ce9f21ed5..c7c705651ad6e784e0603f630d86d88e1ad88ef4 100644 (file)
@@ -58,43 +58,43 @@ export const createWsAdapter = (ws: WsWebSocket): WebSocketLike => {
   }
 
   return {
-    close(code?: number, reason?: string): void {
+    close (code?: number, reason?: string): void {
       ws.close(code, reason)
     },
-    get onclose(): ((event: { code: number; reason: string }) => void) | null {
+    get onclose (): ((event: { code: number; reason: string }) => void) | null {
       return oncloseCallback
     },
 
-    set onclose(callback: ((event: { code: number; reason: string }) => void) | null) {
+    set onclose (callback: ((event: { code: number; reason: string }) => void) | null) {
       oncloseCallback = callback
     },
-    get onerror(): ((event: { error: unknown; message: string }) => void) | null {
+    get onerror (): ((event: { error: unknown; message: string }) => void) | null {
       return onerrorCallback
     },
 
-    set onerror(callback: ((event: { error: unknown; message: string }) => void) | null) {
+    set onerror (callback: ((event: { error: unknown; message: string }) => void) | null) {
       onerrorCallback = callback
     },
-    get onmessage(): ((event: { data: string }) => void) | null {
+    get onmessage (): ((event: { data: string }) => void) | null {
       return onmessageCallback
     },
 
-    set onmessage(callback: ((event: { data: string }) => void) | null) {
+    set onmessage (callback: ((event: { data: string }) => void) | null) {
       onmessageCallback = callback
     },
-    get onopen(): (() => void) | null {
+    get onopen (): (() => void) | null {
       return onopenCallback
     },
 
-    set onopen(callback: (() => void) | null) {
+    set onopen (callback: (() => void) | null) {
       onopenCallback = callback
     },
 
-    get readyState(): WebSocketReadyState {
+    get readyState (): WebSocketReadyState {
       return ws.readyState as WebSocketReadyState
     },
 
-    send(data: string): void {
+    send (data: string): void {
       ws.send(data)
     },
   }
index 5b3271df8e3a4816df0326b0e121a652b256a293..0cdf5a54b5cb0c6942ec68e60b6ad651d0188a5b 100644 (file)
@@ -4,7 +4,7 @@ import { describe, it } from 'node:test'
 import { ConnectionError } from '../src/client/errors.js'
 import { executeCommand } from '../src/client/lifecycle.js'
 
-await describe('CLI error types', async () => {
+await describe('lifecycle', async () => {
   await it('should create ConnectionError with url', () => {
     const err = new ConnectionError('ws://localhost:8080')
     assert.strictEqual(err.name, 'ConnectionError')
@@ -17,23 +17,8 @@ await describe('CLI error types', async () => {
     const err = new ConnectionError('ws://localhost:8080', cause)
     assert.strictEqual(err.cause, cause)
   })
-})
-
-await describe('lifecycle deadline sharing', async () => {
-  await it('should compute remaining timeout after connect phase', () => {
-    // This test verifies the deadline sharing logic by checking that:
-    // 1. A budget is computed from timeoutMs or default
-    // 2. startTime is recorded before connect
-    // 3. remaining is computed as budget - elapsed
-    // 4. remaining is passed to sendRequest
-
-    // We verify this indirectly by checking that the code compiles and
-    // the lifecycle module exports executeCommand with the correct signature
-    assert.ok(typeof executeCommand === 'function')
 
-    // The actual deadline sharing is tested via integration:
-    // - WebSocketClient.sendRequest accepts optional timeoutMs parameter
-    // - lifecycle.ts passes remaining budget to sendRequest
-    // Both are verified by their respective unit tests
+  await it('should export executeCommand function', () => {
+    assert.strictEqual(typeof executeCommand, 'function')
   })
 })
index 2c14ef51d9e1ecde69dad6bba54f36c90e1f0a61..1a2848d3e07ea47c7bb79962556c6c8461780362 100644 (file)
@@ -382,7 +382,7 @@ await describe('WebSocketClient', async () => {
         assert.ok(error.message.includes('timed out'))
         assert.ok(error.message.includes('50ms'))
         // Should timeout around 50ms, definitely not 60s
-        assert.ok(elapsed < 500, `Expected timeout within 500ms, got ${elapsed}ms`)
+        assert.ok(elapsed < 500, `Expected timeout within 500ms, got ${elapsed.toString()}ms`)
         return true
       }
     )