Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
jpulec opened this issue Nov 29, 2022 · 0 comments
Open
3 tasks done

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

jpulec opened this issue Nov 29, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@jpulec
Copy link

jpulec commented Nov 29, 2022

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?
@jpulec jpulec added the bug Something isn't working label Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant