From 7fbb87453531e6599264920730ae092824d2df89 Mon Sep 17 00:00:00 2001 From: Hebilicious Date: Mon, 12 Jun 2023 23:36:35 +0700 Subject: [PATCH] test: pass body to vercel-edge test --- test/fixture/actions/action.ts | 3 +-- test/presets/vercel-edge.test.ts | 7 +++++-- test/tests.ts | 16 +++++++++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/test/fixture/actions/action.ts b/test/fixture/actions/action.ts index a30ab2a1c3..f311c62af4 100644 --- a/test/fixture/actions/action.ts +++ b/test/fixture/actions/action.ts @@ -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 }) ); } diff --git a/test/presets/vercel-edge.test.ts b/test/presets/vercel-edge.test.ts index 49336df0dc..e1d8b691a3 100644 --- a/test/presets/vercel-edge.test.ts +++ b/test/presets/vercel-edge.test.ts @@ -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; diff --git a/test/tests.ts b/test/tests.ts index f62a3289e1..b1c678691b 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -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" && @@ -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);