|
1 | 1 | import bodyParser from "body-parser"
|
2 | 2 | import * as express from "express"
|
| 3 | +import { proxy } from "../../src/node/proxy" |
| 4 | +// import { proxy } from "../../src/node/proxy" |
3 | 5 | import * as httpserver from "../utils/httpserver"
|
4 | 6 | import * as integration from "../utils/integration"
|
5 | 7 |
|
@@ -147,3 +149,44 @@ describe("proxy", () => {
|
147 | 149 | expect(resp.statusText).toMatch("Internal Server Error")
|
148 | 150 | })
|
149 | 151 | })
|
| 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