'How to set a node environment variable when runnig via webpack
I am currently setting up testing with jest/puppeteer and want to make use of the process.env.HEADLESS environment variable of the default config of jest-puppeteer:
module.exports = {
launch: {
dumpio: true,
headless: process.env.HEADLESS !== 'false'
product: 'chrome'
},
browserContext: 'default',
}
I run my page via webpack and would like to create a different run configuration that does not use headless chrome:
"test": "webpack serve --config ./webpack.config.js --mode development --env testvisibly --devtool source-map",
I understand that I need to set this environment variable in NODE, but am currently only setting environment variables in webpack. Those it seems I cannot access in the puppeteer configuration.
What do I need to do, how do I need to write my script to
- run webpack
- also have a switch available in my configuration file to turn headless on/off
- I want to put this switch into the package.json -> scripts
Thanks a lot for your support.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
