diff options
author | Rebecca Turner <me@re-becca.org> | 2017-05-10 10:35:33 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2017-05-26 04:55:10 +0300 |
commit | db056476979d33070dde7f92d79fc6ee831209a2 (patch) | |
tree | 82fd69757adff7a673628186739ae1f9b50c0e94 /test | |
parent | 9513cb2bee522250a7be925ef77b71fcff66c6ae (diff) |
tests: Filter run-script env
Diffstat (limited to 'test')
-rw-r--r-- | test/common-tap.js | 33 | ||||
-rw-r--r-- | test/tap/spec-local-specifiers.js | 2 |
2 files changed, 24 insertions, 11 deletions
diff --git a/test/common-tap.js b/test/common-tap.js index 8d9c4a0d4..16475411e 100644 --- a/test/common-tap.js +++ b/test/common-tap.js @@ -18,19 +18,21 @@ var path = require('path') var port = exports.port = 1337 exports.registry = 'http://localhost:' + port -process.env.npm_config_loglevel = 'error' -process.env.npm_config_progress = 'false' +const ourenv = {} +ourenv.npm_config_loglevel = 'error' +ourenv.npm_config_progress = 'false' var npm_config_cache = path.resolve(__dirname, 'npm_cache') -process.env.npm_config_cache = exports.npm_config_cache = npm_config_cache -process.env.npm_config_userconfig = exports.npm_config_userconfig = path.join(__dirname, 'fixtures', 'config', 'userconfig') -process.env.npm_config_globalconfig = exports.npm_config_globalconfig = path.join(__dirname, 'fixtures', 'config', 'globalconfig') -process.env.npm_config_global_style = 'false' -process.env.npm_config_legacy_bundling = 'false' -process.env.npm_config_fetch_retries = '0' -process.env.random_env_var = 'foo' +ourenv.npm_config_cache = exports.npm_config_cache = npm_config_cache +ourenv.npm_config_userconfig = exports.npm_config_userconfig = path.join(__dirname, 'fixtures', 'config', 'userconfig') +ourenv.npm_config_globalconfig = exports.npm_config_globalconfig = path.join(__dirname, 'fixtures', 'config', 'globalconfig') +ourenv.npm_config_global_style = 'false' +ourenv.npm_config_legacy_bundling = 'false' +ourenv.npm_config_fetch_retries = '0' +ourenv.random_env_var = 'foo' // suppress warnings about using a prerelease version of node -process.env.npm_config_node_version = process.version.replace(/-.*$/, '') +ourenv.npm_config_node_version = process.version.replace(/-.*$/, '') +for (let key of Object.keys(ourenv)) process.env[key] = ourenv[key] var bin = exports.bin = require.resolve('../bin/npm-cli.js') @@ -141,6 +143,17 @@ exports.newEnv = function () { return new Environment(process.env) } +exports.emptyEnv = function () { + const filtered = {} + for (let key of Object.keys(process.env)) { + if (!/^npm_/.test(key)) filtered[key] = process.env[key] + } + for (let key of Object.keys(ourenv)) { + filtered[key] = ourenv[key] + } + return new Environment(filtered) +} + function Environment (env) { if (env instanceof Environment) return env.clone() diff --git a/test/tap/spec-local-specifiers.js b/test/tap/spec-local-specifiers.js index 608d5503a..715c9c0ec 100644 --- a/test/tap/spec-local-specifiers.js +++ b/test/tap/spec-local-specifiers.js @@ -19,7 +19,7 @@ var tmpdir = path.join(basedir, 'tmp') var conf = { cwd: testdir, - env: common.newEnv().extend({ + env: common.emptyEnv().extend({ npm_config_cache: cachedir, npm_config_tmp: tmpdir, npm_config_prefix: globaldir, |