Skip to content

Commit 5a5486a

Browse files
committed
escape hatch e2e tests
1 parent b1ec516 commit 5a5486a

File tree

7 files changed

+181
-13
lines changed

7 files changed

+181
-13
lines changed

e2e/src/express.entrypoint.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {type NextFunction, type Request, type Response, Router} from "express"
22
import {bootstrap} from "./generated/server/express"
3+
import {createEscapeHatchesRouter} from "./routes/express/escape-hatches"
34
import {createRequestHeadersRouter} from "./routes/express/request-headers"
45
import {createValidationRouter} from "./routes/express/validation"
56
import {createErrorResponse} from "./shared"
@@ -9,9 +10,11 @@ function createRouter() {
910

1011
const requestHeadersRouter = createRequestHeadersRouter()
1112
const validationRouter = createValidationRouter()
13+
const escapeHatchesRouter = createEscapeHatchesRouter()
1214

1315
router.use(requestHeadersRouter)
1416
router.use(validationRouter)
17+
router.use(escapeHatchesRouter)
1518

1619
return router
1720
}

e2e/src/generated/server/express/routes/escape-hatches.ts

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/src/generated/server/express/routes/request-headers.ts

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

e2e/src/generated/server/express/routes/validation.ts

Lines changed: 33 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {SkipResponse} from "@nahkies/typescript-express-runtime/server"
2+
import {
3+
type GetEscapeHatchesPlainText,
4+
createRouter,
5+
} from "../../generated/server/express/routes/escape-hatches"
6+
7+
const getEscapeHatchesPlainText: GetEscapeHatchesPlainText = async (
8+
_,
9+
respond,
10+
req,
11+
res,
12+
) => {
13+
res.setHeader("x-ratelimit-remaining", "100")
14+
res.status(200).send("Plain text response")
15+
16+
// TODO: the typescript types are correct, but gets mangled by json serialization
17+
// return respond.with200().body("Plain text response")
18+
19+
return SkipResponse
20+
}
21+
22+
export function createEscapeHatchesRouter() {
23+
return createRouter({
24+
getEscapeHatchesPlainText,
25+
})
26+
}

e2e/src/routes/express/validation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type {ExpressRuntimeResponse} from "@nahkies/typescript-express-runtime/server"
12
import {
23
type GetResponses500,
34
type GetResponsesEmpty,

e2e/src/shared.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
import {ExpressRuntimeError} from "@nahkies/typescript-express-runtime/errors"
12
import {KoaRuntimeError} from "@nahkies/typescript-koa-runtime/errors"
23

34
export function createErrorResponse(err: unknown) {
4-
if (KoaRuntimeError.isKoaError(err) && err.phase !== "request_handler") {
5+
if (
6+
(KoaRuntimeError.isKoaError(err) ||
7+
ExpressRuntimeError.isExpressError(err)) &&
8+
err.phase !== "request_handler"
9+
) {
510
return {
611
status: 400,
712
body: {

0 commit comments

Comments
 (0)