-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
LichuAcu
committed
Aug 20, 2024
1 parent
1776af0
commit 065474b
Showing
6 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
test/integration/module-id-strategies/components/CustomComponent.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
3 changes: 3 additions & 0 deletions
3
test/integration/module-id-strategies/module-with-long-name.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
bundlePagesRouterDependencies: true, | ||
serverExternalPackages: ['opted-out-external-package'], | ||
} |
3 changes: 3 additions & 0 deletions
3
test/integration/module-id-strategies/node_modules/external-module-with-long-name.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* 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 allBundles = '' | ||
|
||
beforeAll(async () => { | ||
await nextBuild(appDir, []) | ||
|
||
const ssrPath = join(appDir, '.next/server/chunks/ssr') | ||
const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) => | ||
p.match(/\.js$/) | ||
) | ||
for (const basename of pageBundleBasenames) { | ||
const output = await fs.readFile(join(ssrPath, basename), 'utf8') | ||
allBundles += output | ||
} | ||
}) | ||
|
||
it('should have no long module ids for basic modules', async () => { | ||
expect(allBundles).not.toContain('module-with-long-name') | ||
expect(allBundles).toContain('the content of a module with a long name') | ||
}) | ||
|
||
it('should have no long module ids for external modules', async () => { | ||
expect(allBundles).not.toContain('external-module-with-long-name') | ||
expect(allBundles).toContain( | ||
'the content of an external module with a long name' | ||
) | ||
}) | ||
|
||
it('should have no long module ids for async loader modules', async () => { | ||
expect(allBundles).not.toContain('CustomComponent.tsx') | ||
expect(allBundles).toContain('the content of a dynamic component') | ||
}) | ||
}) | ||
;(!process.env.TURBOPACK || process.env.TURBOPACK_BUILD | ||
? describe.skip | ||
: describe)('development mode', () => { | ||
let allBundles = '' | ||
|
||
beforeAll(async () => { | ||
appPort = await findPort() | ||
app = await launchApp(appDir, appPort) | ||
|
||
await renderViaHTTP(appPort, '/') | ||
|
||
const ssrPath = join(appDir, '.next/server/chunks/ssr') | ||
const pageBundleBasenames = (await fs.readdir(ssrPath)).filter((p) => | ||
p.match(/\.js$/) | ||
) | ||
for (const basename of pageBundleBasenames) { | ||
const output = await fs.readFile(join(ssrPath, basename), 'utf8') | ||
allBundles += output | ||
} | ||
}) | ||
afterAll(() => killApp(app)) | ||
|
||
it('should have long module ids for basic modules', async () => { | ||
expect(allBundles).toContain('module-with-long-name') | ||
expect(allBundles).toContain('the content of a module with a long name') | ||
}) | ||
|
||
it('should have long module ids for external modules', async () => { | ||
expect(allBundles).toContain('external-module-with-long-name') | ||
expect(allBundles).toContain( | ||
'the content of an external module with a long name' | ||
) | ||
}) | ||
|
||
it('should have long module ids for async loader modules', async () => { | ||
expect(allBundles).toContain('CustomComponent.tsx') | ||
expect(allBundles).toContain('the content of a dynamic component') | ||
}) | ||
}) | ||
}) |