Skip to content

Commit

Permalink
Module ID strategies tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LichuAcu committed Aug 20, 2024
1 parent 1776af0 commit 1495563
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
foo: 'a very long module 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'],
}
5 changes: 5 additions & 0 deletions test/integration/module-id-strategies/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { foo } from '../module-with-long-name'

export default function Index() {
return <div>{foo}</div>
}
67 changes: 67 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,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')
})
})
})

0 comments on commit 1495563

Please sign in to comment.