Skip to content

Commit

Permalink
test(vercel): move custom test to additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 17, 2023
1 parent 044bb6a commit fb361f8
Showing 1 changed file with 128 additions and 123 deletions.
251 changes: 128 additions & 123 deletions test/presets/vercel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,136 +6,141 @@ import { setupTest, startServer, testNitro } from "../tests";

describe("nitro:preset:vercel", async () => {
const ctx = await setupTest("vercel");
testNitro(ctx, async () => {
const handle = await import(
resolve(ctx.outDir, "functions/__nitro.func/index.mjs")
).then((r) => r.default || r);
await startServer(ctx, handle);
return async ({ url }) => {
const res = await ctx.fetch(url);
return res;
};
});
it("should add route rules to config", async () => {
const config = await fsp
.readFile(resolve(ctx.outDir, "config.json"), "utf8")
.then((r) => JSON.parse(r));
expect(config).toMatchInlineSnapshot(`
{
"overrides": {
"api/hey/index.html": {
"path": "api/hey",
},
"api/param/foo.json/index.html": {
"path": "api/param/foo.json",
},
"api/param/prerender1/index.html": {
"path": "api/param/prerender1",
},
"api/param/prerender3/index.html": {
"path": "api/param/prerender3",
},
"api/param/prerender4/index.html": {
"path": "api/param/prerender4",
},
"prerender/index.html": {
"path": "prerender",
},
},
"routes": [
{
"headers": {
"Location": "https://nitro.unjs.io/",
},
"src": "/rules/redirect/obj",
"status": 308,
},
{
"headers": {
"Location": "/other",
testNitro(
ctx,
async () => {
const handle = await import(
resolve(ctx.outDir, "functions/__nitro.func/index.mjs")
).then((r) => r.default || r);
await startServer(ctx, handle);
return async ({ url }) => {
const res = await ctx.fetch(url);
return res;
};
},
() => {
it("should add route rules to config", async () => {
const config = await fsp
.readFile(resolve(ctx.outDir, "config.json"), "utf8")
.then((r) => JSON.parse(r));
expect(config).toMatchInlineSnapshot(`
{
"overrides": {
"api/hey/index.html": {
"path": "api/hey",
},
"src": "/rules/nested/override",
"status": 307,
},
{
"headers": {
"cache-control": "s-maxage=60",
"api/param/foo.json/index.html": {
"path": "api/param/foo.json",
},
"src": "/rules/headers",
},
{
"headers": {
"access-control-allow-headers": "*",
"access-control-allow-methods": "GET",
"access-control-allow-origin": "*",
"access-control-max-age": "0",
},
"src": "/rules/cors",
},
{
"headers": {
"Location": "/base",
"api/param/prerender1/index.html": {
"path": "api/param/prerender1",
},
"src": "/rules/redirect",
"status": 307,
},
{
"headers": {
"Location": "/base",
"x-test": "test",
"api/param/prerender3/index.html": {
"path": "api/param/prerender3",
},
"src": "/rules/nested/.*",
"status": 307,
},
{
"headers": {
"cache-control": "public, max-age=3600, immutable",
"api/param/prerender4/index.html": {
"path": "api/param/prerender4",
},
"src": "/build/.*",
},
{
"continue": true,
"headers": {
"cache-control": "public,max-age=31536000,immutable",
"prerender/index.html": {
"path": "prerender",
},
"src": "/build(.*)",
},
{
"handle": "filesystem",
},
{
"dest": "/__nitro",
"src": "/rules/_/cached/noncached",
},
{
"dest": "/__nitro",
"src": "(?<url>/rules/_/noncached/.*)",
},
{
"dest": "/__nitro--rules---cached?url=$url",
"src": "(?<url>/rules/_/cached/.*)",
},
{
"dest": "/__nitro",
"src": "/rules/dynamic",
},
{
"dest": "/__nitro--rules-swr?url=$url",
"src": "(?<url>/rules/swr/.*)",
},
{
"dest": "/__nitro--rules-swr-ttl?url=$url",
"src": "(?<url>/rules/swr-ttl/.*)",
},
{
"dest": "/__nitro",
"src": "/(.*)",
},
],
"version": 3,
}
`);
});
"routes": [
{
"headers": {
"Location": "https://nitro.unjs.io/",
},
"src": "/rules/redirect/obj",
"status": 308,
},
{
"headers": {
"Location": "/other",
},
"src": "/rules/nested/override",
"status": 307,
},
{
"headers": {
"cache-control": "s-maxage=60",
},
"src": "/rules/headers",
},
{
"headers": {
"access-control-allow-headers": "*",
"access-control-allow-methods": "GET",
"access-control-allow-origin": "*",
"access-control-max-age": "0",
},
"src": "/rules/cors",
},
{
"headers": {
"Location": "/base",
},
"src": "/rules/redirect",
"status": 307,
},
{
"headers": {
"Location": "/base",
"x-test": "test",
},
"src": "/rules/nested/.*",
"status": 307,
},
{
"headers": {
"cache-control": "public, max-age=3600, immutable",
},
"src": "/build/.*",
},
{
"continue": true,
"headers": {
"cache-control": "public,max-age=31536000,immutable",
},
"src": "/build(.*)",
},
{
"handle": "filesystem",
},
{
"dest": "/__nitro",
"src": "/rules/_/cached/noncached",
},
{
"dest": "/__nitro",
"src": "(?<url>/rules/_/noncached/.*)",
},
{
"dest": "/__nitro--rules---cached?url=$url",
"src": "(?<url>/rules/_/cached/.*)",
},
{
"dest": "/__nitro",
"src": "/rules/dynamic",
},
{
"dest": "/__nitro--rules-swr?url=$url",
"src": "(?<url>/rules/swr/.*)",
},
{
"dest": "/__nitro--rules-swr-ttl?url=$url",
"src": "(?<url>/rules/swr-ttl/.*)",
},
{
"dest": "/__nitro",
"src": "/(.*)",
},
],
"version": 3,
}
`);
});
}
);
});

describe.skip("nitro:preset:vercel-edge", async () => {
Expand Down

0 comments on commit fb361f8

Please sign in to comment.