Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 5, 2024
1 parent e57286d commit ac18343
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
7 changes: 5 additions & 2 deletions test/fixture/plugins/vary.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export default defineNitroPlugin((app) => {
app.hooks.hook("request", (event) => {
if (event.path.endsWith(".css")) setResponseHeader(event, "Vary", "Origin");
if (event.path.endsWith(".js"))
if (event.path.endsWith(".css")) {
setResponseHeader(event, "Vary", "Origin");
}
if (event.path.endsWith(".js")) {
setResponseHeader(event, "Vary", ["Origin"]);
}
});
});
68 changes: 36 additions & 32 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,38 +311,42 @@ export function testNitro(
expect(data).toMatch("<h1 >Hello JSX!</h1>");
});

it.skipIf(
ctx.preset.startsWith("cloudflare") || ctx.preset === "vercel-edge"
)("handles custom Vary header", async () => {
let headers = (
await callHandler({
url: "/foo.css",
headers: { "Accept-Encoding": "gzip" },
})
).headers;
if (headers["vary"])
expect(
headers["vary"].includes("Origin") &&
headers["vary"].includes("Accept-Encoding")
).toBeTruthy();

headers = (
await callHandler({ url: "/foo.css", headers: { "Accept-Encoding": "" } })
).headers;
if (headers["vary"]) expect(headers["vary"]).toBe("Origin");

headers = (
await callHandler({
url: "/foo.js",
headers: { "Accept-Encoding": "gzip" },
})
).headers;
if (headers["vary"])
expect(
headers["vary"].includes("Origin") &&
headers["vary"].includes("Accept-Encoding")
).toBeTruthy();
});
it.runIf(ctx.nitro?.options.serveStatic)(
"handles custom Vary header",
async () => {
let headers = (
await callHandler({
url: "/foo.css",
headers: { "Accept-Encoding": "gzip" },
})
).headers;
if (headers["vary"])
expect(
headers["vary"].includes("Origin") &&
headers["vary"].includes("Accept-Encoding")
).toBeTruthy();

headers = (
await callHandler({
url: "/foo.css",
headers: { "Accept-Encoding": "" },
})
).headers;
if (headers["vary"]) expect(headers["vary"]).toBe("Origin");

headers = (
await callHandler({
url: "/foo.js",
headers: { "Accept-Encoding": "gzip" },
})
).headers;
if (headers["vary"])
expect(
headers["vary"].includes("Origin") &&
headers["vary"].includes("Accept-Encoding")
).toBeTruthy();
}
);

it("handles route rules - headers", async () => {
const { headers } = await callHandler({ url: "/rules/headers" });
Expand Down

0 comments on commit ac18343

Please sign in to comment.