@epic-web/app-launcher
Version:
Utility for launching your applications on a per-test basis.
42 lines • 1.57 kB
JavaScript
import { AppProcess, kUrl } from './app-process.js';
import { waitForPort } from './wait-for-port.js';
export const kLauncherOptions = Symbol('kLauncherOptions');
export function defineLauncher(options) {
return {
[kLauncherOptions]: options,
async run(runOptions) {
const context = (await options.context?.()) ?? {};
const baseEnv = await options.extends?.[kLauncherOptions].env?.({
context,
});
const customEnv = await options.env?.({ context });
const env = {
...(baseEnv || {}),
...(customEnv || {}),
};
const command = await options.command({ context, env });
// Spawn the application.
const app = new AppProcess({
command,
env,
cwd: runOptions?.cwd,
});
const childProcess = await app.launch();
if (options?.debug) {
childProcess.stdout?.pipe(process.stdout);
childProcess.stderr?.pipe(process.stderr);
}
// Wait for the provided application URL to be up.
const url = await options.url({
context,
env,
appProcess: childProcess,
});
const resolvedUrl = url instanceof URL ? url : new URL(url);
app[kUrl] = resolvedUrl;
await waitForPort(+resolvedUrl.port);
return app;
},
};
}
//# sourceMappingURL=define-launcher.js.map