Skip to content

Commit 51a3aa2

Browse files
committed
test: test dynamic base on browser
1 parent 9ea817c commit 51a3aa2

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/plugin-rsc/e2e/fixture.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function editFileJson(filepath: string, edit: (s: string) => string) {
200200
export async function setupInlineFixture(options: {
201201
src: string
202202
dest: string
203-
files?: Record<string, string>
203+
files?: Record<string, string | { edit: (s: string) => string }>
204204
}) {
205205
fs.rmSync(options.dest, { recursive: true, force: true })
206206
fs.mkdirSync(options.dest, { recursive: true })
@@ -214,6 +214,12 @@ export async function setupInlineFixture(options: {
214214
// write additional files
215215
if (options.files) {
216216
for (let [filename, contents] of Object.entries(options.files)) {
217+
if (typeof contents === 'object' && 'edit' in contents) {
218+
const file = path.join(options.dest, filename)
219+
const editted = contents.edit(fs.readFileSync(file, 'utf-8'))
220+
fs.writeFileSync(file, editted)
221+
continue
222+
}
217223
let filepath = path.join(options.dest, filename)
218224
fs.mkdirSync(path.dirname(filepath), { recursive: true })
219225
// strip indent

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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,9 @@ test.describe(() => {
249249
const root = 'examples/e2e/temp/renderBuiltUrl-runtime'
250250

251251
test.beforeAll(async () => {
252-
// TODO: test client shared chunk
253252
const renderBuiltUrl = (filename: string) => {
254253
return {
255-
runtime: `globalThis.__dynamicBase + ${JSON.stringify(filename)}`,
254+
runtime: `__dynamicBase + ${JSON.stringify(filename)}`,
256255
}
257256
}
258257
await setupInlineFixture({
@@ -293,11 +292,36 @@ test.describe(() => {
293292
}
294293
}
295294
],
295+
// tweak chunks to test "__dynamicBase" used on browser for "__vite__mapDeps"
296+
environments: {
297+
client: {
298+
build: {
299+
rollupOptions: {
300+
output: {
301+
manualChunks: (id) => {
302+
if (id.includes('node_modules/react/')) {
303+
return 'lib-react';
304+
}
305+
}
306+
},
307+
}
308+
}
309+
}
310+
},
296311
experimental: {
297312
renderBuiltUrl: ${renderBuiltUrl.toString()}
298-
}
313+
},
299314
})
300315
`,
316+
'src/root.tsx': {
317+
// define __dynamicBase on browser via head script
318+
edit: (s: string) =>
319+
s.replace(
320+
'</head>',
321+
() =>
322+
`<script>{\`globalThis.__dynamicBase = $\{JSON.stringify(globalThis.__dynamicBase ?? "/")}\`}</script></head>`,
323+
),
324+
},
301325
},
302326
})
303327
})

0 commit comments

Comments
 (0)