@@ -266,13 +266,51 @@ exports.setUserSpecs = (bsConfig, args) => {
266266 }
267267}
268268
269- // env option must be set only from command line args as a string
270269exports . setTestEnvs = ( bsConfig , args ) => {
270+ // env option must be set only from command line args as a string
271271 if ( ! this . isUndefined ( args . env ) ) {
272272 bsConfig . run_settings . env = this . fixCommaSeparatedString ( args . env ) ;
273273 } else {
274274 bsConfig . run_settings . env = null ;
275275 }
276+
277+ // set env vars which start with CYPRESS_ and cypress_
278+ let pattern = / ^ c y p r e s s _ / i;
279+ let matchingKeys = this . getKeysMatchingPattern ( process . env , pattern ) ;
280+ if ( matchingKeys ) {
281+ let envKeys = [ ] ;
282+ matchingKeys . forEach ( ( envVar ) => {
283+ envKeys . push ( `${ envVar } =${ process . env . envVar } ` ) ;
284+ } ) ;
285+
286+ if ( bsConfig . run_settings . env !== null ) {
287+ bsConfig . run_settings . env = `${ bsConfig . run_settings . env } ,${ envKeys . join ( ',' ) } ` ;
288+ } else {
289+ bsConfig . run_settings . env = matchingKeys . join ( ',' ) ;
290+ }
291+ }
292+
293+ // set env vars which are defined in system_env_vars key
294+ if ( ! this . undefined ( bsConfig . run_settings . system_env_vars ) ) {
295+ let system_env_vars = bsConfig . run_settings . system_env_vars ;
296+ let envKeys = [ ] ;
297+ system_env_vars . forEach ( ( envVar ) => {
298+ envKeys . push ( `${ envVar } =${ process . env . envVar } ` ) ;
299+ } ) ;
300+
301+ if ( bsConfig . run_settings . env !== null ) {
302+ bsConfig . run_settings . env = `${ bsConfig . run_settings . env } ,${ system_env_vars . join ( ',' ) } ` ;
303+ } else {
304+ bsConfig . run_settings . env = system_env_vars . join ( ',' ) ;
305+ }
306+ }
307+ }
308+
309+ exports . getKeysMatchingPattern = ( obj , pattern ) => {
310+ let matchingKeys = Object . keys ( obj ) . filter ( function ( key ) {
311+ return pattern . test ( key ) ;
312+ } ) ;
313+ return matchingKeys ;
276314}
277315
278316exports . fixCommaSeparatedString = ( string ) => {
0 commit comments