-
-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathfs-router.spec.ts
98 lines (84 loc) · 3.3 KB
/
fs-router.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
import { expect } from '@playwright/test';
import { test, prepareStandaloneSetup } from './utils.js';
const startApp = prepareStandaloneSetup('fs-router');
for (const mode of ['DEV', 'PRD'] as const) {
test.describe(`fs-router: ${mode}`, async () => {
let port: number;
let stopApp: () => Promise<void>;
test.beforeAll(async () => {
({ port, stopApp } = await startApp(mode));
});
test.afterAll(async () => {
await stopApp();
});
test('home', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
const backgroundColor = await page.evaluate(() =>
window
.getComputedStyle(document.body)
.getPropertyValue('background-color'),
);
expect(backgroundColor).toBe('rgba(0, 0, 0, 0)');
});
test('foo', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
await page.click("a[href='/foo']");
await expect(page.getByRole('heading', { name: 'Foo' })).toBeVisible();
await page.goto(`http://localhost:${port}/foo`);
await expect(page.getByRole('heading', { name: 'Foo' })).toBeVisible();
});
test('nested/foo', async ({ page }) => {
// /nested/foo is defined as a staticPath of /nested/[id] which matches this layout
await page.goto(`http://localhost:${port}/nested/foo`);
await expect(
page.getByRole('heading', { name: 'Nested / foo' }),
).toBeVisible();
});
test('nested/baz', async ({ page }) => {
await page.goto(`http://localhost:${port}/nested/baz`);
await expect(
page.getByRole('heading', { name: 'Nested Layout' }),
).toBeVisible();
});
test('api hi', async () => {
const res = await fetch(`http://localhost:${port}/api/hi`);
expect(res.status).toBe(200);
expect(await res.text()).toBe('Hello from API!');
});
test('api hi.txt', async () => {
const res = await fetch(`http://localhost:${port}/api/hi.txt`);
expect(res.status).toBe(200);
expect(await res.text()).toBe('hello from a text file!');
});
test('api empty', async () => {
const res = await fetch(`http://localhost:${port}/api/empty`);
expect(res.status).toBe(200);
expect(await res.text()).toBe('');
});
test('api hi with POST', async () => {
const res = await fetch(`http://localhost:${port}/api/hi`, {
method: 'POST',
body: 'from the test!',
});
expect(res.status).toBe(200);
expect(await res.text()).toBe('POST Hello from API! from the test!');
});
test('_components', async ({ page }) => {
await page.goto(`http://localhost:${port}/_components/Counter`);
await expect(page.getByText('404 Not Found')).toBeVisible();
});
test('alt click', async ({ page }) => {
await page.goto(`http://localhost:${port}`);
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
await page.click("a[href='/foo']", {
button: 'right',
});
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
await page.click("a[href='/foo']", {
modifiers: ['ControlOrMeta'],
});
await expect(page.getByRole('heading', { name: 'Home' })).toBeVisible();
});
});
}