-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
135 lines (112 loc) · 2.97 KB
/
cli.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { deepStrictEqual, throws } from 'node:assert/strict'
import { createReadStream, readFileSync } from 'node:fs';
import { Readable } from 'node:stream'
import { buffer, text } from 'node:stream/consumers'
import { TransformStream } from 'node:stream/web';
import test, { describe } from 'node:test'
import cli from 'esdipi/cli'
describe('clean-sdp', async function()
{
const testCases = [
[
'empty SDP',
Readable.from(''),
Buffer.alloc(0)
],
[
'Offer SDP',
createReadStream('test/sdp/offer.sdp', 'utf8'),
readFileSync('test/sdp/offer-clean.sdp')
],
[
'Answer SDP',
createReadStream('test/sdp/answer.sdp', 'utf8'),
readFileSync('test/sdp/answer-clean.sdp')
]
]
await Promise.all(testCases.map(async function([title, input, expected])
{
await test(title, async function()
{
const stdinWeb = Readable.toWeb(input)
const { readable, writable } = new TransformStream
cli(stdinWeb, writable, 'clean-sdp')
const result = await buffer(readable)
deepStrictEqual(result, expected)
})
}))
})
describe('compress', async function()
{
const testCases = [
[
'empty SDP',
Readable.from(''),
Buffer.alloc(0)
],
[
'Offer SDP',
createReadStream('test/sdp/offer.sdp', 'utf8'),
readFileSync('test/sdp/offer.esdipi')
],
[
'Answer SDP',
createReadStream('test/sdp/answer.sdp', 'utf8'),
readFileSync('test/sdp/answer.esdipi')
]
]
await Promise.all(testCases.map(async function([title, input, expected])
{
await test(title, async function()
{
const stdinWeb = Readable.toWeb(input)
const { readable, writable } = new TransformStream
cli(stdinWeb, writable, 'compress')
const result = await buffer(readable)
deepStrictEqual(result, expected)
})
}))
})
describe('decompress', async function()
{
const testCases = [
[
'empty esdipi',
Readable.from(''),
''
],
[
'Offer esdipi',
createReadStream('test/sdp/offer.esdipi'),
readFileSync('test/sdp/offer.sdp', 'utf8')
],
[
'Answer esdipi',
createReadStream('test/sdp/answer.esdipi'),
readFileSync('test/sdp/answer.sdp', 'utf8')
]
]
await Promise.all(testCases.map(async function([title, input, expected])
{
await test(title, async function()
{
const stdinWeb = Readable.toWeb(input)
const { readable, writable } = new TransformStream
cli(stdinWeb, writable, 'decompress')
const result = await text(readable)
deepStrictEqual(result, expected)
})
}))
})
test('prefix', async function()
{
const expected = readFileSync('test/prefix.txt', 'utf8')
const { readable, writable } = new TransformStream
cli(null, writable, 'prefix')
const result = await text(readable)
deepStrictEqual(result, expected)
})
test('unknown command', function()
{
throws(cli, `Missing or unknown subcommand: undefined`)
})