New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

mock-env

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-env

morph process.env by adding/chaning/removing env vars for the lifetime of a callback

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

Build Status

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 environment
  • setVars - object with zero or more key-value pairs to set in process.env
  • removeVars - array of names that should be removed from process.env

license

MIT

Keywords

node

FAQs

Package last updated on 15 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts