Skip to content

Commit 5dbb65f

Browse files
committed
Add test that there are no server-side CSS chunks
1 parent 1f2edc0 commit 5dbb65f

File tree

9 files changed

+83
-0
lines changed

9 files changed

+83
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 } = nextTestSetup({ files: __dirname })
7+
8+
it('should not write CSS chunks for the server', async () => {
9+
// Fetch all routes to compile them in development
10+
expect((await next.fetch('/client')).status).toBe(200)
11+
expect((await next.fetch('/server')).status).toBe(200)
12+
expect((await next.fetch('/pages')).status).toBe(200)
13+
14+
let clientChunks = (
15+
await fs.readdir(path.join(next.testDir, '.next', 'static'), {
16+
recursive: true,
17+
})
18+
).filter((f) => f.endsWith('.js') || f.endsWith('.css'))
19+
expect(clientChunks).toEqual(
20+
expect.arrayContaining([expect.stringMatching(/\.css$/)])
21+
)
22+
23+
let serverChunks = (
24+
await Promise.all(
25+
['.next/server/app', '.next/server/pages'].map((d) =>
26+
fs.readdir(path.join(next.testDir, d), {
27+
recursive: true,
28+
encoding: 'utf8',
29+
})
30+
)
31+
)
32+
)
33+
.flat()
34+
.filter((f) => f.endsWith('.js') || f.endsWith('.css'))
35+
expect(serverChunks).not.toBeEmpty()
36+
expect(serverChunks).not.toEqual(
37+
expect.arrayContaining([expect.stringMatching(/\.css$/)])
38+
)
39+
})
40+
})
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)