Skip to content

BUG: Spawned Process does Not Reflect Parent process.env #8

Description

@jpulec

Describe your issue:
There's an issue with jest where it does not properly pass along the process.env value when calling spawn. This is because jest sandboxes and isolates a copy of process.env which means that any changes to process.env made inside of a test setup script, for example, will not be reflected in subprocess environment. One simple way to resolve this is to just explicitly pass process.env to the spawn call.

Relevant Jest issue here.

The code of the library usage:

import { prepareEnvironment } from '@gmrchk/cli-testing-library';

process.env.COOL_ENV_VAR = 'foo';

it('program', async () => {
    const { cleanup, exec path } = await prepareEnvironment();
    
    const { stdout } = await exec('printenv'); 
    
    console.log(stdout); // COOL_ENV_VAR is not there

    await cleanup();
});

Before creating this issue, did you think of...:

  • Have you checked closed issues for similar/related problems?
  • Have you provided all helpful information available?
  • Have you considered creating a demo repository, or a link to your running project where the problem is reproducible?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions