diff --git a/packages/plugin-rsc/e2e/root.test.ts b/packages/plugin-rsc/e2e/root.test.ts index 5ff9cbc74..8bcb648d2 100644 --- a/packages/plugin-rsc/e2e/root.test.ts +++ b/packages/plugin-rsc/e2e/root.test.ts @@ -45,3 +45,50 @@ test.describe(() => { defineStarterTest(f) }) }) + +// Test that the RSC plugin works when `root` is passed as a CLI argument +// e.g. `vite dev ./app` where the app lives in a subdirectory. +// This effectively tests `createServer/createBuilder({ root })` +// and then loading config file from the specified root. +test.describe('root-config', () => { + const root = 'examples/e2e/temp/root-config' + + test.beforeAll(async () => { + await setupInlineFixture({ + src: 'examples/starter', + dest: `${root}/app`, + files: { + 'vite.config.base.ts': { cp: 'vite.config.ts' }, + 'vite.config.ts': /* js */ ` + import baseConfig from './vite.config.base.ts' + import path from "node:path"; + for (const e of Object.values(baseConfig.environments)) { + e.build.rollupOptions.input.index = path.resolve( + 'app', + e.build.rollupOptions.input.index, + ); + } + export default baseConfig; + `, + }, + }) + }) + + test.describe('dev', () => { + const f = useFixture({ root, mode: 'dev', command: 'vite dev ./app' }) + const oldCreateEditor = f.createEditor + f.createEditor = (filePath: string) => + oldCreateEditor(path.resolve(root, 'app', filePath)) + defineStarterTest(f) + }) + + test.describe('build', () => { + const f = useFixture({ + root, + mode: 'build', + buildCommand: 'vite build ./app', + command: 'vite preview ./app', + }) + defineStarterTest(f) + }) +})