@@ -6,6 +6,7 @@ import { createServer as createTcpServer, type Socket } from "node:net";
66import { mkdtempSync , rmSync , writeFileSync } from "node:fs" ;
77import { tmpdir } from "node:os" ;
88import { dirname , join } from "node:path" ;
9+ import { performance } from "node:perf_hooks" ;
910import { fileURLToPath } from "node:url" ;
1011import { promisify } from "node:util" ;
1112import { buildIsolatedCliEnv } from "e2e/isolation" ;
@@ -128,7 +129,7 @@ describe.each(["node", ...(hasBun ? ["bun"] : [])])(
128129 } ) ;
129130 try {
130131 // runNodeMain forces DO_NOT_TRACK=1; this test intentionally exercises telemetry.
131- const { stdout , stderr } = await execFileAsync (
132+ const execution = execFileAsync (
132133 runtime === "node" ? process . execPath : bun ,
133134 [
134135 ...( runtime === "node" ? [ "--import" , import . meta. resolve ( "tsx" ) ] : [ ] ) ,
@@ -140,8 +141,27 @@ describe.each(["node", ...(hasBun ? ["bun"] : [])])(
140141 ] ,
141142 { cwd : runtimeRoot , env : isolated . env , timeout : 8_000 , maxBuffer : 1024 * 1024 } ,
142143 ) ;
144+ let outputBuffer = "" ;
145+ let outputCompletedAt : number | undefined ;
146+ execution . child . stdout ?. on ( "data" , ( chunk : string ) => {
147+ outputBuffer += chunk ;
148+ if ( outputCompletedAt === undefined && outputBuffer . trimEnd ( ) . endsWith ( "}" ) ) {
149+ outputCompletedAt = performance . now ( ) ;
150+ }
151+ } ) ;
152+ const { stdout, stderr } = await execution ;
153+ const exitedAt = performance . now ( ) ;
143154 expect ( JSON . parse ( stdout ) ) . toEqual ( { ok : true } ) ;
144- expect ( JSON . parse ( stderr ) ) . toEqual ( { requests : disabled ? 0 : 1 , closed : ! disabled } ) ;
155+ const { outputToRunMs, ...connectionStatus } = JSON . parse ( stderr ) ;
156+ expect ( connectionStatus ) . toEqual ( { requests : disabled ? 0 : 1 , closed : ! disabled } ) ;
157+ if ( [ "fast" , "headers" , "body" ] . includes ( mode ) ) {
158+ expect ( outputToRunMs ) . toBeGreaterThanOrEqual ( 0 ) ;
159+ expect ( outputToRunMs , "output completion to run() return" ) . toBeLessThan ( 3_000 ) ;
160+ expect ( outputCompletedAt ) . toBeDefined ( ) ;
161+ expect ( exitedAt - outputCompletedAt ! , "output completion to process exit" ) . toBeLessThan (
162+ 3_000 ,
163+ ) ;
164+ }
145165 expect ( dnsQueries ) . toBe ( 0 ) ;
146166 if ( ! disabled && ! mode . startsWith ( "tls" ) ) {
147167 expect ( requests [ 0 ] ?. method ) . toBe ( "POST" ) ;
0 commit comments