Skip to content

Commit 4f1d8dc

Browse files
committed
test: e2e
1 parent be90696 commit 4f1d8dc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

packages/plugin-rsc/e2e/basic.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
waitForHydration,
1010
} from './helper'
1111
import { x } from 'tinyexec'
12+
import { normalizePath, type Rollup } from 'vite'
13+
import path from 'node:path'
1214

1315
test.describe('dev-default', () => {
1416
const f = useFixture({ root: 'examples/basic', mode: 'dev' })
@@ -45,6 +47,17 @@ test.describe('dev-initial', () => {
4547
test.describe('build-default', () => {
4648
const f = useFixture({ root: 'examples/basic', mode: 'build' })
4749
defineTest(f)
50+
51+
test('custom client chunk', async () => {
52+
const { chunks }: { chunks: Rollup.OutputChunk[] } = JSON.parse(
53+
f.createEditor('dist/client/.vite/test.json').read(),
54+
)
55+
const chunk = chunks.find((c) => c.name === 'custom-chunk')
56+
const expected = [1, 2, 3].map((i) =>
57+
normalizePath(path.join(f.root, `src/routes/chunk/client${i}.tsx`)),
58+
)
59+
expect(chunk?.moduleIds).toEqual(expect.arrayContaining(expected))
60+
})
4861
})
4962

5063
test.describe('dev-non-optimized-cjs', () => {

packages/plugin-rsc/examples/basic/vite.config.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from 'vite'
1212
// import inspect from 'vite-plugin-inspect'
1313
import path from 'node:path'
14+
import fs from 'node:fs'
1415
import { fileURLToPath } from 'node:url'
1516

1617
export default defineConfig({
@@ -48,6 +49,23 @@ export default defineConfig({
4849
}
4950
},
5051
},
52+
{
53+
// dump entire bundle to analyze build output for e2e
54+
name: 'test-metadata',
55+
enforce: 'post',
56+
writeBundle(options, bundle) {
57+
const chunks: Rollup.OutputChunk[] = []
58+
for (const chunk of Object.values(bundle)) {
59+
if (chunk.type === 'chunk') {
60+
chunks.push(chunk)
61+
}
62+
}
63+
fs.writeFileSync(
64+
path.join(options.dir!, '.vite/test.json'),
65+
JSON.stringify({ chunks }, null, 2),
66+
)
67+
},
68+
},
5169
{
5270
name: 'test-server-assets-security',
5371
buildStart() {

0 commit comments

Comments
 (0)