relax-env-json

0.0.4 • Public • Published

relax-env-json

Requirements

  • node.js ^17.9.0

Dependencies

  • @types/node ^17.0.41

Summary

This pack help you set your test environments so easy. Just create in root path environments.json like this:

{
   "deafult": {
        // Some your settings
    } 
}

and enjoy!

Get started

  1. install relax-env-json:
> npm i relax-env-json
  1. create in root path environments.json:
{
    "default": {
        "foo": "bar",
        "isEnabled": true,
        ...
        "someObj": {
            ...
        }
    }
}

More info below.

  1. add requirement into your test:
const env = require('relax-env-json');
let defaultEnvironment = env.getEnvironment();
  1. use your environment settings:
defaultEnvironment.foo; // = "bar"

Advanced settings

Different environment files usage

You can include various files, not only environment.json. For use anoither env file set process variable file:

> env file=another/environmen/file.json mocha test.js

Set default environment name

For set environment name dofferent than default you can use defaultEnvName field in env file:

{
    "defaultEnvName": "myEnv",
    ...
    "myEnv": {
        // some your settings
    }
}

Switch environments through cli

You can use process variable name for it:

> env name=myEnv mocha test.js

Switch environments in runtime

If you want to get variables from another environment you have two ways:

  • you may get variables without environment switch:
anotherEnv = env.getEnvironmentByName('myEnv');
  • or you can set new default environment:
defaultEnvironment = env.setEnvironment('myEnv');

Environments.json format

{
    "defaultEnvName": string (optional, if no default field - required)
    "default": any (required, if used defaultEnvName - optional)
    "another-environment": any (optional)
}

Contributors

qx57

Package Sidebar

Install

npm i relax-env-json

Weekly Downloads

2

Version

0.0.4

License

GPL-2.0-only

Unpacked Size

35.4 kB

Total Files

9

Last publish

Collaborators

  • qx57