@@ -89,6 +89,9 @@ export function createPool(ctx: Vitest): ProcessPool {
8989 const environments = await getSpecificationsEnvironments ( specs )
9090 const groups = groupSpecs ( sorted )
9191
92+ const projectEnvs = new WeakMap < TestProject , Partial < NodeJS . ProcessEnv > > ( )
93+ const projectExecArgvs = new WeakMap < TestProject , string [ ] > ( )
94+
9295 for ( const group of groups ) {
9396 if ( ! group ) {
9497 continue
@@ -114,6 +117,33 @@ export function createPool(ctx: Vitest): ProcessPool {
114117 throw new Error ( `Cannot find the environment. This is a bug in Vitest.` )
115118 }
116119
120+ let env = projectEnvs . get ( project )
121+ if ( ! env ) {
122+ env = {
123+ ...process . env ,
124+ ...options . env ,
125+ ...ctx . config . env ,
126+ ...project . config . env ,
127+ }
128+
129+ // env are case-insensitive on Windows, but spawned processes don't support it
130+ if ( isWindows ) {
131+ for ( const name in env ) {
132+ env [ name . toUpperCase ( ) ] = env [ name ]
133+ }
134+ }
135+ projectEnvs . set ( project , env )
136+ }
137+
138+ let execArgv = projectExecArgvs . get ( project )
139+ if ( ! execArgv ) {
140+ execArgv = [
141+ ...options . execArgv ,
142+ ...project . config . execArgv ,
143+ ]
144+ projectExecArgvs . set ( project , execArgv )
145+ }
146+
117147 taskGroup . push ( {
118148 context : {
119149 pool,
@@ -126,8 +156,8 @@ export function createPool(ctx: Vitest): ProcessPool {
126156 workerId : workerId ++ ,
127157 } ,
128158 project,
129- env : { ... options . env , ... project . config . env } ,
130- execArgv : [ ... options . execArgv , ... project . config . execArgv ] ,
159+ env,
160+ execArgv,
131161 worker : pool ,
132162 isolate : project . config . isolate ,
133163 memoryLimit : getMemoryLimit ( ctx . config , pool ) ?? null ,
@@ -250,18 +280,9 @@ function resolveOptions(ctx: Vitest) {
250280 NODE_ENV : process . env . NODE_ENV || 'test' ,
251281 VITEST_MODE : ctx . config . watch ? 'WATCH' : 'RUN' ,
252282 FORCE_TTY : isatty ( 1 ) ? 'true' : '' ,
253- ...process . env ,
254- ...ctx . config . env ,
255283 } ,
256284 }
257285
258- // env are case-insensitive on Windows, but spawned processes don't support it
259- if ( isWindows ) {
260- for ( const name in options . env ) {
261- options . env [ name . toUpperCase ( ) ] = options . env [ name ]
262- }
263- }
264-
265286 return options
266287}
267288
0 commit comments