-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathDevToolsConnectionAdapter.test.ts
More file actions
63 lines (48 loc) · 1.82 KB
/
DevToolsConnectionAdapter.test.ts
File metadata and controls
63 lines (48 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import assert from 'node:assert';
import {describe, it} from 'node:test';
import sinon from 'sinon';
import {DevToolsConnectionAdapter} from '../src/DevToolsConnectionAdapter.js';
import {type ConnectionTransport} from '../src/third_party/index.js';
class MockTransport implements ConnectionTransport {
onmessage: ((message: string) => void) | undefined;
onclose: (() => void) | undefined;
send(message: string): void {}
close(): void {}
}
describe('DevToolsConnectionAdapter', () => {
it('should pass messages from transport to onMessage', () => {
const transport = new MockTransport();
const adapter = new DevToolsConnectionAdapter(transport);
const onMessage = sinon.spy();
adapter.setOnMessage(onMessage);
transport.onmessage?.('test message');
assert.ok(onMessage.calledOnceWith('test message'));
});
it('should call onDisconnect when transport closes', () => {
const transport = new MockTransport();
const adapter = new DevToolsConnectionAdapter(transport);
const onDisconnect = sinon.spy();
adapter.setOnDisconnect(onDisconnect);
transport.onclose?.();
assert.ok(onDisconnect.calledOnce);
});
it('should send messages through the transport', () => {
const transport = new MockTransport();
const spy = sinon.spy(transport, 'send');
const adapter = new DevToolsConnectionAdapter(transport);
adapter.sendRawMessage('test message');
assert.ok(spy.calledOnceWith('test message'));
});
it('should close the transport on disconnect', async () => {
const transport = new MockTransport();
const spy = sinon.spy(transport, 'close');
const adapter = new DevToolsConnectionAdapter(transport);
await adapter.disconnect();
assert.ok(spy.calledOnce);
});
});