Unverified Commit 161a8ba0 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Test that there are no server-side CSS chunks (#82471)

A few months ago, this was fixed  for Turbopack. Adding a regression test now
parent d2512647
'use client'
import '../../global.css'
import styles from '../../styles.module.css'
export default function Page() {
return <div className={styles.foo}>Hello</div>
}
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
import '../../global.css'
import styles from '../../styles.module.css'
export default function Page() {
return <div className={styles.foo}>Hello</div>
}
import { nextTestSetup } from 'e2e-utils'
import fs from 'node:fs/promises'
import path from 'node:path'
describe('css-server-chunks', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
})
if (skipped) {
return
}
it('should not write CSS chunks for the server', async () => {
// Fetch all routes to compile them in development
expect((await next.fetch('/client')).status).toBe(200)
expect((await next.fetch('/server')).status).toBe(200)
expect((await next.fetch('/pages')).status).toBe(200)
let clientChunks = (
await fs.readdir(path.join(next.testDir, '.next', 'static'), {
recursive: true,
})
).filter((f) => f.endsWith('.js') || f.endsWith('.css'))
expect(clientChunks).toEqual(
expect.arrayContaining([expect.stringMatching(/\.css$/)])
)
let serverChunks = (
await Promise.all(
['.next/server/app', '.next/server/pages'].map((d) =>
fs.readdir(path.join(next.testDir, d), {
recursive: true,
encoding: 'utf8',
})
)
)
)
.flat()
.filter((f) => f.endsWith('.js') || f.endsWith('.css'))
expect(serverChunks).not.toBeEmpty()
expect(serverChunks).not.toEqual(
expect.arrayContaining([expect.stringMatching(/\.css$/)])
)
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
import '../global.css'
export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
import styles from '../styles.module.css'
export default function Page() {
return <div className={styles.foo}>Hello</div>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment