@@ -18,19 +18,36 @@ export interface BootedServer {
1818 pid : number
1919}
2020
21- export async function boot ( target : Target , withDb : boolean ) : Promise < BootedServer | { skipped : string } > {
22- const proc = Bun . spawn ( [ process . execPath , join ( BENCH_ROOT , 'servers' , target . server ) ] , {
21+ /** Keep benchmark targets out of the application's preload graph. */
22+ export function serverCommand ( server : string ) : string [ ] {
23+ return [
24+ process . execPath ,
25+ `--config=${ join ( BENCH_ROOT , 'bunfig.toml' ) } ` ,
26+ join ( BENCH_ROOT , 'servers' , server ) ,
27+ ]
28+ }
29+
30+ /** Give every framework the same production environment. */
31+ export function serverEnvironment ( target : Target , withDb : boolean , scenarioId ?: string ) : Record < string , string > {
32+ return {
33+ ...process . env ,
34+ APP_ENV : 'production' ,
35+ NODE_ENV : 'production' ,
36+ BENCH_PORT : String ( PORT ) ,
37+ BENCH_DB : withDb ? '1' : '0' ,
38+ BENCH_DB_FILE : FIXTURE ,
39+ DB_DATABASE_PATH : FIXTURE ,
40+ ...( scenarioId ? { BENCH_SCENARIO : scenarioId } : { } ) ,
41+ ...target . env ,
42+ } as Record < string , string >
43+ }
44+
45+ export async function boot ( target : Target , withDb : boolean , scenario ?: Scenario ) : Promise < BootedServer | { skipped : string } > {
46+ const proc = Bun . spawn ( serverCommand ( target . server ) , {
2347 cwd : REPO_ROOT ,
2448 stdout : 'pipe' ,
2549 stderr : 'pipe' ,
26- env : {
27- ...process . env ,
28- BENCH_PORT : String ( PORT ) ,
29- BENCH_DB : withDb ? '1' : '0' ,
30- BENCH_DB_FILE : FIXTURE ,
31- DB_DATABASE_PATH : FIXTURE ,
32- ...target . env ,
33- } as Record < string , string > ,
50+ env : serverEnvironment ( target , withDb , scenario ?. id ) ,
3451 } )
3552
3653 const deadline = Date . now ( ) + 60_000
@@ -43,7 +60,7 @@ export async function boot(target: Target, withDb: boolean): Promise<BootedServe
4360 throw new Error ( `${ target . id } server exited ${ proc . exitCode } :\n${ err } ` )
4461 }
4562 try {
46- const res = await fetch ( `http://127.0.0.1:${ PORT } /bench/json` )
63+ const res = await fetch ( `http://127.0.0.1:${ PORT } ${ scenario ?. path ?? ' /bench/json' } ` )
4764 if ( res . ok ) {
4865 await res . arrayBuffer ( )
4966 break
0 commit comments