-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
40 lines (31 loc) · 850 Bytes
/
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
const tape = require('tape')
const jsonist = require('jsonist')
const PORT = process.env.PORT = process.env.PORT || require('get-PORT-sync')()
const server = require('./server')
const urlBase = `http://localhost:${PORT}`
tape('should respond hello', (t) => {
jsonist.get(urlBase, (err, body) => {
if (err) t.error(err)
t.equal(body.msg, 'hello')
t.end()
})
})
tape('should respond user-agent', (t) => {
const opts = { headers: { 'User-Agent': 'tape' } }
jsonist.get(`${urlBase}/user-agent`, opts, (err, body) => {
if (err) t.error(err)
t.equal(body.ua, 'tape')
t.end()
})
})
tape('should respond b64', (t) => {
jsonist.get(`${urlBase}/b64/hello`, (err, body) => {
if (err) t.error(err)
t.equal(body.b64, 'aGVsbG8=')
t.end()
})
})
tape('cleanup', function (t) {
server.close()
t.end()
})