Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

css.prod.spec.ts

80 lines2.4 KB

1import { expect } from '@playwright/test'
2import { test } from '@tanstack/router-e2e-utils'
3​
4test.skip(process.env.MODE !== 'prod', 'Prod-only coverage')
5test.skip(
6 process.env.VITE_CSS_CODE_SPLIT !== 'false',
7 'Requires cssCodeSplit=false mode',
8)
9​
10test.describe('CSS modules with cssCodeSplit disabled', () => {
11 test.describe('with JavaScript disabled', () => {
12 test.use({ javaScriptEnabled: false })
13​
14 test('CSS modules are applied on initial page load', async ({ page }) => {
15 await page.goto('/modules')
16​
17 const card = page.getByTestId('module-card')
18 await expect(card).toBeVisible()
19​
20 const className = await card.getAttribute('class')
21 expect(className).toBeTruthy()
22 expect(className).not.toBe('card')
23 expect(className!.length).toBeGreaterThan(5)
24​
25 const backgroundColor = await card.evaluate(
26 (el) => getComputedStyle(el).backgroundColor,
27 )
28 expect(backgroundColor).toBe('rgb(240, 253, 244)')
29​
30 const padding = await card.evaluate((el) => getComputedStyle(el).padding)
31 expect(padding).toBe('16px')
32​
33 const borderRadius = await card.evaluate(
34 (el) => getComputedStyle(el).borderRadius,
35 )
36 expect(borderRadius).toBe('8px')
37 })
38 })
39​
40 test('CSS modules styles persist after hydration', async ({ page }) => {
41 await page.goto('/modules')
42​
43 const card = page.getByTestId('module-card')
44 await expect(card).toBeVisible()
45​
46 await expect(async () => {
47 const backgroundColor = await card.evaluate(
48 (el) => getComputedStyle(el).backgroundColor,
49 )
50 expect(backgroundColor).toBe('rgb(240, 253, 244)')
51 }).toPass({ timeout: 5000 })
52 })
53​
54 test('styles work correctly after client-side navigation', async ({
55 page,
56 }) => {
57 await page.goto('/')
58​
59 const globalElement = page.getByTestId('global-styled')
60 await expect(globalElement).toBeVisible()
61​
62 let backgroundColor = await globalElement.evaluate(
63 (el) => getComputedStyle(el).backgroundColor,
64 )
65 expect(backgroundColor).toBe('rgb(59, 130, 246)')
66​
67 await page.getByTestId('nav-modules').click()
68 await page.waitForURL('**/modules')
69​
70 const card = page.getByTestId('module-card')
71 await expect(card).toBeVisible()
72​
73 await expect(async () => {
74 const backgroundColor = await card.evaluate(
75 (el) => getComputedStyle(el).backgroundColor,
76 )
77 expect(backgroundColor).toBe('rgb(240, 253, 244)')
78 }).toPass({ timeout: 5000 })
79 })
80})