Skip to content

Commit 2e409c8

Browse files
committed
add e2e for next/head
1 parent 8bb7e74 commit 2e409c8

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { InferGetServerSidePropsType } from "next";
2+
import Head from "next/head";
3+
4+
export async function getServerSideProps() {
5+
return {
6+
props: {
7+
time: new Date().toISOString(),
8+
envVar: process.env.SOME_PROD_VAR,
9+
},
10+
};
11+
}
12+
13+
export default function Page({
14+
time,
15+
envVar,
16+
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
17+
return (
18+
<div>
19+
<Head>
20+
<title>OpenNext head</title>
21+
<meta
22+
property="og:title"
23+
content={`OpenNext pages router head ${envVar}`}
24+
/>
25+
<meta property="time" content={time} />
26+
<meta
27+
name="description"
28+
content="OpenNext takes the Next.js build output and converts it into packages that can be deployed across a variety of environments. Natively OpenNext has support for AWS Lambda, Cloudflare, and classic Node.js Server."
29+
/>
30+
</Head>
31+
<p>This is a page!</p>
32+
</div>
33+
);
34+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test.describe("next/head", () => {
4+
test("should have the correct title", async ({ page }) => {
5+
await page.goto("/head");
6+
const title = await page.title();
7+
expect(title).toBe("OpenNext head");
8+
});
9+
test("should have the correct meta tags", async ({ page }) => {
10+
await page.goto("/head");
11+
const ogTitle = await page
12+
.locator('meta[property="og:title"]')
13+
.getAttribute("content");
14+
const ogDesc = await page
15+
.locator('meta[name="description"]')
16+
.getAttribute("content");
17+
const time = await page
18+
.locator('meta[property="time"]')
19+
.getAttribute("content");
20+
expect(ogTitle).toBe("OpenNext pages router head bar");
21+
expect(ogDesc).toBe(
22+
"OpenNext takes the Next.js build output and converts it into packages that can be deployed across a variety of environments. Natively OpenNext has support for AWS Lambda, Cloudflare, and classic Node.js Server.",
23+
);
24+
25+
expect(new Date(time!).getTime()).toBeLessThan(Date.now());
26+
});
27+
});

0 commit comments

Comments
 (0)