Environment management helper. More info: https://github.com/qx57/relax-env-json
npm install relax-env-json* node.js ^17.9.0
* @types/node ^17.0.41
This pack help you set your test environments so easy. Just create in root path environments.json like this:
``json`
{
"deafult": {
// Some your settings
}
}
and enjoy!
1. install relax-env-json:
`bash`
> npm i relax-env-json
2. create in root path environments.json:
`json`
{
"default": {
"foo": "bar",
"isEnabled": true,
...
"someObj": {
...
}
}
}
More info below.
3. add requirement into your test:
`js`
const env = require('relax-env-json');
let defaultEnvironment = env.getEnvironment();
4. use your environment settings:
`js`
defaultEnvironment.foo; // = "bar"
You can include various files, not only environment.json. For use anoither env file set process variable file:
`bash`
> env file=another/environmen/file.json mocha test.js
For set environment name dofferent than _default_ you can use defaultEnvName field in env file:
`json`
{
"defaultEnvName": "myEnv",
...
"myEnv": {
// some your settings
}
}
You can use process variable name for it:
`bash`
> env name=myEnv mocha test.js
If you want to get variables from another environment you have two ways:
* you may get variables without environment switch:
`js`
anotherEnv = env.getEnvironmentByName('myEnv');
* or you can set new default environment:
`js`
defaultEnvironment = env.setEnvironment('myEnv');
`json``
{
"defaultEnvName": string (optional, if no default field - required)
"default": any (required, if used defaultEnvName - optional)
"another-environment": any (optional)
}