summaryrefslogtreecommitdiff
path: root/deps/npm/test/common-tap.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test/common-tap.js')
-rw-r--r--deps/npm/test/common-tap.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/deps/npm/test/common-tap.js b/deps/npm/test/common-tap.js
index 14c1581f78..8fe5b78fd9 100644
--- a/deps/npm/test/common-tap.js
+++ b/deps/npm/test/common-tap.js
@@ -2,6 +2,7 @@
var fs = require('graceful-fs')
var readCmdShim = require('read-cmd-shim')
var isWindows = require('../lib/utils/is-windows.js')
+var extend = Object.assign || require('util')._extend
// cheesy hackaround for test deps (read: nock) that rely on setImmediate
if (!global.setImmediate || !require('timers').setImmediate) {
@@ -42,6 +43,7 @@ exports.npm = function (cmd, opts, cb) {
opts = opts || {}
opts.env = opts.env || process.env
+ if (opts.env._storage) opts.env = opts.env._storage
if (!opts.env.npm_config_cache) {
opts.env.npm_config_cache = npm_config_cache
}
@@ -120,3 +122,39 @@ exports.pendIfWindows = function (why) {
console.log('not ok 1 # todo ' + why)
process.exit(0)
}
+
+exports.newEnv = function () {
+ return new Environment(process.env)
+}
+
+function Environment (env) {
+ this._storage = extend({}, env)
+}
+Environment.prototype = {}
+
+Environment.prototype.delete = function (key) {
+ var args = Array.isArray(key) ? key : arguments
+ var ii
+ for (ii = 0; ii < args.length; ++ii) {
+ delete this._storage[args[ii]]
+ }
+ return this
+}
+
+Environment.prototype.clone = function () {
+ return new Environment(this._storage)
+}
+
+Environment.prototype.extend = function (env) {
+ var self = this
+ var args = Array.isArray(env) ? env : arguments
+ var ii
+ for (ii = 0; ii < args.length; ++ii) {
+ var arg = args[ii]
+ if (!arg) continue
+ Object.keys(arg).forEach(function (name) {
+ self._storage[name] = arg[name]
+ })
+ }
+ return this
+}