-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.test.ts
45 lines (41 loc) · 1.2 KB
/
index.test.ts
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
import { assert, test } from 'vitest'
import Parser from './index'
const inputs = [
':hitchcock.freenode.net NOTICE * :*** Looking up your hostname...\r\n',
'ERROR :Closing Link: 127.0.0.1 (Connection timed out)\r\n',
':[email protected] JOIN #express\r\n',
]
const expected = [
{
prefix: 'hitchcock.freenode.net',
command: 'NOTICE',
params: '*',
trailing: '*** Looking up your hostname...',
string: ':hitchcock.freenode.net NOTICE * :*** Looking up your hostname...',
},
{
prefix: '',
command: 'ERROR',
params: '',
trailing: 'Closing Link: 127.0.0.1 (Connection timed out)',
string: 'ERROR :Closing Link: 127.0.0.1 (Connection timed out)',
},
{
prefix: '[email protected]',
command: 'JOIN',
params: '#express',
trailing: '',
string:
':[email protected] JOIN #express',
},
]
test('should emit "message" events', () => {
const parser = new Parser()
let n = 0
parser.on('message', (msg) => {
assert.deepEqual(expected[n++], msg)
})
for (const line of inputs) {
parser.write(Buffer.from(line))
}
})