Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module ID strategies tests #69110

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

async function CustomComponent() {
return (
<div>
<h1>the content of a dynamic component</h1>
</div>
)
}

export default CustomComponent
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
foo: 'the content of a module with a long name',
}
4 changes: 4 additions & 0 deletions test/integration/module-id-strategies/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
bundlePagesRouterDependencies: true,
serverExternalPackages: ['opted-out-external-package'],
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions test/integration/module-id-strategies/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { foo } from '../module-with-long-name'
import { bar } from '../node_modules/external-module-with-long-name'
import dynamic from 'next/dynamic'

const DynamicCustomComponent = dynamic(
() => import('../components/CustomComponent'),
{
loading: () => <p>Loading...</p>,
}
)

export default function Index() {
return (
<div>
<DynamicCustomComponent />
{foo} {bar}
</div>
)
}
121 changes: 121 additions & 0 deletions test/integration/module-id-strategies/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* 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', () => {
let ssrBundles = ''
let staticBundles = ''

beforeAll(async () => {
await nextBuild(appDir, [])

const ssrPath = join(appDir, '.next/server/chunks/ssr/')
const ssrBundleBasenames = (await fs.readdir(ssrPath)).filter((p) =>
p.match(/\.js$/)
)
for (const basename of ssrBundleBasenames) {
const output = await fs.readFile(join(ssrPath, basename), 'utf8')
ssrBundles += output
}

const staticPath = join(appDir, '.next/static/chunks/')
const staticBundleBasenames = (await fs.readdir(staticPath)).filter((p) =>
p.match(/\.js$/)
)
for (const basename of staticBundleBasenames) {
const output = await fs.readFile(join(staticPath, basename), 'utf8')
staticBundles += output
}
})

it('should have no long module ids for basic modules', async () => {
expect(ssrBundles).not.toContain('module-with-long-name')
expect(ssrBundles).toContain('the content of a module with a long name')
})

it('should have no long module ids for external modules', async () => {
expect(ssrBundles).not.toContain('external-module-with-long-name')
expect(ssrBundles).toContain(
'the content of an external module with a long name'
)
})

it('should have no long module ids for async loader modules', async () => {
expect(ssrBundles).not.toContain('CustomComponent.tsx')
expect(ssrBundles).toContain('the content of a dynamic component')
})

it('should have no long module id for the next client runtime module', async () => {
expect(staticBundles).not.toContain('next/dist/client/next-turbopack')
})
})
;(!process.env.TURBOPACK || process.env.TURBOPACK_BUILD
? describe.skip
: describe)('development mode', () => {
let ssrBundles = ''
let staticBundles = ''

beforeAll(async () => {
appPort = await findPort()
app = await launchApp(appDir, appPort)

await renderViaHTTP(appPort, '/')

const ssrPath = join(appDir, '.next/server/chunks/ssr/')
const ssrBundleBasenames = (await fs.readdir(ssrPath)).filter((p) =>
p.match(/\.js$/)
)
for (const basename of ssrBundleBasenames) {
const output = await fs.readFile(join(ssrPath, basename), 'utf8')
ssrBundles += output
}

const staticPath = join(appDir, '.next/static/chunks/')
const staticBundleBasenames = (await fs.readdir(staticPath)).filter((p) =>
p.match(/\.js$/)
)
for (const basename of staticBundleBasenames) {
const output = await fs.readFile(join(staticPath, basename), 'utf8')
staticBundles += output
}
})
afterAll(() => killApp(app))

it('should have long module ids for basic modules', async () => {
expect(ssrBundles).toContain('module-with-long-name')
expect(ssrBundles).toContain('the content of a module with a long name')
})

it('should have long module ids for external modules', async () => {
expect(ssrBundles).toContain('external-module-with-long-name')
expect(ssrBundles).toContain(
'the content of an external module with a long name'
)
})

it('should have long module ids for async loader modules', async () => {
expect(ssrBundles).toContain('CustomComponent.tsx')
expect(ssrBundles).toContain('the content of a dynamic component')
})

it('should have long module id for the next client runtime module', async () => {
expect(staticBundles).toContain('next/dist/client/next-dev-turbopack')
})
})
})
Loading