mock-env
v0.2.0
Published
morph process.env by adding/chaning/removing env vars for the lifetime of a callback
Downloads
26,030
Readme
mock-env
morph process.env by adding/chaning/removing env vars for the lifetime of a callback.
This is intended for use in unit tests. It modifies process.env per passed arguments, calls a designated callback, then restores process.env to its original value.
Beware using this in an asynchronous manner.
Install
npm install mock-env
Usage Example
var morph = require('mock-env').morph;
var result = morph(function() {
return process.env['LOGNAME'];
}, {
LOGNAME: 'someone-else';
});
// result will be 'someone-else', not your LOGNAME
Function
var result = morph(callback [,setVars={} [,removeVars=[]]])
Returns whatever callback() returns.
Call back 'callback' after morphing process.env by setting (adding or modifying) properties per the setVars object and un setting (deleting) any properties named in the removeVars list.
options:
callback
- (required) the callback to invoke in the morphed environmentsetVars
- object with zero or more key-value pairs to set in process.envremoveVars
- array of names that should be removed from process.env
license
MIT