Skip to content

Commit

Permalink
Fix css dependency in /_error
Browse files Browse the repository at this point in the history
  • Loading branch information
TasukuUno committed Sep 29, 2020
1 parent c731c63 commit d16e701
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/next/pages/_document.tsx
Expand Up @@ -55,8 +55,7 @@ function getDocumentFiles(
pathname: string
): DocumentFiles {
const sharedFiles: readonly string[] = getPageFiles(buildManifest, '/_app')
const pageFiles: readonly string[] =
pathname !== '/_error' ? getPageFiles(buildManifest, pathname) : []
const pageFiles: readonly string[] = getPageFiles(buildManifest, pathname)

return {
sharedFiles,
Expand Down
3 changes: 3 additions & 0 deletions test/integration/document-file-dependencies/css/app.css
@@ -0,0 +1,3 @@
.global {
background-color: #eeeeee;
}
@@ -0,0 +1,3 @@
.error {
color: #ff0000;
}
@@ -0,0 +1,3 @@
.index {
color: #333333;
}
11 changes: 11 additions & 0 deletions test/integration/document-file-dependencies/pages/_app.js
@@ -0,0 +1,11 @@
import '../css/app.css'

function App({ Component, pageProps }) {
return (
<div className="global">
<Component {...pageProps} />
</div>
)
}

export default App
5 changes: 5 additions & 0 deletions test/integration/document-file-dependencies/pages/_error.js
@@ -0,0 +1,5 @@
import style from '../css/error.module.css'

export default function Error() {
return <div className={style.error}>error</div>
}
14 changes: 14 additions & 0 deletions test/integration/document-file-dependencies/pages/error-trigger.js
@@ -0,0 +1,14 @@
import style from '../css/index.module.css'

function ErrorTrigger() {
return <div className={style.index}>error-trigger</div>
}

ErrorTrigger.getInitialProps = () => {
throw new Error('Intentional Error')

// eslint-disable-next-line no-unreachable
return {}
}

export default ErrorTrigger
5 changes: 5 additions & 0 deletions test/integration/document-file-dependencies/pages/index.js
@@ -0,0 +1,5 @@
import style from '../css/index.module.css'

export default function Index() {
return <div className={style.index}>index</div>
}
50 changes: 50 additions & 0 deletions test/integration/document-file-dependencies/test/index.test.js
@@ -0,0 +1,50 @@
/* eslint-env jest */

import { join } from 'path'
import {
fetchViaHTTP,
findPort,
killApp,
nextBuild,
nextStart,
} from 'next-test-utils'
import cheerio from 'cheerio'

jest.setTimeout(1000 * 60 * 2)
const appDir = join(__dirname, '..')

let appPort
let app

describe('File Dependencies', () => {
describe('production mode', () => {
beforeAll(async () => {
appPort = await findPort()
await nextBuild(appDir)
app = await nextStart(appDir, appPort)
})

afterAll(() => killApp(app))

it('should depend on global and module css files in standard page', async () => {
const res = await fetchViaHTTP(appPort, '/')
const $ = cheerio.load(await res.text())
const cssFiles = $('link[rel="stylesheet"]')
expect(cssFiles.length).toBe(2)
})

it('should depend on global and module css files in 404 page', async () => {
const res = await fetchViaHTTP(appPort, '/__not_found__')
const $ = cheerio.load(await res.text())
const cssFiles = $('link[rel="stylesheet"]')
expect(cssFiles.length).toBe(2)
})

it('should depend on global and module css files in _error page', async () => {
const res = await fetchViaHTTP(appPort, '/error-trigger')
const $ = cheerio.load(await res.text())
const cssFiles = $('link[rel="stylesheet"]')
expect(cssFiles.length).toBe(2)
})
})
})

0 comments on commit d16e701

Please sign in to comment.