From: Jérôme Benoit Date: Wed, 15 Apr 2026 18:06:40 +0000 (+0200) Subject: test(cli): fix lifecycle test structure — single top-level describe X-Git-Tag: v4.5~91 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=711108181080309b92261431c50bce61eb08789b;p=e-mobility-charging-stations-simulator.git test(cli): fix lifecycle test structure — single top-level describe --- diff --git a/ui/cli/src/client/ws-adapter.ts b/ui/cli/src/client/ws-adapter.ts index 8a8354ce..c7c70565 100644 --- a/ui/cli/src/client/ws-adapter.ts +++ b/ui/cli/src/client/ws-adapter.ts @@ -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) }, } diff --git a/ui/cli/tests/lifecycle.test.ts b/ui/cli/tests/lifecycle.test.ts index 5b3271df..0cdf5a54 100644 --- a/ui/cli/tests/lifecycle.test.ts +++ b/ui/cli/tests/lifecycle.test.ts @@ -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') }) }) diff --git a/ui/common/tests/WebSocketClient.test.ts b/ui/common/tests/WebSocketClient.test.ts index 2c14ef51..1a2848d3 100644 --- a/ui/common/tests/WebSocketClient.test.ts +++ b/ui/common/tests/WebSocketClient.test.ts @@ -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 } )