Skip to content

Commit c75146f

Browse files
authored
Test CSS/Media Caching in Production Suite (vercel#10184)
* Test CSS Modules in Production Suite * fix build * test css and media assets
1 parent ebc46c1 commit c75146f

File tree

6 files changed

+68
-15
lines changed

6 files changed

+68
-15
lines changed

packages/next/next-server/server/next-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ export default class Server {
330330
if (
331331
params.path[0] === CLIENT_STATIC_FILES_RUNTIME ||
332332
params.path[0] === 'chunks' ||
333+
params.path[0] === 'css' ||
334+
params.path[0] === 'media' ||
333335
params.path[0] === this.buildId
334336
) {
335337
this.setImmutableAssetCacheControl(res)
Lines changed: 19 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import styles from './logo.module.css'
2+
3+
export default function Logo() {
4+
return <div className={styles.logo}></div>
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.logo {
2+
background-image: url(dark.svg);
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Logo from '../components/logo'
2+
3+
export default () => (
4+
<div>
5+
<Logo />
6+
</div>
7+
)

test/integration/production/test/index.test.js

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
/* eslint-env jest */
22
/* global jasmine, browserName */
3-
import webdriver from 'next-webdriver'
4-
import { readFileSync, existsSync } from 'fs'
5-
import { join } from 'path'
3+
import cheerio from 'cheerio'
4+
import { existsSync, readFileSync } from 'fs'
65
import {
76
nextServer,
7+
renderViaHTTP,
88
runNextCommand,
99
startApp,
1010
stopApp,
11-
renderViaHTTP,
1211
waitFor,
1312
} from 'next-test-utils'
14-
import fetch from 'node-fetch'
15-
import dynamicImportTests from './dynamic'
16-
import processEnv from './process-env'
17-
import security from './security'
13+
import webdriver from 'next-webdriver'
1814
import {
1915
BUILD_MANIFEST,
20-
REACT_LOADABLE_MANIFEST,
2116
PAGES_MANIFEST,
17+
REACT_LOADABLE_MANIFEST,
2218
} from 'next/constants'
23-
import cheerio from 'cheerio'
19+
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
20+
import fetch from 'node-fetch'
21+
import { join } from 'path'
22+
import dynamicImportTests from './dynamic'
23+
import processEnv from './process-env'
24+
import security from './security'
2425
const appDir = join(__dirname, '../')
2526
let serverDir
2627
let appPort
@@ -172,23 +173,39 @@ describe('Production Usage', () => {
172173
))
173174
const url = `http://localhost:${appPort}/_next/`
174175

175-
const resources = []
176+
const resources = new Set()
176177

177178
// test a regular page
178-
resources.push(`${url}static/${buildId}/pages/index.js`)
179+
resources.add(`${url}static/${buildId}/pages/index.js`)
179180

180181
// test dynamic chunk
181-
resources.push(
182+
resources.add(
182183
url + reactLoadableManifest['../../components/hello1'][0].publicPath
183184
)
184185

185186
// test main.js runtime etc
186187
for (const item of buildManifest.pages['/']) {
187-
resources.push(url + item)
188+
resources.add(url + item)
188189
}
189190

191+
const cssStaticAssets = await recursiveReadDir(
192+
join(__dirname, '..', '.next', 'static'),
193+
/\.css$/
194+
)
195+
expect(cssStaticAssets.length).toBeGreaterThanOrEqual(1)
196+
expect(cssStaticAssets[0]).toMatch(/[\\/]css[\\/]/)
197+
const mediaStaticAssets = await recursiveReadDir(
198+
join(__dirname, '..', '.next', 'static'),
199+
/\.svg$/
200+
)
201+
expect(mediaStaticAssets.length).toBeGreaterThanOrEqual(1)
202+
expect(mediaStaticAssets[0]).toMatch(/[\\/]media[\\/]/)
203+
;[...cssStaticAssets, ...mediaStaticAssets].forEach(asset => {
204+
resources.add(`${url}static${asset.replace(/\\+/g, '/')}`)
205+
})
206+
190207
const responses = await Promise.all(
191-
resources.map(resource => fetch(resource))
208+
[...resources].map(resource => fetch(resource))
192209
)
193210

194211
responses.forEach(res => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy