-
Notifications
You must be signed in to change notification settings - Fork 16
/
echo.test.ts
39 lines (32 loc) · 831 Bytes
/
echo.test.ts
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
import anyTest, { TestFn } from "ava"
const test = anyTest as TestFn<{ port: number }>
import { Straightforward, middleware } from "../src"
import got from "got-cjs"
import { makeProxyAgents, timeout } from "./utils"
let basePort = 10300
test.beforeEach((t) => {
t.context.port = basePort += 1
})
test("will echo requests", async (t) => {
const port = t.context.port
const sf = new Straightforward()
sf.onRequest.use(middleware.echo)
await sf.listen(port)
const data = (await got("http://example.com", {
agent: makeProxyAgents(port),
}).json()) as any
t.deepEqual(data, {
url: "http://example.com/",
locals: {
isConnect: false,
urlParts: {
host: "example.com",
port: 80,
path: "/",
},
},
})
t.is(sf.stats.onRequest, 1)
sf.close()
t.pass()
})