EN
JavaScript | Jest - pass env variables into jest.config.js file
3
points
In this short article, we would like to show how to pass env variables into jest.config.js file in JavaScript project.
Project configuration
Example jest.config.js file:
// ...
// ...
module.exports = () => {
const {variable1, variable2, variable3} = process.env;
// ...
return {
// ...
};
};
Where:
jest.config.jsshould be located directly in the project directory.
Running tests
Using a Bash environment:
- open command line,
- go to the project directory,
- run the command:
variable1=value1 variable2=value2 variable3=value3 npx jest