Skip to content

Commit

Permalink
test: pass body to vercel-edge test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hebilicious committed Jun 17, 2023
1 parent 9c8f09b commit 7fbb874
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
3 changes: 1 addition & 2 deletions test/fixture/actions/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ async function respondWithResponse(event: H3Event, response: Response) {
}

function actionResponse(event: H3Event, data: any, action?: any) {
// return { data, action };
return respondWithResponse(
event,
new Response(JSON.stringify({ data, action }))
new Response(JSON.stringify({ data, action }), { status: 200 })
);
}

Expand Down
7 changes: 5 additions & 2 deletions test/presets/vercel-edge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ describeIf(!isWindows, "nitro:preset:vercel-edge", async () => {
"globalThis.handleEvent = handleEvent"
)
);
return async ({ url, headers }) => {
return async ({ url, headers, method = "GET", body }) => {
const res = await runtime.evaluate(
`handleEvent({
url: new URL("http://localhost${url}"),
headers: new Headers(${JSON.stringify(headers || {})})
method: ${JSON.stringify(method)},
headers: new Headers(${JSON.stringify(headers || {})}),
body: ${JSON.stringify(body)},
arrayBuffer: () => Promise.resolve(${JSON.stringify(body)})
})`
);
return res;
Expand Down
16 changes: 11 additions & 5 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,15 @@ export async function setupTest(preset: string) {
dev: ctx.isDev,
rootDir: ctx.rootDir,
buildDir: resolve(fixtureDir, presetTempDir, ".nitro"),
handlers: [{ route: "/action", handler: "~/actions/action.ts", lazy: true, formAction: true }],
handlers: [
{
route: "/action",
handler: "~/actions/action.ts",
lazy: true,
formAction: true,
},
],
renderer: "~/renderer.ts",
minify: false,
serveStatic:
preset !== "cloudflare" &&
preset !== "cloudflare-module" &&
Expand Down Expand Up @@ -161,11 +167,11 @@ export function testNitro(
const { data: actionData } = await callHandler({
url: "/action",
method: "POST",
body: JSON.stringify({ hello: "world" })
})
body: JSON.stringify({ hello: "world" }),
});
expect(actionData).to.toMatchObject({ data: { hello: "world" } });
});

it("handles route rules - redirects", async () => {
const base = await callHandler({ url: "/rules/redirect" });
expect(base.status).toBe(307);
Expand Down

0 comments on commit 7fbb874

Please sign in to comment.