-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
85 lines (65 loc) · 1.5 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const {PassThrough} = require('stream')
const duplexify = require('duplexify')
const Finest = require('.')
const {performance: {now}} = require('perf_hooks')
test('basic', function(done)
{
expect.assertions(4)
const delay = 1000
const expected = 'asdf'
let finest_finish
let downstream_finish
const upstream = new PassThrough
const downstream = new PassThrough
upstream.on('data', downstream.write.bind(downstream))
const finest = new Finest(duplexify(upstream, downstream))
upstream.on('data', function(data)
{
expect(data.toString()).toBe(expected)
})
finest.on('data', function(data)
{
expect(data.toString()).toBe(expected)
setTimeout(downstream.end.bind(downstream), delay)
})
downstream.once('finish', function()
{
downstream_finish = now()
})
finest.once('finish', function()
{
finest_finish = now()
})
Promise.all([
new Promise(function(resolve, reject)
{
upstream.once('end', function()
{
try {
expect(now() - finest_finish).toBeGreaterThan(delay)
}
catch(e)
{
return reject(e)
}
resolve()
})
}),
new Promise(function(resolve, reject)
{
finest.once('end', function()
{
try {
expect(now() - downstream_finish).toBeLessThan(50)
}
catch(e)
{
return reject(e)
}
resolve()
})
})
])
.then(done.bind(null, null), done)
finest.end(expected)
})