-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathapp.spec.ts
More file actions
134 lines (114 loc) 路 4.65 KB
/
Copy pathapp.spec.ts
File metadata and controls
134 lines (114 loc) 路 4.65 KB
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
import { expect } from '@playwright/test'
import { DEV_STYLES_ATTR } from '@tanstack/router-core'
import { test } from '@tanstack/router-e2e-utils'
import { ssrStylesMode } from '../env'
// Whitelist errors that can occur in CI:
// - net::ERR_NAME_NOT_RESOLVED: transient network issues
// - 504 (Outdated Optimize Dep): Vite dependency optimization reload
const whitelistErrors = [
'Failed to load resource: net::ERR_NAME_NOT_RESOLVED',
'Failed to load resource: the server responded with a status of 504',
]
test.describe(`dev.ssrStyles (mode=${ssrStylesMode})`, () => {
test.use({ whitelistErrors })
test('page renders correctly', async ({ page }) => {
await page.goto('/')
await expect(page.getByTestId('home-heading')).toHaveText(
'Dev SSR Styles Test',
)
})
if (ssrStylesMode === 'default') {
test.describe('default (enabled, basepath = vite base)', () => {
test.use({ javaScriptEnabled: false, whitelistErrors })
test('SSR HTML contains dev styles link tag', async ({ request }) => {
const response = await request.get('/')
expect(response.ok()).toBeTruthy()
const html = await response.text()
// Should have a dev styles link tag.
expect(html).toContain('/@tanstack-start/styles.css')
expect(html).toContain(DEV_STYLES_ATTR)
})
test('dev styles link uses vite base (/) as basepath prefix', async ({
request,
}) => {
const response = await request.get('/')
expect(response.ok()).toBeTruthy()
const html = await response.text()
// With default vite base (/), the dev styles URL should be
// /@tanstack-start/styles.css (no extra prefix)
const match = html.match(
/href="([^"]*@tanstack-start\/styles\.css[^"]*)"/,
)
expect(match).toBeTruthy()
const href = match![1]
expect(href).toMatch(/^\/@tanstack-start\/styles\.css/)
})
test('CSS is applied on initial page load (SSR)', async ({ page }) => {
await page.goto('/')
const element = page.getByTestId('styled-box')
await expect(element).toBeVisible()
// Verify the CSS is applied: #3b82f6 (blue-500) in RGB is rgb(59, 130, 246)
const backgroundColor = await element.evaluate(
(el) => getComputedStyle(el).backgroundColor,
)
expect(backgroundColor).toBe('rgb(59, 130, 246)')
})
})
}
if (ssrStylesMode === 'disabled') {
test.describe('disabled (enabled=false)', () => {
test('SSR HTML does NOT contain dev styles link tag', async ({
request,
}) => {
const response = await request.get('/')
expect(response.ok()).toBeTruthy()
const html = await response.text()
// Should NOT have a dev styles link tag.
expect(html).not.toContain('/@tanstack-start/styles.css')
expect(html).not.toContain(DEV_STYLES_ATTR)
})
test('page still renders without dev styles', async ({ page }) => {
await page.goto('/')
await expect(page.getByTestId('home-heading')).toHaveText(
'Dev SSR Styles Test',
)
// The styled box should exist but may not have CSS applied via SSR
await expect(page.getByTestId('styled-box')).toBeVisible()
})
})
}
if (ssrStylesMode === 'custom-basepath') {
test.describe('custom basepath (/custom-styles/)', () => {
test('SSR HTML contains dev styles link with custom basepath', async ({
request,
}) => {
const response = await request.get('/')
expect(response.ok()).toBeTruthy()
const html = await response.text()
// The dev styles URL should use /custom-styles/ as the basepath prefix
const match = html.match(
/href="([^"]*@tanstack-start\/styles\.css[^"]*)"/,
)
expect(match).toBeTruthy()
const href = match![1]
expect(href).toMatch(/^\/custom-styles\/@tanstack-start\/styles\.css/)
expect(html).toContain(DEV_STYLES_ATTR)
})
test.describe('with JavaScript disabled', () => {
test.use({ javaScriptEnabled: false, whitelistErrors })
test('CSS is applied on initial page load (SSR) with custom basepath', async ({
page,
}) => {
await page.goto('/')
const element = page.getByTestId('styled-box')
await expect(element).toBeVisible()
// Verify the CSS is applied: #3b82f6 (blue-500) in RGB is rgb(59, 130, 246)
const backgroundColor = await element.evaluate(
(el) => getComputedStyle(el).backgroundColor,
)
expect(backgroundColor).toBe('rgb(59, 130, 246)')
})
})
})
}
})