Skip to content

Commit

Permalink
test: enable vercel-edge test
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 3, 2023
1 parent 0793451 commit 7951532
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 16 deletions.
30 changes: 30 additions & 0 deletions test/presets/vercel-edge.test.ts
Original file line number Diff line number Diff line change
@@ -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;
};
});
});
15 changes: 0 additions & 15 deletions test/presets/vercel.test.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand Down Expand Up @@ -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;
};
});
});
4 changes: 3 additions & 1 deletion test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 7951532

Please sign in to comment.