-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
49 lines (42 loc) · 1.03 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
const AppMgr = require('appmgr')
const delay = require('delay')
const debug = require('debug')('pagemon-test')
const pagemon = require('.')
const test = require('tape')
test(async (t) => {
const msg = 'this page was slow'
const m = new AppMgr({port: 0})
let slowCalled = 0
m.app.get('/slow', async (req, res) => {
slowCalled++
await delay(1000)
res.send(msg)
})
await m.start()
const url = m.siteurl + '/slow'
const mon = new pagemon.Monitor()
const run = async () => {
const t0 = new Date()
const g1 = await mon.got(url)
t.equal(g1.body, msg)
const t1 = new Date()
const dur = t1 - t0
debug('duration=%dms', dur)
return dur
}
const d1 = await run()
t.assert(d1 > 800)
t.assert(d1 < 1500)
const d2 = await run()
t.assert(d2 < 100)
// actually, it's not just fast, it's synchronous:
let ticks = 0
process.nextTick(() => { ticks++ })
const d3 = await run()
t.equal(ticks, 0)
t.assert(d3 < 100)
t.equal(slowCalled, 1)
await mon.stop()
await m.stop()
t.end()
})