2022-06-06 16:02:13 +00:00
|
|
|
import { readableStreamFromReader, fromFileUrl } from './deps.js';
|
2022-03-30 12:42:19 +00:00
|
|
|
const dir = new URL('./', import.meta.url);
|
|
|
|
|
|
|
|
export async function runBuild(fixturePath) {
|
|
|
|
let proc = Deno.run({
|
|
|
|
cmd: ['node', '../../../../../astro/astro.js', 'build', '--silent'],
|
2022-03-30 12:43:13 +00:00
|
|
|
cwd: fromFileUrl(new URL(fixturePath, dir)),
|
2022-03-30 12:42:19 +00:00
|
|
|
});
|
|
|
|
await proc.status();
|
|
|
|
return async () => await proc.close();
|
|
|
|
}
|
|
|
|
|
2022-06-06 16:02:13 +00:00
|
|
|
export async function startModFromImport(baseUrl) {
|
|
|
|
const entryUrl = new URL('./dist/server/entry.mjs', baseUrl);
|
|
|
|
const mod = await import(entryUrl);
|
|
|
|
|
2022-04-15 21:02:19 +00:00
|
|
|
if (!mod.running()) {
|
2022-04-15 21:01:33 +00:00
|
|
|
mod.start();
|
|
|
|
}
|
2022-06-06 16:02:13 +00:00
|
|
|
|
|
|
|
return () => mod.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function startModFromSubprocess(baseUrl) {
|
|
|
|
const entryUrl = new URL('./dist/server/entry.mjs', baseUrl);
|
|
|
|
let proc = Deno.run({
|
|
|
|
cmd: ['deno', 'run', '--allow-env', '--allow-net', fromFileUrl(entryUrl)],
|
|
|
|
cwd: fromFileUrl(baseUrl),
|
|
|
|
stderr: 'piped'
|
|
|
|
});
|
|
|
|
const stderr = readableStreamFromReader(proc.stderr);
|
|
|
|
const dec = new TextDecoder();
|
|
|
|
for await(let bytes of stderr) {
|
|
|
|
let msg = dec.decode(bytes);
|
|
|
|
if(msg.includes(`Server running`)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return () => proc.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function runBuildAndStartApp(fixturePath, cb) {
|
|
|
|
const url = new URL(fixturePath, dir);
|
|
|
|
const close = await runBuild(fixturePath);
|
|
|
|
const stop = await startModFromImport(url);
|
|
|
|
|
|
|
|
await cb();
|
|
|
|
await stop();
|
|
|
|
await close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export async function runBuildAndStartAppFromSubprocess(fixturePath, cb) {
|
|
|
|
const url = new URL(fixturePath, dir);
|
|
|
|
const close = await runBuild(fixturePath);
|
|
|
|
const stop = await startModFromSubprocess(url);
|
|
|
|
|
2022-03-30 12:42:19 +00:00
|
|
|
await cb();
|
2022-06-06 16:02:13 +00:00
|
|
|
await stop();
|
2022-03-30 12:42:19 +00:00
|
|
|
await close();
|
|
|
|
}
|