From 79515320c172adbc173b6f28bb323a560a3baee0 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 3 May 2023 23:24:49 +0200 Subject: [PATCH] test: enable `vercel-edge` test --- test/presets/vercel-edge.test.ts | 30 ++++++++++++++++++++++++++++++ test/presets/vercel.test.ts | 15 --------------- test/tests.ts | 4 +++- 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 test/presets/vercel-edge.test.ts diff --git a/test/presets/vercel-edge.test.ts b/test/presets/vercel-edge.test.ts new file mode 100644 index 0000000000..971133f0c4 --- /dev/null +++ b/test/presets/vercel-edge.test.ts @@ -0,0 +1,30 @@ +import { promises as fsp } from "node:fs"; +import { resolve } from "pathe"; +import { describe, it, expect } from "vitest"; +import { EdgeRuntime } from "edge-runtime"; +import { setupTest, startServer, testNitro } from "../tests"; + +describe("nitro:preset:vercel-edge", async () => { + const ctx = await setupTest("vercel-edge"); + testNitro(ctx, async () => { + // TODO: Add add-event-listener + const entry = resolve(ctx.outDir, "functions/__nitro.func/index.mjs"); + const initialCode = await fsp.readFile(entry, "utf8"); + const runtime = new EdgeRuntime(); + runtime.evaluate( + initialCode.replace( + "export{handleEvent as default}", + "globalThis.handleEvent = handleEvent" + ) + ); + return async ({ url, headers }) => { + const res = await runtime.evaluate( + `handleEvent({ + url: new URL("http://localhost${url}"), + headers: new Headers(${JSON.stringify(headers || {})}) + })` + ); + return res; + }; + }); +}); diff --git a/test/presets/vercel.test.ts b/test/presets/vercel.test.ts index 15e6975419..cd7bbb5373 100644 --- a/test/presets/vercel.test.ts +++ b/test/presets/vercel.test.ts @@ -1,7 +1,6 @@ import { promises as fsp } from "node:fs"; import { resolve } from "pathe"; import { describe, it, expect } from "vitest"; -import { EdgeRuntime } from "edge-runtime"; import { setupTest, startServer, testNitro } from "../tests"; describe("nitro:preset:vercel", async () => { @@ -154,17 +153,3 @@ describe("nitro:preset:vercel", async () => { } ); }); - -describe.skip("nitro:preset:vercel-edge", async () => { - const ctx = await setupTest("vercel-edge"); - testNitro(ctx, async () => { - // TODO: Add add-event-listener - const entry = resolve(ctx.outDir, "functions/__nitro.func/index.mjs"); - const entryCode = await fsp.readFile(entry, "utf8"); - const runtime = new EdgeRuntime({ initialCode: entryCode }); - return async ({ url }) => { - const res = await runtime.dispatchFetch("http://localhost" + url); - return res; - }; - }); -}); diff --git a/test/tests.ts b/test/tests.ts index 6122981e4a..99b11b176f 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -334,7 +334,9 @@ export function testNitro( sharedRuntimeConfig: { dynamic: // TODO - ctx.preset.includes("cloudflare") || ctx.preset === "nitro-dev" + ctx.preset.includes("cloudflare") || + ctx.preset === "vercel-edge" || + ctx.preset === "nitro-dev" ? "initial" : "from-env", app: {