forked from vitejs/vite-plugin-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcss-code-split.test.ts
More file actions
69 lines (63 loc) · 2.04 KB
/
css-code-split.test.ts
File metadata and controls
69 lines (63 loc) · 2.04 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
import { expect, test } from '@playwright/test'
import { setupInlineFixture, useFixture } from './fixture'
import { defineStarterTest } from './starter'
test.describe('cssCodeSplit-false', () => {
const root = 'examples/e2e/temp/cssCodeSplit-false'
test.beforeAll(async () => {
await setupInlineFixture({
src: 'examples/starter',
dest: root,
files: {
'vite.config.base.ts': { cp: 'vite.config.ts' },
'vite.config.ts': /* js */ `
import { defineConfig, mergeConfig } from 'vite'
import baseConfig from './vite.config.base.ts'
const overrideConfig = defineConfig({
build: {
cssCodeSplit: false,
},
})
export default mergeConfig(baseConfig, overrideConfig)
`,
// test server css module too
// (starter example already tests normal server css)
'src/server-only.module.css': /* css */ `
.serverOnly {
color: rgb(123, 45, 67);
}
`,
'src/server-only.tsx': /* js */ `
import styles from './server-only.module.css'
export function ServerOnly() {
return (
<button data-testid="server-only" className={styles.serverOnly}>
server-only
</button>
)
}
`,
'src/root.tsx': {
edit: (s) =>
s
.replace(
`import { ClientCounter } from './client.tsx'`,
`import { ClientCounter } from './client.tsx';
import { ServerOnly } from './server-only.tsx'`,
)
.replace(`<ClientCounter />`, `<ClientCounter /><ServerOnly />`),
},
},
})
})
test.describe('build', () => {
const f = useFixture({ root, mode: 'build' })
defineStarterTest(f)
test('server css module', async ({ page }) => {
await page.goto(f.url())
await expect(page.getByTestId('server-only')).toHaveCSS(
'color',
'rgb(123, 45, 67)',
)
})
})
})