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

Set environment variables before running tests. #138

Closed
Nxtra opened this issue Jan 18, 2021 · 4 comments
Closed

Set environment variables before running tests. #138

Nxtra opened this issue Jan 18, 2021 · 4 comments

Comments

@Nxtra
Copy link

Nxtra commented Jan 18, 2021

How can I specify an environment variable that should be available during the execution of my tests?

Eg. I want to set the AWS_DEFAULT_PROFILE environment variable to run my test.

@firsttris
Copy link
Owner

firsttris commented Jan 18, 2021

take a look here:
#123

this will only work for debug

@firsttris
Copy link
Owner

generally it should also be possible to define an alternative jest command

"scripts": {
  "test": "NODE_ENV=test jest"
},

than in your vscode config

"jestrunner.jestCommand": "npm run test --"

@Nxtra
Copy link
Author

Nxtra commented Jan 19, 2021

generally it should also be possible to define an alternative jest command

"scripts": {
  "test": "NODE_ENV=test jest"
},

than in your vscode config

"jestrunner.jestCommand": "npm run test --"

Nice, that works for running. I found the debug config via the linked issue.

For others coming here, to set env vars for run and debug:

Setup
.vscode/settings.json:

{
  "jestrunner.jestCommand": "npm run test --",
  "jestrunner.debugOptions": {
    "env": {
      "AWS_PROFILE": "your-profile"
    }
  }
}

package.json

scripts : {
  "test": "AWS_PROFILE=your-profile jest",
}

@firsttris
Copy link
Owner

nice thx for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants