Skip to content

Commit 63b7b15

Browse files
committed
improve e2e
1 parent 229f62f commit 63b7b15

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

examples/app-pages-router/pages/[[...page]].tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ import type {
66
} from "next";
77

88
const validRootPages = ["conico974", "kheuzy", "sommeeer"];
9+
const validLongPaths = ["super/long/path/to/secret/page"];
910

1011
export async function getStaticPaths(): Promise<GetStaticPathsResult> {
1112
const rootPaths = validRootPages.map((page) => ({
1213
params: { page: [page] },
1314
}));
1415

15-
const paths = [{ params: { page: [] } }, ...rootPaths];
16+
const longPaths = validLongPaths.map((path) => ({
17+
params: { page: path.split("/") },
18+
}));
19+
20+
const paths = [{ params: { page: [] } }, ...rootPaths, ...longPaths];
1621

1722
return {
1823
paths,
@@ -40,6 +45,10 @@ export async function getStaticProps(context: GetStaticPropsContext) {
4045
};
4146
}
4247

48+
const pagePath = page.join("/");
49+
if (validLongPaths.includes(pagePath)) {
50+
return { props: { subpage: page, pageType: "long-path" } };
51+
}
4352
return { notFound: true };
4453
}
4554

@@ -52,7 +61,8 @@ export default function Page({
5261
}
5362
return (
5463
<div>
55-
<h1>{pageType === "home" ? "Homepage" : `Root page: ${subpage}`}</h1>
64+
<h1 data-testid="page">{`Page: ${subpage}`}</h1>
65+
<p>Page type: {pageType}</p>
5666
<p>Path: {subpage.join("/")}</p>
5767
</div>
5868
);

examples/sst/sst.config.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type { SSTConfig } from "sst";
22

33
import { AppPagesRouter } from "./stacks/AppPagesRouter";
4-
import { AppRouter } from "./stacks/AppRouter";
5-
import { Experimental } from "./stacks/Experimental";
6-
import { PagesRouter } from "./stacks/PagesRouter";
74

85
export default {
96
config(_input) {
@@ -14,9 +11,9 @@ export default {
1411
},
1512
stacks(app) {
1613
app
17-
.stack(AppRouter)
18-
.stack(PagesRouter)
19-
.stack(AppPagesRouter)
20-
.stack(Experimental);
14+
// .stack(AppRouter)
15+
// .stack(PagesRouter)
16+
.stack(AppPagesRouter);
17+
// .stack(Experimental);
2118
},
2219
} satisfies SSTConfig;
Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1-
import { test } from "@playwright/test";
1+
import { test, expect } from "@playwright/test";
22

33
// Going to `/`, `/conico974`, `/kheuzy` and `/sommeeer` should be catched by our `[[...page]]` route.
4-
test("Optional Catch all route in root should work", async ({ page }) => {
5-
await page.goto("/");
6-
await page.locator("h1").getByText("App Router").isVisible();
7-
await page.locator("h1").getByText("Pages Router").isVisible();
4+
// Also the /super/long/path/to/secret/page should be pregenerated by the `getStaticPaths` function.
5+
test.describe("Catch-all route in root should work", () => {
6+
test("should be possible to visit home and a pregenerated subpage", async ({
7+
page,
8+
}) => {
9+
await page.goto("/");
10+
await page.locator("h1").getByText("App Router").isVisible();
11+
await page.locator("h1").getByText("Pages Router").isVisible();
812

9-
await page.goto("/conico974");
10-
const pElement = page.getByText("Path: conico974", { exact: true });
11-
await pElement.isVisible();
13+
await page.goto("/conico974");
14+
const pElement = page.getByText("Path: conico974", { exact: true });
15+
await pElement.isVisible();
16+
});
17+
test("should be possible to visit a long path", async ({ page }) => {
18+
await page.goto("/super/long/path/to/secret/page");
19+
const h1Text = await page.getByTestId("page").textContent();;
20+
expect(h1Text).toBe("Page: super,long,path,to,secret,page");
21+
});
22+
test("should be possible to request an API route when you have a catch-all in root", async ({
23+
request,
24+
}) => {
25+
const response = await request.get("/api/hello");
26+
expect(response.status()).toBe(200);
27+
const body = await response.json();
28+
expect(body).toEqual({ hello: "world" });
29+
});
1230
});

0 commit comments

Comments
 (0)