|
| 1 | +/** |
| 2 | + * The project's path (SPEC §2.1, J2.15, G1): an app under a directory whose |
| 3 | + * name carries characters a project path may (`#` as in `C#` or `project |
| 4 | + * #2`, `%`, spaces, parentheses, non-ASCII) is code-split like any other |
| 5 | + * app, in every bundler's build. A `#` matters most: read as a URL fragment, |
| 6 | + * every route module of the app silently stays unsplit (nothing fails, the |
| 7 | + * app only ships everything eagerly). |
| 8 | + */ |
| 9 | +import { expect, test } from 'vitest' |
| 10 | +import { build, head, rootRoute, ssrRenderEntry } from '../build-harness' |
| 11 | + |
| 12 | +type BundlerName = 'vite' | 'rspack' | 'webpack' |
| 13 | + |
| 14 | +const route = `${head}function Page() { |
| 15 | + return <p>MARK_COMPONENT</p> |
| 16 | +} |
| 17 | +export const Route = createFileRoute('/')({ |
| 18 | + loader: () => 'MARK_LOADER', |
| 19 | + component: Page, |
| 20 | +}) |
| 21 | +` |
| 22 | + |
| 23 | +/** Builds the app under a directory named with `prefix` and returns what the build placed where, and the render. */ |
| 24 | +async function buildUnder(bundler: BundlerName, prefix: string) { |
| 25 | + const app = await build({ |
| 26 | + bundler, |
| 27 | + env: 'ssr', |
| 28 | + minify: false, |
| 29 | + prefix, |
| 30 | + files: { |
| 31 | + 'routes/__root.tsx': rootRoute, |
| 32 | + 'routes/index.tsx': route, |
| 33 | + 'entry.ts': ssrRenderEntry, |
| 34 | + }, |
| 35 | + }) |
| 36 | + const run = await app.run( |
| 37 | + `return [await entry.render(entry.Route.options.component), await entry.Route.options.loader({})]`, |
| 38 | + ) |
| 39 | + return { |
| 40 | + root: app.root, |
| 41 | + component: app.where('MARK_COMPONENT'), |
| 42 | + rendered: run.result, |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +const directories = [ |
| 47 | + { name: 'a # (C#, project #2)', prefix: '.project-path-C# project #2-' }, |
| 48 | + { name: 'a %', prefix: '.project-path-100%-' }, |
| 49 | + { |
| 50 | + name: 'spaces, parentheses and non-ASCII', |
| 51 | + prefix: '.project-path-café 日本語 (2)+-', |
| 52 | + }, |
| 53 | +] |
| 54 | + |
| 55 | +test.each( |
| 56 | + directories.flatMap(({ name, prefix }) => |
| 57 | + (['vite', 'rspack', 'webpack'] as const).map((bundler) => ({ |
| 58 | + name, |
| 59 | + prefix, |
| 60 | + bundler, |
| 61 | + })), |
| 62 | + ), |
| 63 | +)( |
| 64 | + 'an app under a directory with $name is code-split and renders ($bundler)', |
| 65 | + async ({ prefix, bundler }) => { |
| 66 | + const result = await buildUnder(bundler, prefix) |
| 67 | + expect(result.root).toContain(prefix.slice(1, -1)) |
| 68 | + expect(result).toMatchObject({ |
| 69 | + component: 'lazy', |
| 70 | + rendered: ['<p>MARK_COMPONENT</p>', 'MARK_LOADER'], |
| 71 | + }) |
| 72 | + }, |
| 73 | + 120_000, |
| 74 | +) |
0 commit comments