chore: speed up vite tests (#3258)

This commit is contained in:
Marvin Hagemeister
2025-08-26 09:52:26 +02:00
committed by GitHub
parent a743b0c5d3
commit adc5c2e4a8
3 changed files with 44 additions and 41 deletions
+21 -8
View File
@@ -47,12 +47,8 @@ async function copyDir(from: string, to: string) {
}
}
export async function withDevServer(
fixtureDir: string,
fn: (address: string, dir: string) => void | Promise<void>,
env: Record<string, string> = {},
) {
await using tmp = await withTmpDir({
export async function prepareDevServer(fixtureDir: string) {
const tmp = await withTmpDir({
dir: path.join(import.meta.dirname!, ".."),
prefix: "tmp_vite_",
});
@@ -72,16 +68,33 @@ export default defineConfig({
`,
);
return tmp;
}
export async function launchDevServer(
dir: string,
fn: (address: string, dir: string) => void | Promise<void>,
env: Record<string, string> = {},
) {
await withChildProcessServer(
{
cwd: tmp.dir,
cwd: dir,
args: ["run", "-A", "--cached-only", "npm:vite", "--port", "0"],
env,
},
async (address) => await fn(address, tmp.dir),
async (address) => await fn(address, dir),
);
}
export async function withDevServer(
fixtureDir: string,
fn: (address: string, dir: string) => void | Promise<void>,
env: Record<string, string> = {},
) {
await using tmp = await prepareDevServer(fixtureDir);
await launchDevServer(tmp.dir, fn, env);
}
export async function buildVite(fixtureDir: string) {
const tmp = await withTmpDir({
dir: path.join(import.meta.dirname!, ".."),