-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathbroken-links.spec.ts
171 lines (154 loc) · 7.09 KB
/
broken-links.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import { expect } from '@playwright/test';
import { test, prepareStandaloneSetup } from './utils.js';
const startApp = prepareStandaloneSetup('broken-links');
test.describe('broken-links: normal server', async () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp('PRD'));
});
test.afterAll(async () => {
await stopApp();
});
test.describe('server side navigation', () => {
test('existing page', async ({ page }) => {
// Go to an existing page
await page.goto(`http://localhost:${port}/exists`);
// The page renders its header
await expect(page.getByRole('heading')).toHaveText('Existing page');
// The page URL is correct
expect(page.url()).toBe(`http://localhost:${port}/exists`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('missing page', async ({ page }) => {
// Navigate to a non-existing page
await page.goto(`http://localhost:${port}/broken`);
// The page renders the custom 404.tsx
await expect(page.getByRole('heading')).toHaveText('Custom not found');
// The browsers URL remains the one that was navigated to
expect(page.url()).toBe(`http://localhost:${port}/broken`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('redirect', async ({ page }) => {
// Navigate to a page that redirects to an existing page
await page.goto(`http://localhost:${port}/redirect`);
// The page renders the target page
await expect(page.getByRole('heading')).toHaveText('Existing page');
// The browsers URL is the one of the target page
expect(page.url()).toBe(`http://localhost:${port}/exists`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('broken redirect', async ({ page }) => {
// Navigate to a page that redirects to a non-existing page
await page.goto(`http://localhost:${port}/broken-redirect`);
// The page renders the custom 404.tsx
await expect(page.getByRole('heading')).toHaveText('Custom not found');
// The browsers URL remains the one that was redirected to
expect(page.url()).toBe(`http://localhost:${port}/broken`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
});
});
test.describe('broken-links: static server', () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp('STATIC'));
});
test.afterAll(async () => {
await stopApp();
});
test.describe('client side navigation', () => {
test('correct link', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
// Click on a link to an existing page
await page.getByRole('link', { name: 'Existing page' }).click();
// The page renders the target page
await expect(page.getByRole('heading')).toHaveText('Existing page');
// The browsers URL is the one of the target page
expect(page.url()).toBe(`http://localhost:${port}/exists`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('broken link', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
// Click on a link to a non-existing page
await page.getByRole('link', { name: 'Broken link' }).click();
// The page renders the custom 404.tsx
await expect(page.getByRole('heading')).toHaveText('Custom not found');
// The browsers URL remains the one that was navigated to
expect(page.url()).toBe(`http://localhost:${port}/broken`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('redirect', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
// Click on a link to a redirect
await page.getByRole('link', { name: 'Correct redirect' }).click();
// The page renders the target page
await expect(page.getByRole('heading')).toHaveText('Existing page');
// The browsers URL is the one of the target page
expect(page.url()).toBe(`http://localhost:${port}/exists`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
test('broken redirect', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
// Click on a link to a broken redirect
await page.getByRole('link', { name: 'Broken redirect' }).click();
// The page renders the custom 404.tsx
await expect(page.getByRole('heading')).toHaveText('Custom not found');
// The browsers URL remains the link href
// NOTE: This is inconsistent with server side navigation, but
// there is no way to tell where the RSC request was redirected
// to before failing with 404.
expect(page.url()).toBe(`http://localhost:${port}/broken-redirect`);
// Go back to the index page
await page.getByRole('link', { name: 'Back' }).click();
await expect(page.getByRole('heading')).toHaveText('Index');
});
});
});
for (const mode of ['DEV', 'PRD'] as const) {
test.describe(`broken-links/dynamic-not-found: ${mode}`, async () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp(mode));
});
test.afterAll(async () => {
await stopApp();
});
test('access sync page directly', async ({ page }) => {
await page.goto(`http://localhost:${port}/dynamic-not-found/sync`);
await expect(page.getByRole('heading')).toHaveText('Custom not found');
});
test('access async page directly', async ({ page }) => {
await page.goto(`http://localhost:${port}/dynamic-not-found/async`);
await expect(page.getByRole('heading')).toHaveText('Custom not found');
});
test('access sync page with client navigation', async ({ page }) => {
await page.goto(`http://localhost:${port}/`);
await expect(page.getByRole('heading')).toHaveText('Index');
await page.click("a[href='/dynamic-not-found/sync']");
await expect(page.getByRole('heading')).toHaveText('Custom not found');
});
test('access async page with client navigation', async ({ page }) => {
await page.goto(`http://localhost:${port}/`);
await expect(page.getByRole('heading')).toHaveText('Index');
await page.click("a[href='/dynamic-not-found/async']");
await expect(page.getByRole('heading')).toHaveText('Custom not found');
});
});
}