diff --git a/test/integration/module-id-strategies/module-with-long-name.js b/test/integration/module-id-strategies/module-with-long-name.js new file mode 100644 index 00000000000000..065b137c77cdb8 --- /dev/null +++ b/test/integration/module-id-strategies/module-with-long-name.js @@ -0,0 +1,3 @@ +module.exports = { + foo: 'a very long module name!', +} diff --git a/test/integration/module-id-strategies/next.config.js b/test/integration/module-id-strategies/next.config.js new file mode 100644 index 00000000000000..40c2e5b7e65a1c --- /dev/null +++ b/test/integration/module-id-strategies/next.config.js @@ -0,0 +1,4 @@ +module.exports = { + bundlePagesRouterDependencies: true, + serverExternalPackages: ['opted-out-external-package'], +} diff --git a/test/integration/module-id-strategies/pages/index.js b/test/integration/module-id-strategies/pages/index.js new file mode 100644 index 00000000000000..d618ff33ec892a --- /dev/null +++ b/test/integration/module-id-strategies/pages/index.js @@ -0,0 +1,5 @@ +import { foo } from '../module-with-long-name' + +export default function Index() { + return
{foo}
+} diff --git a/test/integration/module-id-strategies/test/index.test.js b/test/integration/module-id-strategies/test/index.test.js new file mode 100644 index 00000000000000..464adea7ac0a14 --- /dev/null +++ b/test/integration/module-id-strategies/test/index.test.js @@ -0,0 +1,67 @@ +/* eslint-env jest */ + +import fs from 'fs-extra' +import { join } from 'path' +import { + killApp, + findPort, + launchApp, + nextBuild, + renderViaHTTP, +} from 'next-test-utils' + +const appDir = join(__dirname, '../') + +let appPort +let app + +describe('minified module ids', () => { + ;(!process.env.TURBOPACK || process.env.TURBOPACK_DEV + ? describe.skip + : describe)('production mode', () => { + beforeAll(async () => { + await nextBuild(appDir, []) + }) + + it('should have no long module ids', async () => { + const ssrPath = join(appDir, '.next/server/chunks/ssr') + const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) => + p.match(/\.js$/) + ) + expect(pageBundleBasenames).not.toBeEmpty() + let allBundles = '' + for (const basename of pageBundleBasenames) { + const output = await fs.readFile(join(ssrPath, basename), 'utf8') + allBundles += output + } + + expect(allBundles).not.toContain('module-with-long-name') + }) + }) + ;(!process.env.TURBOPACK || process.env.TURBOPACK_BUILD + ? describe.skip + : describe)('development mode', () => { + beforeAll(async () => { + appPort = await findPort() + app = await launchApp(appDir, appPort) + }) + afterAll(() => killApp(app)) + + it('should have long module ids', async () => { + await renderViaHTTP(appPort, '/') + + const ssrPath = join(appDir, '.next/server/chunks/ssr') + const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) => + p.match(/\.js$/) + ) + expect(pageBundleBasenames).not.toBeEmpty() + let allBundles = '' + for (const basename of pageBundleBasenames) { + const output = await fs.readFile(join(ssrPath, basename), 'utf8') + allBundles += output + } + + expect(allBundles).toContain('module-with-long-name') + }) + }) +})