Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/client/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use client'

import '../../global.css'
import styles from '../../styles.module.css'

export default function Page() {
return <div className={styles.foo}>Hello</div>
}
7 changes: 7 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/css-server-chunks/app/server/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import '../../global.css'
import styles from '../../styles.module.css'

export default function Page() {
return <div className={styles.foo}>Hello</div>
}
47 changes: 47 additions & 0 deletions test/e2e/app-dir/css-server-chunks/css-server-chunks.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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$/)])
)
})
})
3 changes: 3 additions & 0 deletions test/e2e/app-dir/css-server-chunks/global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
color: blue;
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/css-server-chunks/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}

module.exports = nextConfig
5 changes: 5 additions & 0 deletions test/e2e/app-dir/css-server-chunks/pages/_app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import '../global.css'

export default function App({ Component, pageProps }) {
return <Component {...pageProps} />
}
5 changes: 5 additions & 0 deletions test/e2e/app-dir/css-server-chunks/pages/pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styles from '../styles.module.css'

export default function Page() {
return <div className={styles.foo}>Hello</div>
}
3 changes: 3 additions & 0 deletions test/e2e/app-dir/css-server-chunks/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.foo {
color: red;
}