From 2ed6aa377c88d9b9b64a87ef7e96c71bddcfa5ae Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 14 May 2022 17:34:21 +0800 Subject: [PATCH] test(#36855): add test case --- test/integration/export-404-html/.gitignore | 1 + .../export-404-html/next.config.js | 5 +++ .../export-404-html/pages/index.js | 1 + .../export-404-html/test/index.test.js | 43 +++++++++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 test/integration/export-404-html/.gitignore create mode 100644 test/integration/export-404-html/next.config.js create mode 100644 test/integration/export-404-html/pages/index.js create mode 100644 test/integration/export-404-html/test/index.test.js diff --git a/test/integration/export-404-html/.gitignore b/test/integration/export-404-html/.gitignore new file mode 100644 index 000000000000..3ec8dc5141d7 --- /dev/null +++ b/test/integration/export-404-html/.gitignore @@ -0,0 +1 @@ +.next-dev diff --git a/test/integration/export-404-html/next.config.js b/test/integration/export-404-html/next.config.js new file mode 100644 index 000000000000..d703fe4768a8 --- /dev/null +++ b/test/integration/export-404-html/next.config.js @@ -0,0 +1,5 @@ +module.exports = (phase) => { + return { + trailingSlash: false, + } +} diff --git a/test/integration/export-404-html/pages/index.js b/test/integration/export-404-html/pages/index.js new file mode 100644 index 000000000000..cdcba171398a --- /dev/null +++ b/test/integration/export-404-html/pages/index.js @@ -0,0 +1 @@ +export default () =>
diff --git a/test/integration/export-404-html/test/index.test.js b/test/integration/export-404-html/test/index.test.js new file mode 100644 index 000000000000..49ef5852a7d5 --- /dev/null +++ b/test/integration/export-404-html/test/index.test.js @@ -0,0 +1,43 @@ +/* eslint-env jest */ + +import { join } from 'path' +import { nextBuild, nextExport, File } from 'next-test-utils' + +import { promises } from 'fs' + +const { access, stat } = promises +const appDir = join(__dirname, '../') +const outdir = join(appDir, 'out') +const context = {} +context.appDir = appDir +const nextConfig = new File(join(appDir, 'next.config.js')) + +const fileExist = (path) => + access(path) + .then(() => stat(path)) + .then((stats) => (stats.isFile() ? true : false)) + .catch(() => false) + +// Issue #36855 +// https://github.com/vercel/next.js/issues/36855 +describe('Static 404 Export', () => { + it('only export 404.html when trailingSlash: false', async () => { + await nextBuild(appDir) + await nextExport(appDir, { outdir }) + + expect(await fileExist(join(outdir, '404.html'))).toBe(true) + expect(await fileExist(join(outdir, '404.html.html'))).toBe(false) + expect(await fileExist(join(outdir, '404/index.html'))).toBe(false) + }) + + it('export 404.html and 404/index.html when trailingSlash: true', async () => { + nextConfig.replace(`trailingSlash: false`, `trailingSlash: true`) + await nextBuild(appDir) + await nextExport(appDir, { outdir }) + nextConfig.restore() + + expect(await fileExist(join(outdir, '404/index.html'))).toBe(true) + expect(await fileExist(join(outdir, '404.html.html'))).toBe(false) + expect(await fileExist(join(outdir, '404.html'))).toBe(true) + }) +})