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

Turbopack build: Fix client-components-tree-shaking test #70662

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
Expand Up @@ -6,4 +6,4 @@ export default function RootLayout({ children }) {
)
}

export const dynamic = 'forced-dynamic'
export const dynamic = 'force-dynamic'
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import fs from 'fs'
import { nextTestSetup } from 'e2e-utils'
import { join } from 'path'

describe('app-dir client-components-tree-shaking', () => {
const { next, skipped } = nextTestSetup({
Expand All @@ -10,22 +8,19 @@ describe('app-dir client-components-tree-shaking', () => {
if (skipped) return

it('should only include imported components 3rd party package in browser bundle with direct imports', async () => {
const clientChunksDir = join(
next.testDir,
'.next',
'static',
'chunks',
'app',
'third-party-dep'
const $ = await next.render$('/third-party-dep')
const chunkContents = await Promise.all(
$('script[src]')
.toArray()
.map(async (el) => {
const href = $(el).attr('src')

const file = await next.fetch(href).then((res) => res.text())

return file
})
)
const staticChunksDirents = fs.readdirSync(clientChunksDir, {
withFileTypes: true,
})
const chunkContents = staticChunksDirents
.filter((dirent) => dirent.isFile())
.map((chunkDirent) =>
fs.readFileSync(join(chunkDirent.path, chunkDirent.name), 'utf8')
)

expect(
chunkContents.some((content) => content.includes('client-dep-bar:esm'))
).toBe(true)
Expand All @@ -40,23 +35,18 @@ describe('app-dir client-components-tree-shaking', () => {
})

it('should only include the imported identifier of CJS module in browser bundle', async () => {
const clientChunksDir = join(
next.testDir,
'.next',
'static',
'chunks',
'app',
'cjs-dep'
)
const $ = await next.render$('/cjs-dep')
const chunkContents = await Promise.all(
$('script[src]')
.toArray()
.map(async (el) => {
const href = $(el).attr('src')

const chunkContents = fs
.readdirSync(clientChunksDir, {
withFileTypes: true,
})
.filter((dirent) => dirent.isFile())
.map((chunkDirent) =>
fs.readFileSync(join(chunkDirent.path, chunkDirent.name), 'utf8')
)
const file = await next.fetch(href).then((res) => res.text())

return file
})
)

expect(
chunkContents.some((content) => content.includes('cjs-client:default'))
Expand Down Expand Up @@ -87,22 +77,19 @@ describe('app-dir client-components-tree-shaking', () => {
})

it('should only include imported relative components in browser bundle with direct imports', async () => {
const clientChunksDir = join(
next.testDir,
'.next',
'static',
'chunks',
'app',
'relative-dep'
const $ = await next.render$('/relative-dep')
const chunkContents = await Promise.all(
$('script[src]')
.toArray()
.map(async (el) => {
const href = $(el).attr('src')

const file = await next.fetch(href).then((res) => res.text())

return file
})
)
const staticChunksDirents = fs.readdirSync(clientChunksDir, {
withFileTypes: true,
})
const chunkContents = staticChunksDirents
.filter((dirent) => dirent.isFile())
.map((chunkDirent) =>
fs.readFileSync(join(chunkDirent.path, chunkDirent.name), 'utf8')
)

expect(
chunkContents.some((content) => content.includes('client-comp-imported'))
).toBe(true)
Expand Down
5 changes: 2 additions & 3 deletions test/turbopack-build-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15773,13 +15773,12 @@
"test/production/app-dir/client-components-tree-shaking/index.test.ts": {
"passed": [
"app-dir client-components-tree-shaking should able to resolve the client module entry with mixing rexports",
"app-dir client-components-tree-shaking should handle mixing namespace imports and named imports from client components"
],
"failed": [
"app-dir client-components-tree-shaking should handle mixing namespace imports and named imports from client components",
"app-dir client-components-tree-shaking should only include imported components 3rd party package in browser bundle with direct imports",
"app-dir client-components-tree-shaking should only include imported relative components in browser bundle with direct imports",
"app-dir client-components-tree-shaking should only include the imported identifier of CJS module in browser bundle"
],
"failed": [],
"pending": [],
"flakey": [],
"runtimeError": false
Expand Down
Loading