-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
55 lines (51 loc) · 1.25 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
import TestRunner from 'test-runner'
import ConditionalGet from 'lws-conditional-get'
import Lws from 'lws'
import url from 'url'
import fetch from 'node-fetch'
import { strict as a } from 'assert'
const tom = new TestRunner.Tom()
tom.test('simple', async function () {
const port = 8000 + this.index
class One {
middleware () {
return function (ctx) {
ctx.body = 'one'
}
}
}
const lws = await Lws.create({
port,
stack: [ ConditionalGet, One ]
})
const response = await fetch(`http://localhost:${port}/`)
const etag = response.headers.get('etag')
const response2 = await fetch(`http://localhost:${port}/`, {
headers: {
'If-None-Match': etag
}
})
lws.server.close()
a.equal(response.status, 200)
a.equal(response2.status, 304)
})
tom.test('disabled', async function () {
const port = 8000 + this.index
class One {
middleware () {
return function (ctx) {
ctx.body = 'one'
}
}
}
const lws = await Lws.create({
port,
stack: [ ConditionalGet, One ],
noConditionalGet: true
})
const response = await fetch(`http://localhost:${port}/`)
lws.server.close()
a.equal(response.status, 200)
a.equal(response.headers.get('etag'), null)
})
export default tom