Languages
[Edit]
EN

JavaScript | Jest - pass env variables into jest.config.js file

3 points
Created by:
Creg
9600

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.js should be located directly in the project directory.

 

Running tests

Using a Bash environment:

  1. open command line,
  2. go to the project directory,
  3. run the command:
    variable1=value1 variable2=value2 variable3=value3 npx jest

 

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join