Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b83d6ca

Browse files
committedJul 26, 2021
wip: testing proxy
1 parent e4fecc9 commit b83d6ca

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
 

‎test/unit/proxy.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import bodyParser from "body-parser"
22
import * as express from "express"
3+
import { proxy } from "../../src/node/proxy"
4+
// import { proxy } from "../../src/node/proxy"
35
import * as httpserver from "../utils/httpserver"
46
import * as integration from "../utils/integration"
57

@@ -147,3 +149,44 @@ describe("proxy", () => {
147149
expect(resp.statusText).toMatch("Internal Server Error")
148150
})
149151
})
152+
153+
describe("proxy (standalone)", () => {
154+
const testServer = new httpserver.HttpServer()
155+
const proxyServer = proxy
156+
let expressServer: express.Express
157+
158+
beforeAll(async () => {
159+
await testServer.listen((req, res) => {
160+
expressServer(req, res)
161+
})
162+
await proxyServer.listen(testServer.port())
163+
})
164+
165+
afterAll(async () => {
166+
await testServer.close()
167+
await proxyServer.close()
168+
})
169+
170+
beforeEach(() => {
171+
expressServer = express.default()
172+
})
173+
174+
it("should handle errors", async () => {
175+
// Notes: I think I'm close
176+
// but I think this code is testing that our fake expressServer
177+
// is returning a 500
178+
// not the proxy
179+
expressServer.post("/error", (req, res) => {
180+
throw new Error("BROKEN")
181+
})
182+
183+
const resp = await testServer.fetch(`/error`, {
184+
method: "post",
185+
body: JSON.stringify("coder is the best"),
186+
headers: {
187+
"Content-Type": "application/json",
188+
},
189+
})
190+
expect(resp.status).toBe(500)
191+
})
192+
})

0 commit comments

Comments
 (0)
Please sign in to comment.