Skip to content

Commit

Permalink
add e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
conico974 committed Sep 20, 2024
1 parent 0d518d7 commit 0d19aeb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/pages-router/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ const nextConfig = {
eslint: {
ignoreDuringBuilds: true,
},
headers: () => [
{
source: "/",
headers: [
{
key: "x-custom-header",
value: "my custom header value",
},
],
},
],
rewrites: () => [
{ source: "/rewrite", destination: "/", locale: false },
{
Expand Down
13 changes: 13 additions & 0 deletions examples/pages-router/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NextRequest, NextResponse } from "next/server";

export function middleware(request: NextRequest) {

Check warning on line 3 in examples/pages-router/src/middleware.ts

View workflow job for this annotation

GitHub Actions / validate

'request' is defined but never used. Allowed unused args must match /^_/u
return NextResponse.next({
headers: {
"x-from-middleware": "true",
},
});
}

export const config = {
matcher: ["/"],
};
17 changes: 17 additions & 0 deletions packages/tests-e2e/tests/pagesRouter/i18n.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { expect, test } from "@playwright/test";

test("Next config headers with i18n", async ({ page }) => {
const responsePromise = page.waitForResponse((response) => {
return response.status() === 200;
});
await page.goto("/");

const response = await responsePromise;
// Response header should be set
const headers = response.headers();
// Headers from next.config.js should be set
expect(headers["x-custom-header"]).toEqual("my custom header value");

// Headers from middleware should be set
expect(headers["x-from-middleware"]).toEqual("true");
});

0 comments on commit 0d19aeb

Please sign in to comment.