@@ -4,6 +4,7 @@ import {splitSemicolonEnvVars} from "../../../src/argv.js";
44import chalk from "chalk-template" ;
55import { initSpawnSpy } from "../../mocks/utils.mock.js" ;
66import { WhenStatics } from "../../mocks/when-statics.js" ;
7+ import { execFile } from "child_process" ;
78
89beforeAll ( ( ) => {
910 initSpawnSpy ( WhenStatics . all ) ;
@@ -186,63 +187,32 @@ test("GCL_VARIABLE env split reaches handler as separate variables", async () =>
186187
187188// --- Integration test: spawns real CLI with GCL_VARIABLE env ---
188189
189- test ( "GCL_VARIABLE env var is split by CLI middleware" , async ( ) => {
190- const proc = Bun . spawn (
191- [ "bun" , "src/index.ts" , "test-job" , "--cwd" , "tests/test-cases/gcl-env-variable-split" ] ,
192- {
193- env : {
194- ...process . env ,
195- GCL_VARIABLE : "VAR1=from_env1;VAR2=from_env2" ,
196- } ,
197- stdout : "pipe" ,
198- stderr : "pipe" ,
199- } ,
200- ) ;
201-
202- const stdout = await new Response ( proc . stdout ) . text ( ) ;
203- const exitCode = await proc . exited ;
190+ function runCli ( envVars : Record < string , string > ) : Promise < { stdout : string ; exitCode : number } > {
191+ return new Promise ( ( resolve , reject ) => {
192+ execFile ( "bun" , [ "src/index.ts" , "test-job" , "--cwd" , "tests/test-cases/gcl-env-variable-split" ] , {
193+ env : { ...process . env , ...envVars } ,
194+ } , ( error , stdout ) => {
195+ if ( error && error . code === undefined ) return reject ( error ) ;
196+ resolve ( { stdout, exitCode : typeof error ?. code === "number" ? error . code : 0 } ) ;
197+ } ) ;
198+ } ) ;
199+ }
204200
201+ test ( "GCL_VARIABLE env var is split by CLI middleware" , async ( ) => {
202+ const { stdout, exitCode} = await runCli ( { GCL_VARIABLE : "VAR1=from_env1;VAR2=from_env2" } ) ;
205203 expect ( exitCode ) . toBe ( 0 ) ;
206204 expect ( stdout ) . toContain ( "from_env1" ) ;
207205 expect ( stdout ) . toContain ( "from_env2" ) ;
208206} , 30_000 ) ;
209207
210208test ( "GCL_VARIABLE with single value (no semicolon) works via CLI" , async ( ) => {
211- const proc = Bun . spawn (
212- [ "bun" , "src/index.ts" , "test-job" , "--cwd" , "tests/test-cases/gcl-env-variable-split" ] ,
213- {
214- env : {
215- ...process . env ,
216- GCL_VARIABLE : "VAR1=single_value" ,
217- } ,
218- stdout : "pipe" ,
219- stderr : "pipe" ,
220- } ,
221- ) ;
222-
223- const stdout = await new Response ( proc . stdout ) . text ( ) ;
224- const exitCode = await proc . exited ;
225-
209+ const { stdout, exitCode} = await runCli ( { GCL_VARIABLE : "VAR1=single_value" } ) ;
226210 expect ( exitCode ) . toBe ( 0 ) ;
227211 expect ( stdout ) . toContain ( "single_value" ) ;
228212} , 30_000 ) ;
229213
230214test ( "GCL_VARIABLE with three semicolon-separated values via CLI" , async ( ) => {
231- const proc = Bun . spawn (
232- [ "bun" , "src/index.ts" , "test-job" , "--cwd" , "tests/test-cases/gcl-env-variable-split" ] ,
233- {
234- env : {
235- ...process . env ,
236- GCL_VARIABLE : "VAR1=first;VAR2=second;VAR3=third" ,
237- } ,
238- stdout : "pipe" ,
239- stderr : "pipe" ,
240- } ,
241- ) ;
242-
243- const stdout = await new Response ( proc . stdout ) . text ( ) ;
244- const exitCode = await proc . exited ;
245-
215+ const { stdout, exitCode} = await runCli ( { GCL_VARIABLE : "VAR1=first;VAR2=second;VAR3=third" } ) ;
246216 expect ( exitCode ) . toBe ( 0 ) ;
247217 expect ( stdout ) . toContain ( "first" ) ;
248218 expect ( stdout ) . toContain ( "second" ) ;
0 commit comments