From d16e701eb16a44610d830c2f41fd3e59ffa00556 Mon Sep 17 00:00:00 2001 From: TasukuUno Date: Wed, 23 Sep 2020 14:30:56 +0900 Subject: [PATCH] Fix css dependency in /_error --- packages/next/pages/_document.tsx | 3 +- .../document-file-dependencies/css/app.css | 3 ++ .../css/error.module.css | 3 ++ .../css/index.module.css | 3 ++ .../document-file-dependencies/pages/_app.js | 11 ++++ .../pages/_error.js | 5 ++ .../pages/error-trigger.js | 14 ++++++ .../document-file-dependencies/pages/index.js | 5 ++ .../test/index.test.js | 50 +++++++++++++++++++ 9 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 test/integration/document-file-dependencies/css/app.css create mode 100644 test/integration/document-file-dependencies/css/error.module.css create mode 100644 test/integration/document-file-dependencies/css/index.module.css create mode 100644 test/integration/document-file-dependencies/pages/_app.js create mode 100644 test/integration/document-file-dependencies/pages/_error.js create mode 100644 test/integration/document-file-dependencies/pages/error-trigger.js create mode 100644 test/integration/document-file-dependencies/pages/index.js create mode 100644 test/integration/document-file-dependencies/test/index.test.js diff --git a/packages/next/pages/_document.tsx b/packages/next/pages/_document.tsx index 7d3259af7475d..989efe682e8a4 100644 --- a/packages/next/pages/_document.tsx +++ b/packages/next/pages/_document.tsx @@ -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, diff --git a/test/integration/document-file-dependencies/css/app.css b/test/integration/document-file-dependencies/css/app.css new file mode 100644 index 0000000000000..bcb11204cd085 --- /dev/null +++ b/test/integration/document-file-dependencies/css/app.css @@ -0,0 +1,3 @@ +.global { + background-color: #eeeeee; +} diff --git a/test/integration/document-file-dependencies/css/error.module.css b/test/integration/document-file-dependencies/css/error.module.css new file mode 100644 index 0000000000000..efdfa20ef9471 --- /dev/null +++ b/test/integration/document-file-dependencies/css/error.module.css @@ -0,0 +1,3 @@ +.error { + color: #ff0000; +} diff --git a/test/integration/document-file-dependencies/css/index.module.css b/test/integration/document-file-dependencies/css/index.module.css new file mode 100644 index 0000000000000..2534e4c6b0115 --- /dev/null +++ b/test/integration/document-file-dependencies/css/index.module.css @@ -0,0 +1,3 @@ +.index { + color: #333333; +} diff --git a/test/integration/document-file-dependencies/pages/_app.js b/test/integration/document-file-dependencies/pages/_app.js new file mode 100644 index 0000000000000..fab489588a00c --- /dev/null +++ b/test/integration/document-file-dependencies/pages/_app.js @@ -0,0 +1,11 @@ +import '../css/app.css' + +function App({ Component, pageProps }) { + return ( +
+ +
+ ) +} + +export default App diff --git a/test/integration/document-file-dependencies/pages/_error.js b/test/integration/document-file-dependencies/pages/_error.js new file mode 100644 index 0000000000000..3ea8ea1bd0f58 --- /dev/null +++ b/test/integration/document-file-dependencies/pages/_error.js @@ -0,0 +1,5 @@ +import style from '../css/error.module.css' + +export default function Error() { + return
error
+} diff --git a/test/integration/document-file-dependencies/pages/error-trigger.js b/test/integration/document-file-dependencies/pages/error-trigger.js new file mode 100644 index 0000000000000..6888cac20b1d3 --- /dev/null +++ b/test/integration/document-file-dependencies/pages/error-trigger.js @@ -0,0 +1,14 @@ +import style from '../css/index.module.css' + +function ErrorTrigger() { + return
error-trigger
+} + +ErrorTrigger.getInitialProps = () => { + throw new Error('Intentional Error') + + // eslint-disable-next-line no-unreachable + return {} +} + +export default ErrorTrigger diff --git a/test/integration/document-file-dependencies/pages/index.js b/test/integration/document-file-dependencies/pages/index.js new file mode 100644 index 0000000000000..be138891666b8 --- /dev/null +++ b/test/integration/document-file-dependencies/pages/index.js @@ -0,0 +1,5 @@ +import style from '../css/index.module.css' + +export default function Index() { + return
index
+} diff --git a/test/integration/document-file-dependencies/test/index.test.js b/test/integration/document-file-dependencies/test/index.test.js new file mode 100644 index 0000000000000..19f60c6695bd8 --- /dev/null +++ b/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) + }) + }) +})