Skip to content

Commit 7ed3bd2

Browse files
committed
Add test that there are no server-side CSS chunks
1 parent 21fdfd4 commit 7ed3bd2

File tree

9 files changed

+90
-0
lines changed

9 files changed

+90
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use client'
2+
3+
import '../../global.css'
4+
import styles from '../../styles.module.css'
5+
6+
export default function Page() {
7+
return <div className={styles.foo}>Hello</div>
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Root({ children }: { children: React.ReactNode }) {
2+
return (
3+
<html>
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '../../global.css'
2+
import styles from '../../styles.module.css'
3+
4+
export default function Page() {
5+
return <div className={styles.foo}>Hello</div>
6+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import fs from 'node:fs/promises'
3+
import path from 'node:path'
4+
5+
describe('css-server-chunks', () => {
6+
const { next, skipped } = nextTestSetup({
7+
files: __dirname,
8+
skipDeployment: true,
9+
})
10+
11+
if (skipped) {
12+
return
13+
}
14+
15+
it('should not write CSS chunks for the server', async () => {
16+
// Fetch all routes to compile them in development
17+
expect((await next.fetch('/client')).status).toBe(200)
18+
expect((await next.fetch('/server')).status).toBe(200)
19+
expect((await next.fetch('/pages')).status).toBe(200)
20+
21+
let clientChunks = (
22+
await fs.readdir(path.join(next.testDir, '.next', 'static'), {
23+
recursive: true,
24+
})
25+
).filter((f) => f.endsWith('.js') || f.endsWith('.css'))
26+
expect(clientChunks).toEqual(
27+
expect.arrayContaining([expect.stringMatching(/\.css$/)])
28+
)
29+
30+
let serverChunks = (
31+
await Promise.all(
32+
['.next/server/app', '.next/server/pages'].map((d) =>
33+
fs.readdir(path.join(next.testDir, d), {
34+
recursive: true,
35+
encoding: 'utf8',
36+
})
37+
)
38+
)
39+
)
40+
.flat()
41+
.filter((f) => f.endsWith('.js') || f.endsWith('.css'))
42+
expect(serverChunks).not.toBeEmpty()
43+
expect(serverChunks).not.toEqual(
44+
expect.arrayContaining([expect.stringMatching(/\.css$/)])
45+
)
46+
})
47+
})
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
color: blue;
3+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @type {import('next').NextConfig}
3+
*/
4+
const nextConfig = {}
5+
6+
module.exports = nextConfig
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import '../global.css'
2+
3+
export default function App({ Component, pageProps }) {
4+
return <Component {...pageProps} />
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import styles from '../styles.module.css'
2+
3+
export default function Page() {
4+
return <div className={styles.foo}>Hello</div>
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}

0 commit comments

Comments
 (0)