Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set environment variables in Mocha under windows

How would it be possible to set environment variables for Mocha tests under windows OS? I'm only able to add only 1 variable but not more, example:

"name": "node-app",
"version": "1.0.0",
"description": "some app",
"main": "index.js",
"scripts": {
    "integration-test": "SET TEST_MODE=handler&mocha tests/test_cases/*.js --reporter spec"
},
"author": "",

This can be done under windows using cross-env without changing the source code, we only need to install it as a dev dependency and then add it to the script line. But still under other linux we can simply do this :

"scripts": {
    "integration-test": "env KEY1=YOUR_KEY1 KEY2=YOUR_KEY2 mocha test"
},

I wonder if it is possible to make it happen for windows without additional libraries?

like image 428
user2517028 Avatar asked Jan 31 '26 09:01

user2517028


1 Answers

There's a package on npm solving this, called cross-env.

From the documentation:

{
  "scripts": {
    "build": "cross-env NODE_ENV=production webpack --config build/webpack.config.js"
  }
}

You can also set multiple variables easily.

like image 200
Karamell Avatar answered Feb 03 '26 01:02

Karamell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!