-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
64 lines (50 loc) · 1.72 KB
/
test.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
import fs from 'fs'
import zlib from 'zlib'
import test from 'ava'
import pEvent from 'p-event'
import m from '.'
const fixture = fs.readFileSync('test.js', 'utf8')
test('get the brotli-compressed size', async (t) => {
t.true(await m(fixture) < fixture.length)
})
test('brotli compression level', async (t) => {
t.true(await m(fixture, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 6 } }) > await m(fixture))
})
test('sync - get the brotli-compressed size', (t) => {
t.true(m.sync(fixture) < fixture.length)
})
test('sync - match async version', async (t) => {
t.is(m.sync(fixture), await m(fixture))
})
test('sync - brotli compression level', (t) => {
t.true(m.sync(fixture, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 6 } }) < m.sync(fixture, { params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 1 } }))
})
test('stream', async (t) => {
const stream = fs.createReadStream('test.js').pipe(m.stream())
await pEvent(stream, 'end')
t.is(stream.brotliSize, m.sync(fixture))
})
test('brotli-size event', async (t) => {
const stream = fs.createReadStream('test.js').pipe(m.stream())
const size = await pEvent(stream, 'brotli-size')
t.is(size, m.sync(fixture))
})
test('passthrough', async (t) => {
let out = ''
const stream = fs.createReadStream('test.js')
.pipe(m.stream())
.on('data', (buffer) => {
out += buffer
})
await pEvent(stream, 'end')
t.is(out, fixture)
})
test('file - get the brotli-compressed size', async (t) => {
t.true(await m.file('test.js') < fixture.length)
})
test('fileSync - get the brotli-compressed size', (t) => {
t.is(m.fileSync('test.js'), m.sync(fixture))
})
test('file - match async version', async (t) => {
t.is(await m.file('test.js'), await m(fixture))
})