node/deps/npm/test/common-tap.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

var spawn = require("child_process").spawn
2014-11-05 07:08:12 +08:00
var path = require("path")
2013-11-21 03:08:52 +08:00
var port = exports.port = 1337
exports.registry = "http://localhost:" + port
process.env.npm_config_loglevel = "error"
2014-11-05 07:08:12 +08:00
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.random_env_var = "foo"
2014-11-05 07:08:12 +08:00
var bin = exports.bin = require.resolve("../bin/npm-cli.js")
var once = require("once")
2014-11-05 07:08:12 +08:00
exports.npm = function (cmd, opts, cb) {
cb = once(cb)
cmd = [bin].concat(cmd)
opts = opts || {}
opts.env = opts.env || process.env
2014-11-05 07:08:12 +08:00
if (!opts.env.npm_config_cache) {
opts.env.npm_config_cache = npm_config_cache
}
var stdout = ""
, stderr = ""
, node = process.execPath
, child = spawn(node, cmd, opts)
if (child.stderr) child.stderr.on("data", function (chunk) {
stderr += chunk
})
if (child.stdout) child.stdout.on("data", function (chunk) {
stdout += chunk
})
child.on("error", cb)
2014-09-25 05:41:07 +08:00
child.on("close", function (code) {
cb(null, code, stdout, stderr)
})
2014-11-05 07:08:12 +08:00
return child
}