-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodec.test.ts
More file actions
25 lines (21 loc) · 817 Bytes
/
Copy pathcodec.test.ts
File metadata and controls
25 lines (21 loc) · 817 Bytes
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
import { describe, expect, it } from 'vitest';
import { decodeProtocolRequest, encodeProtocolMessage } from './codec.js';
describe('protocol codec', () => {
it('has a stable line-oriented JSON representation', () => {
const request = {
id: 1,
method: 'initialize' as const,
params: { client: 'protocol-test' },
};
expect(encodeProtocolMessage(request)).toBe(
'{"id":1,"method":"initialize","params":{"client":"protocol-test"}}',
);
expect(decodeProtocolRequest(encodeProtocolMessage(request))).toEqual(request);
});
it.each(['{}', '{"id":1,"method":"unknown"}', '{"id":1,"method":"initialize","params":[]}'])(
'rejects an invalid request: %s',
(raw) => {
expect(() => decodeProtocolRequest(raw)).toThrow('invalid protocol request');
},
);
});