chore: speed up vite tests (#3258)
This commit is contained in:
@@ -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!, ".."),
|
||||
|
||||
Reference in New Issue
Block a user