}
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)
},
}
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')
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')
})
})
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
}
)