summaryrefslogtreecommitdiff
path: root/deps/npm/test
diff options
context:
space:
mode:
authorTimothy J Fontaine <tjfontaine@gmail.com>2014-11-04 15:08:12 -0800
committerTimothy J Fontaine <tjfontaine@gmail.com>2014-11-05 10:35:43 -0800
commit28ae70ebad8debd8aa7b521a693aa3de89ad84d6 (patch)
treec5cd9142bbefe8f84c9555e07cafd677530cb7ef /deps/npm/test
parent272aa589af50566a20a491910d4dc40bb3692102 (diff)
downloadnode-new-28ae70ebad8debd8aa7b521a693aa3de89ad84d6.tar.gz
npm: Upgrade to v2.1.6
Diffstat (limited to 'deps/npm/test')
-rw-r--r--deps/npm/test/common-tap.js35
-rw-r--r--deps/npm/test/fixtures/config/.npmrc1
-rw-r--r--deps/npm/test/fixtures/config/builtin1
-rw-r--r--deps/npm/test/fixtures/config/globalconfig1
-rw-r--r--deps/npm/test/fixtures/config/malformed1
-rw-r--r--deps/npm/test/fixtures/config/multi-ca32
-rw-r--r--deps/npm/test/fixtures/config/package.json0
-rw-r--r--deps/npm/test/fixtures/config/userconfig23
-rw-r--r--deps/npm/test/fixtures/config/userconfig-with-gc22
-rw-r--r--deps/npm/test/tap/00-check-mock-dep.js4
-rw-r--r--deps/npm/test/tap/00-config-setup.js68
-rw-r--r--deps/npm/test/tap/00-verify-bundle-deps.js2
-rw-r--r--deps/npm/test/tap/00-verify-ls-ok.js15
-rw-r--r--deps/npm/test/tap/404-parent.js51
-rw-r--r--deps/npm/test/tap/builtin-config.js125
-rw-r--r--deps/npm/test/tap/cache-add-localdir-fallback.js84
-rw-r--r--deps/npm/test/tap/cache-add-unpublished.js59
-rw-r--r--deps/npm/test/tap/cache-shasum-fork.js83
-rw-r--r--deps/npm/test/tap/cache-shasum-fork/underscore-1.5.1.tgzbin0 -> 583 bytes
-rw-r--r--deps/npm/test/tap/cache-shasum.js12
-rw-r--r--deps/npm/test/tap/circular-dep.js4
-rw-r--r--deps/npm/test/tap/config-basic.js66
-rw-r--r--deps/npm/test/tap/config-builtin.js68
-rw-r--r--deps/npm/test/tap/config-certfile.js18
-rw-r--r--deps/npm/test/tap/config-credentials.js295
-rw-r--r--deps/npm/test/tap/config-malformed.js14
-rw-r--r--deps/npm/test/tap/config-meta.js50
-rw-r--r--deps/npm/test/tap/config-project.js66
-rw-r--r--deps/npm/test/tap/config-save.js88
-rw-r--r--deps/npm/test/tap/config-semver-tag.js27
-rw-r--r--deps/npm/test/tap/dedupe.js29
-rw-r--r--deps/npm/test/tap/dev-dep-duplicate/desired-ls-results.json9
-rw-r--r--deps/npm/test/tap/dev-dep-duplicate/package.json11
-rw-r--r--deps/npm/test/tap/false_name.js54
-rw-r--r--deps/npm/test/tap/git-cache-locking.js32
-rw-r--r--deps/npm/test/tap/git-cache-no-hooks.js63
-rw-r--r--deps/npm/test/tap/git-cache-permissions.js80
-rw-r--r--deps/npm/test/tap/global-prefix-set-in-userconfig.js4
-rw-r--r--deps/npm/test/tap/ignore-install-link.js2
-rw-r--r--deps/npm/test/tap/ignore-scripts.js53
-rw-r--r--deps/npm/test/tap/ignore-shrinkwrap.js18
-rw-r--r--deps/npm/test/tap/install-at-locally.js52
-rw-r--r--deps/npm/test/tap/install-cli-production.js44
-rw-r--r--deps/npm/test/tap/install-cli-production/dependency/package.json5
-rw-r--r--deps/npm/test/tap/install-cli-production/dev-dependency/package.json5
-rw-r--r--deps/npm/test/tap/install-cli-production/package.json14
-rw-r--r--deps/npm/test/tap/install-cli-unicode.js37
-rw-r--r--deps/npm/test/tap/install-from-local.js33
-rw-r--r--deps/npm/test/tap/install-from-local/package-scoped-dependency/package.json5
-rw-r--r--deps/npm/test/tap/install-from-local/package-with-scoped-paths/package.json8
-rw-r--r--deps/npm/test/tap/install-save-exact.js81
-rw-r--r--deps/npm/test/tap/install-save-local.js59
-rw-r--r--deps/npm/test/tap/install-save-prefix.js122
-rw-r--r--deps/npm/test/tap/install-scoped-already-installed.js86
-rw-r--r--deps/npm/test/tap/install-scoped-link.js49
-rw-r--r--deps/npm/test/tap/install-with-dev-dep-duplicate.js57
-rw-r--r--deps/npm/test/tap/invalid-cmd-exit-code.js7
-rw-r--r--deps/npm/test/tap/lifecycle-path.js4
-rw-r--r--deps/npm/test/tap/lifecycle.js8
-rw-r--r--deps/npm/test/tap/locker.js89
-rw-r--r--deps/npm/test/tap/login-always-auth.js142
-rw-r--r--deps/npm/test/tap/ls-depth-cli.js48
-rw-r--r--deps/npm/test/tap/ls-depth-unmet.js51
-rw-r--r--deps/npm/test/tap/ls-no-results.js12
-rw-r--r--deps/npm/test/tap/noargs-install-config-save.js16
-rw-r--r--deps/npm/test/tap/npm-api-not-loaded-error.js2
-rw-r--r--deps/npm/test/tap/optional-metadep-rollback-collision.js2
-rw-r--r--deps/npm/test/tap/outdated-color.js34
-rw-r--r--deps/npm/test/tap/outdated-depth.js38
-rw-r--r--deps/npm/test/tap/outdated-git.js21
-rw-r--r--deps/npm/test/tap/outdated-include-devdependencies.js10
-rw-r--r--deps/npm/test/tap/outdated-json.js41
-rw-r--r--deps/npm/test/tap/outdated-new-versions.js10
-rw-r--r--deps/npm/test/tap/outdated-notarget.js10
-rw-r--r--deps/npm/test/tap/outdated.js18
-rw-r--r--deps/npm/test/tap/pack-scoped.js52
-rw-r--r--deps/npm/test/tap/peer-deps-invalid.js16
-rw-r--r--deps/npm/test/tap/peer-deps-toplevel.js55
-rw-r--r--deps/npm/test/tap/peer-deps-toplevel/desired-ls-results.json20
-rw-r--r--deps/npm/test/tap/peer-deps-toplevel/package.json11
-rw-r--r--deps/npm/test/tap/peer-deps-without-package-json.js24
-rw-r--r--deps/npm/test/tap/peer-deps.js4
-rw-r--r--deps/npm/test/tap/prepublish.js52
-rw-r--r--deps/npm/test/tap/prune.js99
-rw-r--r--deps/npm/test/tap/publish-config.js37
-rw-r--r--deps/npm/test/tap/publish-scoped.js34
-rw-r--r--deps/npm/test/tap/pwd-prefix.js8
-rw-r--r--deps/npm/test/tap/referer.js9
-rw-r--r--deps/npm/test/tap/registry.js68
-rw-r--r--deps/npm/test/tap/repo.js12
-rw-r--r--deps/npm/test/tap/run-script.js74
-rw-r--r--deps/npm/test/tap/run-script/package.json9
-rw-r--r--deps/npm/test/tap/scripts-whitespace-windows.js95
-rw-r--r--deps/npm/test/tap/search.js265
-rw-r--r--deps/npm/test/tap/semver-doc.js4
-rw-r--r--deps/npm/test/tap/semver-tag.js2
-rw-r--r--deps/npm/test/tap/shrinkwrap-empty-deps.js5
-rw-r--r--deps/npm/test/tap/sorted-package-json.js13
-rw-r--r--deps/npm/test/tap/spawn-enoent.js2
-rw-r--r--deps/npm/test/tap/startstop.js52
-rw-r--r--deps/npm/test/tap/test-run-ls.js6
-rw-r--r--deps/npm/test/tap/uninstall-package.js3
-rw-r--r--deps/npm/test/tap/unpack-foreign-tarball.js42
-rw-r--r--deps/npm/test/tap/update-save.js82
-rw-r--r--deps/npm/test/tap/url-dependencies.js52
-rw-r--r--deps/npm/test/tap/version-no-git.js54
-rw-r--r--deps/npm/test/tap/version-no-tags.js80
-rw-r--r--deps/npm/test/tap/view.js253
-rw-r--r--deps/npm/test/tap/zz-cleanup.js15
109 files changed, 3328 insertions, 1171 deletions
diff --git a/deps/npm/test/common-tap.js b/deps/npm/test/common-tap.js
index 3a1f584a73..2efca30c48 100644
--- a/deps/npm/test/common-tap.js
+++ b/deps/npm/test/common-tap.js
@@ -1,16 +1,27 @@
var spawn = require("child_process").spawn
+var path = require("path")
+var fs = require("fs")
var port = exports.port = 1337
exports.registry = "http://localhost:" + port
process.env.npm_config_loglevel = "error"
+var npm_config_cache = path.resolve(__dirname, "npm_cache")
+exports.npm_config_cache = npm_config_cache
+
var bin = exports.bin = require.resolve("../bin/npm-cli.js")
var once = require("once")
+
exports.npm = function (cmd, opts, cb) {
cb = once(cb)
cmd = [bin].concat(cmd)
opts = opts || {}
+ opts.env = opts.env ? opts.env : process.env
+ if (!opts.env.npm_config_cache) {
+ opts.env.npm_config_cache = npm_config_cache
+ }
+
var stdout = ""
, stderr = ""
, node = process.execPath
@@ -29,4 +40,28 @@ exports.npm = function (cmd, opts, cb) {
child.on("close", function (code) {
cb(null, code, stdout, stderr)
})
+ return child
+}
+
+// based on http://bit.ly/1tkI6DJ
+function deleteNpmCacheRecursivelySync(cache) {
+ cache = cache ? cache : npm_config_cache
+ var files = []
+ var res
+ if( fs.existsSync(cache) ) {
+ files = fs.readdirSync(cache)
+ files.forEach(function(file,index) {
+ var curPath = path.resolve(cache, file)
+ if(fs.lstatSync(curPath).isDirectory()) { // recurse
+ deleteNpmCacheRecursivelySync(curPath)
+ } else { // delete file
+ if (res = fs.unlinkSync(curPath))
+ throw Error("Failed to delete file " + curPath + ", error " + res)
+ }
+ })
+ if (res = fs.rmdirSync(cache))
+ throw Error("Failed to delete directory " + cache + ", error " + res)
+ }
+ return 0
}
+exports.deleteNpmCacheRecursivelySync = deleteNpmCacheRecursivelySync \ No newline at end of file
diff --git a/deps/npm/test/fixtures/config/.npmrc b/deps/npm/test/fixtures/config/.npmrc
new file mode 100644
index 0000000000..7d59bd8be1
--- /dev/null
+++ b/deps/npm/test/fixtures/config/.npmrc
@@ -0,0 +1 @@
+just = testing
diff --git a/deps/npm/test/fixtures/config/builtin b/deps/npm/test/fixtures/config/builtin
new file mode 100644
index 0000000000..dcd542c0ce
--- /dev/null
+++ b/deps/npm/test/fixtures/config/builtin
@@ -0,0 +1 @@
+builtin-config = true
diff --git a/deps/npm/test/fixtures/config/globalconfig b/deps/npm/test/fixtures/config/globalconfig
new file mode 100644
index 0000000000..41c0b70c80
--- /dev/null
+++ b/deps/npm/test/fixtures/config/globalconfig
@@ -0,0 +1 @@
+package-config:foo = boo
diff --git a/deps/npm/test/fixtures/config/malformed b/deps/npm/test/fixtures/config/malformed
new file mode 100644
index 0000000000..182c4d2c71
--- /dev/null
+++ b/deps/npm/test/fixtures/config/malformed
@@ -0,0 +1 @@
+email = """ \ No newline at end of file
diff --git a/deps/npm/test/fixtures/config/multi-ca b/deps/npm/test/fixtures/config/multi-ca
new file mode 100644
index 0000000000..0bc922b25c
--- /dev/null
+++ b/deps/npm/test/fixtures/config/multi-ca
@@ -0,0 +1,32 @@
+-----BEGIN CERTIFICATE-----
+MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
+NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
+dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
+ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
+ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
+ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
+miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
+AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
+Ey1OYXRpAAAAACBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
+DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
+MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
+AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
+X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
+WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO
+-----END CERTIFICATE-----
+-----BEGIN CERTIFICATE-----
+AAAAAACCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
+NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
+dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
+ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
+ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
+ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
+miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
+AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
+Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
+DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
+MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
+AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
+X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
+WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO
+-----END CERTIFICATE-----
diff --git a/deps/npm/test/fixtures/config/package.json b/deps/npm/test/fixtures/config/package.json
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/deps/npm/test/fixtures/config/package.json
diff --git a/deps/npm/test/fixtures/config/userconfig b/deps/npm/test/fixtures/config/userconfig
new file mode 100644
index 0000000000..d600c0664e
--- /dev/null
+++ b/deps/npm/test/fixtures/config/userconfig
@@ -0,0 +1,23 @@
+email = i@izs.me
+env-thing = ${random_env_var}
+init.author.name = Isaac Z. Schlueter
+init.author.email = i@izs.me
+init.author.url = http://blog.izs.me/
+init.version = 1.2.3
+proprietary-attribs = false
+npm:publishtest = true
+_npmjs.org:couch = https://admin:password@localhost:5984/registry
+npm-www:nocache = 1
+nodedir = /Users/isaacs/dev/js/node-v0.8
+sign-git-tag = true
+message = v%s
+strict-ssl = false
+tmp = ~/.tmp
+_auth = dXNlcm5hbWU6cGFzc3dvcmQ=
+
+[_token]
+AuthSession = yabba-dabba-doodle
+version = 1
+expires = 1345001053415
+path = /
+httponly = true
diff --git a/deps/npm/test/fixtures/config/userconfig-with-gc b/deps/npm/test/fixtures/config/userconfig-with-gc
new file mode 100644
index 0000000000..3e5d605f4e
--- /dev/null
+++ b/deps/npm/test/fixtures/config/userconfig-with-gc
@@ -0,0 +1,22 @@
+globalconfig=/Users/ogd/Documents/projects/npm/npm/test/fixtures/config/globalconfig
+email=i@izs.me
+env-thing=asdf
+init.author.name=Isaac Z. Schlueter
+init.author.email=i@izs.me
+init.author.url=http://blog.izs.me/
+init.version=1.2.3
+proprietary-attribs=false
+npm:publishtest=true
+_npmjs.org:couch=https://admin:password@localhost:5984/registry
+npm-www:nocache=1
+sign-git-tag=false
+message=v%s
+strict-ssl=false
+_auth=dXNlcm5hbWU6cGFzc3dvcmQ=
+
+[_token]
+AuthSession=yabba-dabba-doodle
+version=1
+expires=1345001053415
+path=/
+httponly=true
diff --git a/deps/npm/test/tap/00-check-mock-dep.js b/deps/npm/test/tap/00-check-mock-dep.js
index c4d2ff2c22..1c862317c9 100644
--- a/deps/npm/test/tap/00-check-mock-dep.js
+++ b/deps/npm/test/tap/00-check-mock-dep.js
@@ -1,6 +1,7 @@
console.log("TAP Version 13")
-process.on("uncaughtException", function(er) {
+process.on("uncaughtException", function (er) {
+ if (er) { throw er }
console.log("not ok - Failed checking mock registry dep. Expect much fail!")
console.log("1..1")
process.exit(1)
@@ -10,6 +11,7 @@ var assert = require("assert")
var semver = require("semver")
var mock = require("npm-registry-mock/package.json").version
var req = require("../../package.json").devDependencies["npm-registry-mock"]
+
assert(semver.satisfies(mock, req))
console.log("ok")
console.log("1..1")
diff --git a/deps/npm/test/tap/00-config-setup.js b/deps/npm/test/tap/00-config-setup.js
new file mode 100644
index 0000000000..aaad546271
--- /dev/null
+++ b/deps/npm/test/tap/00-config-setup.js
@@ -0,0 +1,68 @@
+var path = require("path")
+var userconfigSrc = path.resolve(__dirname, "..", "fixtures", "config", "userconfig")
+exports.userconfig = userconfigSrc + "-with-gc"
+exports.globalconfig = path.resolve(__dirname, "..", "fixtures", "config", "globalconfig")
+exports.builtin = path.resolve(__dirname, "..", "fixtures", "config", "builtin")
+exports.malformed = path.resolve(__dirname, "..", "fixtures", "config", "malformed")
+exports.ucData =
+ { globalconfig: exports.globalconfig,
+ email: "i@izs.me",
+ "env-thing": "asdf",
+ "init.author.name": "Isaac Z. Schlueter",
+ "init.author.email": "i@izs.me",
+ "init.author.url": "http://blog.izs.me/",
+ "init.version": "1.2.3",
+ "proprietary-attribs": false,
+ "npm:publishtest": true,
+ "_npmjs.org:couch": "https://admin:password@localhost:5984/registry",
+ "npm-www:nocache": "1",
+ nodedir: "/Users/isaacs/dev/js/node-v0.8",
+ "sign-git-tag": true,
+ message: "v%s",
+ "strict-ssl": false,
+ "tmp": process.env.HOME + "/.tmp",
+ _auth: "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ _token:
+ { AuthSession: "yabba-dabba-doodle",
+ version: "1",
+ expires: "1345001053415",
+ path: "/",
+ httponly: true } }
+
+// set the userconfig in the env
+// unset anything else that npm might be trying to foist on us
+Object.keys(process.env).forEach(function (k) {
+ if (k.match(/^npm_config_/i)) {
+ delete process.env[k]
+ }
+})
+process.env.npm_config_userconfig = exports.userconfig
+process.env.npm_config_other_env_thing = 1000
+process.env.random_env_var = "asdf"
+process.env.npm_config__underbar_env_thing = "underful"
+process.env.NPM_CONFIG_UPPERCASE_ENV_THING = 42
+
+exports.envData = {
+ userconfig: exports.userconfig,
+ "_underbar-env-thing": "underful",
+ "uppercase-env-thing": "42",
+ "other-env-thing": "1000"
+}
+exports.envDataFix = {
+ userconfig: exports.userconfig,
+ "_underbar-env-thing": "underful",
+ "uppercase-env-thing": 42,
+ "other-env-thing": 1000
+}
+
+
+if (module === require.main) {
+ // set the globalconfig in the userconfig
+ var fs = require("fs")
+ var uc = fs.readFileSync(userconfigSrc)
+ var gcini = "globalconfig = " + exports.globalconfig + "\n"
+ fs.writeFileSync(exports.userconfig, gcini + uc)
+
+ console.log("0..1")
+ console.log("ok 1 setup done")
+}
diff --git a/deps/npm/test/tap/00-verify-bundle-deps.js b/deps/npm/test/tap/00-verify-bundle-deps.js
index 00291a6c48..9d16b2d3b1 100644
--- a/deps/npm/test/tap/00-verify-bundle-deps.js
+++ b/deps/npm/test/tap/00-verify-bundle-deps.js
@@ -16,7 +16,7 @@ test("all deps are bundled deps or dev deps", function (t) {
})
t.same(
- fs.readdirSync(path.resolve(__dirname, '../../node_modules')).filter(function (name) {
+ fs.readdirSync(path.resolve(__dirname, "../../node_modules")).filter(function (name) {
return (dev.indexOf(name) === -1) && (name !== ".bin")
}).sort(),
bundled.sort(),
diff --git a/deps/npm/test/tap/00-verify-ls-ok.js b/deps/npm/test/tap/00-verify-ls-ok.js
index 7209e7db7e..aa6acdbc56 100644
--- a/deps/npm/test/tap/00-verify-ls-ok.js
+++ b/deps/npm/test/tap/00-verify-ls-ok.js
@@ -1,15 +1,18 @@
+var common = require("../common-tap")
var test = require("tap").test
-var node = process.execPath
var path = require("path")
var cwd = path.resolve(__dirname, "..", "..")
-var npm = path.resolve(cwd, "cli.js")
-var spawn = require("child_process").spawn
+var fs = require("fs")
test("npm ls in npm", function (t) {
+ t.ok(fs.existsSync(cwd), "ensure that the path we are calling ls within exists")
+ var files = fs.readdirSync(cwd)
+ t.notEqual(files.length, 0, "ensure there are files in the directory we are to ls")
+
var opt = { cwd: cwd, stdio: [ "ignore", "ignore", 2 ] }
- var child = spawn(node, [npm, "ls"], opt)
- child.on("close", function (code) {
- t.notOk(code)
+ common.npm(["ls"], opt, function (err, code) {
+ t.ifError(err, "error should not exist")
+ t.equal(code, 0, "npm ls exited with code")
t.end()
})
})
diff --git a/deps/npm/test/tap/404-parent.js b/deps/npm/test/tap/404-parent.js
index b3c353827f..e40d850de7 100644
--- a/deps/npm/test/tap/404-parent.js
+++ b/deps/npm/test/tap/404-parent.js
@@ -1,26 +1,25 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var osenv = require('osenv')
-var path = require('path')
-var fs = require('fs')
-var rimraf = require('rimraf')
-var mkdirp = require('mkdirp')
-var pkg = path.resolve(__dirname, '404-parent')
+var common = require("../common-tap.js")
+var test = require("tap").test
+var npm = require("../../")
+var osenv = require("osenv")
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var pkg = path.resolve(__dirname, "404-parent")
var mr = require("npm-registry-mock")
-test('404-parent: if parent exists, specify parent in error message', function(t) {
+test("404-parent: if parent exists, specify parent in error message", function (t) {
setup()
- rimraf.sync(path.resolve(pkg, 'node_modules'))
- performInstall(function(err) {
- t.ok(err instanceof Error)
- t.pass('error was returned')
- t.ok(err.parent === '404-parent-test')
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ performInstall(function (err) {
+ t.ok(err instanceof Error, "error was returned")
+ t.ok(err.parent === "404-parent-test", "error's parent set")
t.end()
})
})
-test('cleanup', function(t) {
+test("cleanup", function (t) {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
t.end()
@@ -28,23 +27,23 @@ test('cleanup', function(t) {
function setup() {
mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, 'cache'))
- fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
- author: 'Evan Lucas',
- name: '404-parent-test',
- version: '0.0.0',
- description: 'Test for 404-parent',
+ mkdirp.sync(path.resolve(pkg, "cache"))
+ fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({
+ author: "Evan Lucas",
+ name: "404-parent-test",
+ version: "0.0.0",
+ description: "Test for 404-parent",
dependencies: {
- 'test-npm-404-parent-test': '*'
+ "test-npm-404-parent-test": "*"
}
- }), 'utf8')
+ }), "utf8")
process.chdir(pkg)
}
function performInstall(cb) {
mr(common.port, function (s) { // create mock registry.
- npm.load({registry: common.registry}, function() {
- npm.commands.install(pkg, [], function(err) {
+ npm.load({registry: common.registry}, function () {
+ npm.commands.install(pkg, [], function (err) {
cb(err)
s.close() // shutdown mock npm server.
})
diff --git a/deps/npm/test/tap/builtin-config.js b/deps/npm/test/tap/builtin-config.js
new file mode 100644
index 0000000000..75acd2be27
--- /dev/null
+++ b/deps/npm/test/tap/builtin-config.js
@@ -0,0 +1,125 @@
+var fs = require("fs")
+
+if (process.argv[2] === "write-builtin") {
+ var pid = process.argv[3]
+ fs.writeFileSync("npmrc", "foo=bar\npid=" + pid + "\n")
+ return
+}
+
+var rcdata = "foo=bar\npid=" + process.pid + "\n"
+var common = require("../common-tap.js")
+var path = require("path")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var folder = path.resolve(__dirname, "builtin-config")
+var test = require("tap").test
+var npm = path.resolve(__dirname, "../..")
+var spawn = require("child_process").spawn
+var node = process.execPath
+
+test("setup", function (t) {
+ rimraf.sync(folder)
+ mkdirp.sync(folder + "/first")
+ mkdirp.sync(folder + "/second")
+ mkdirp.sync(folder + "/cache")
+ mkdirp.sync(folder + "/tmp")
+
+ t.pass("finished setup")
+ t.end()
+})
+
+
+test("install npm into first folder", function (t) {
+ var args = ["install", npm, "-g",
+ "--prefix=" + folder + "/first",
+ "--cache=" + folder + "/cache",
+ "--no-spin",
+ "--loglevel=silent",
+ "--tmp=" + folder + "/tmp"]
+ common.npm(args, {stdio: "inherit"}, function (er, code) {
+ if (er) throw er
+ t.equal(code, 0)
+ t.end()
+ })
+})
+
+test("write npmrc file", function (t) {
+ common.npm(["explore", "npm", "-g",
+ "--prefix=" + folder + "/first",
+ "--cache=" + folder + "/cache",
+ "--tmp=" + folder + "/tmp",
+ "--no-spin",
+ "--",
+ node, __filename, "write-builtin", process.pid
+ ],
+ {"stdio": "inherit"},
+ function (er, code) {
+ if (er) throw er
+ t.equal(code, 0)
+ t.end()
+ })
+})
+
+test("use first npm to install second npm", function (t) {
+ // get the root location
+ common.npm([ "root", "-g",
+ "--prefix=" + folder + "/first",
+ "--cache=" + folder + "/cache",
+ "--tmp=" + folder + "/tmp",
+ "--no-spin"
+ ], {}, function (er, code, so) {
+ if (er) throw er
+ t.equal(code, 0)
+ var root = so.trim()
+ t.ok(fs.statSync(root).isDirectory())
+
+ var bin = path.resolve(root, "npm/bin/npm-cli.js")
+ spawn( node
+ , [ bin
+ , "install", npm
+ , "-g"
+ , "--prefix=" + folder + "/second"
+ , "--cache=" + folder + "/cache"
+ , "--tmp=" + folder + "/tmp"
+ , "--no-spin"
+ ])
+ .on("error", function (er) { throw er })
+ .on("close", function (code) {
+ t.equal(code, 0, "code is zero")
+ t.end()
+ })
+ })
+})
+
+test("verify that the builtin config matches", function (t) {
+ common.npm([ "root", "-g",
+ "--prefix=" + folder + "/first",
+ "--cache=" + folder + "/cache",
+ "--tmp=" + folder + "/tmp"
+ ], {}, function (er, code, so) {
+ if (er) throw er
+ t.equal(code, 0)
+ var firstRoot = so.trim()
+ common.npm([ "root", "-g",
+ "--prefix=" + folder + "/second",
+ "--cache=" + folder + "/cache",
+ "--tmp=" + folder + "/tmp"
+ ], {}, function (er, code, so) {
+ if (er) throw er
+ t.equal(code, 0)
+ var secondRoot = so.trim()
+ var firstRc = path.resolve(firstRoot, "npm", "npmrc")
+ var secondRc = path.resolve(secondRoot, "npm", "npmrc")
+ var firstData = fs.readFileSync(firstRc, "utf8")
+ var secondData = fs.readFileSync(secondRc, "utf8")
+ t.equal(firstData, secondData)
+ t.end()
+ })
+ })
+})
+
+
+test("clean", function (t) {
+ rimraf.sync(folder)
+ t.end()
+})
diff --git a/deps/npm/test/tap/cache-add-localdir-fallback.js b/deps/npm/test/tap/cache-add-localdir-fallback.js
index 6b036c3809..facd95c3ad 100644
--- a/deps/npm/test/tap/cache-add-localdir-fallback.js
+++ b/deps/npm/test/tap/cache-add-localdir-fallback.js
@@ -3,45 +3,49 @@ var test = require("tap").test
var npm = require("../../lib/npm.js")
var requireInject = require("require-inject")
-npm.load({loglevel : "silent"}, function () {
- var resolved = path.resolve(__dirname, "dir-with-package")
- var resolvedPackage = path.join(resolved, "package.json")
+var realizePackageSpecifier = requireInject("realize-package-specifier", {
+ "fs": {
+ stat: function (file, cb) {
+ process.nextTick(function () {
+ switch (file) {
+ case path.resolve("named"):
+ cb(new Error("ENOENT"))
+ break
+ case path.resolve("file.tgz"):
+ cb(null, { isDirectory: function () { return false } })
+ break
+ case path.resolve("dir-no-package"):
+ cb(null, { isDirectory: function () { return true } })
+ break
+ case path.resolve("dir-no-package/package.json"):
+ cb(new Error("ENOENT"))
+ break
+ case path.resolve("dir-with-package"):
+ cb(null, { isDirectory: function () { return true } })
+ break
+ case path.resolve("dir-with-package/package.json"):
+ cb(null, {})
+ break
+ case path.resolve(__dirname, "dir-with-package"):
+ cb(null, { isDirectory: function () { return true } })
+ break
+ case path.join(__dirname, "dir-with-package", "package.json"):
+ cb(null, {})
+ break
+ case path.resolve(__dirname, "file.tgz"):
+ cb(null, { isDirectory: function () { return false } })
+ break
+ default:
+ throw new Error("Unknown test file passed to stat: " + file)
+ }
+ })
+ }
+ }
+})
+npm.load({loglevel : "silent"}, function () {
var cache = requireInject("../../lib/cache.js", {
- "graceful-fs": {
- stat: function (file, cb) {
- process.nextTick(function () {
- switch (file) {
- case "named":
- cb(new Error("ENOENT"))
- break
- case "file.tgz":
- cb(null, { isDirectory: function () { return false } })
- break
- case "dir-no-package":
- cb(null, { isDirectory: function () { return true } })
- break
- case "dir-no-package/package.json":
- cb(new Error("ENOENT"))
- break
- case "dir-with-package":
- cb(null, { isDirectory: function () { return true } })
- break
- case "dir-with-package/package.json":
- cb(null, {})
- break
- case resolved:
- cb(null, { isDirectory: function () { return true } })
- break
- case resolvedPackage:
- cb(null, {})
- break
- default:
- throw new Error("Unknown test file passed to stat: " + file)
- }
- })
- }
- },
+ "realize-package-specifier": realizePackageSpecifier,
"../../lib/cache/add-named.js": function addNamed (name, version, data, cb) {
cb(null, "addNamed")
},
@@ -51,7 +55,7 @@ npm.load({loglevel : "silent"}, function () {
})
test("npm install localdir fallback", function (t) {
- t.plan(10)
+ t.plan(12)
cache.add("named", null, null, false, function (er, which) {
t.ifError(er, "named was cached")
t.is(which, "addNamed", "registry package name")
@@ -72,5 +76,9 @@ npm.load({loglevel : "silent"}, function () {
t.ifError(er, "local directory (as URI) with package was cached")
t.is(which, "addLocal", "file: URI to local directory with package.json")
})
+ cache.add("file:./file.tgz", null, __dirname, false, function (er, which) {
+ t.ifError(er, "local file (as URI) with package was cached")
+ t.is(which, "addLocal", "file: URI to local file with package.json")
+ })
})
})
diff --git a/deps/npm/test/tap/cache-add-unpublished.js b/deps/npm/test/tap/cache-add-unpublished.js
index e313213145..46f0db232e 100644
--- a/deps/npm/test/tap/cache-add-unpublished.js
+++ b/deps/npm/test/tap/cache-add-unpublished.js
@@ -1,61 +1,12 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-
-var server
-
-var port = common.port
-var http = require("http")
-
-var doc = {
- "_id": "superfoo",
- "_rev": "5-d11adeec0fdfea6b96b120610d2bed71",
- "name": "superfoo",
- "time": {
- "modified": "2014-02-18T18:35:02.930Z",
- "created": "2014-02-18T18:34:08.437Z",
- "1.1.0": "2014-02-18T18:34:08.437Z",
- "unpublished": {
- "name": "isaacs",
- "time": "2014-04-30T18:26:45.584Z",
- "tags": {
- "latest": "1.1.0"
- },
- "maintainers": [
- {
- "name": "foo",
- "email": "foo@foo.com"
- }
- ],
- "description": "do lots a foo",
- "versions": [
- "1.1.0"
- ]
- }
- },
- "_attachments": {}
-}
-
-test("setup", function (t) {
- server = http.createServer(function(req, res) {
- res.end(JSON.stringify(doc))
- })
- server.listen(port, function() {
- t.end()
- })
-})
+var common = require("../common-tap.js")
+var test = require("tap").test
test("cache add", function (t) {
common.npm(["cache", "add", "superfoo"], {}, function (er, c, so, se) {
if (er) throw er
- t.ok(c)
- t.equal(so, "")
- t.similar(se, /404 Not Found: superfoo/)
- t.end()
- })
-})
-
-test("cleanup", function (t) {
- server.close(function() {
+ t.ok(c, "got non-zero exit code")
+ t.equal(so, "", "nothing printed to stdout")
+ t.similar(se, /404 Not Found: superfoo/, "got expected error")
t.end()
})
})
diff --git a/deps/npm/test/tap/cache-shasum-fork.js b/deps/npm/test/tap/cache-shasum-fork.js
new file mode 100644
index 0000000000..383f08c715
--- /dev/null
+++ b/deps/npm/test/tap/cache-shasum-fork.js
@@ -0,0 +1,83 @@
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var mr = require("npm-registry-mock")
+var common = require("../common-tap.js")
+var cache = path.resolve(__dirname, "cache-shasum-fork", "CACHE")
+var cwd = path.resolve(__dirname, "cache-shasum-fork", "CWD")
+var server
+
+// Test for https://github.com/npm/npm/issues/3265
+
+test("mock reg", function (t) {
+ rimraf.sync(cache)
+ mkdirp.sync(cache)
+ rimraf.sync(cwd)
+ mkdirp.sync(path.join(cwd, "node_modules"))
+ mr(common.port, function (s) {
+ server = s
+ t.pass("ok")
+ t.end()
+ })
+})
+
+test("npm cache - install from fork", function (t) {
+ // Install from a tarball that thinks it is underscore@1.5.1
+ // (but is actually a fork)
+ var forkPath = path.resolve(
+ __dirname, "cache-shasum-fork", "underscore-1.5.1.tgz")
+ common.npm(["install", forkPath], {
+ cwd: cwd,
+ env: {
+ "npm_config_cache" : cache,
+ "npm_config_registry" : common.registry,
+ "npm_config_loglevel" : "silent"
+ }
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, "install finished without error")
+ t.notOk(stderr, "Should not get data on stderr: " + stderr)
+ t.equal(code, 0, "install finished successfully")
+
+ t.equal(stdout, "underscore@1.5.1 node_modules/underscore\n")
+ var index = fs.readFileSync(
+ path.join(cwd, "node_modules", "underscore", "index.js"),
+ "utf8"
+ )
+ t.equal(index, 'console.log("This is the fork");\n\n')
+ t.end()
+ })
+})
+
+test("npm cache - install from origin", function (t) {
+ // Now install the real 1.5.1.
+ rimraf.sync(path.join(cwd, "node_modules"))
+ mkdirp.sync(path.join(cwd, "node_modules"))
+ common.npm(["install", "underscore"], {
+ cwd: cwd,
+ env: {
+ "npm_config_cache" : cache,
+ "npm_config_registry" : common.registry,
+ "npm_config_loglevel" : "silent"
+ }
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, "install finished without error")
+ t.equal(code, 0, "install finished successfully")
+ t.notOk(stderr, "Should not get data on stderr: " + stderr)
+ t.equal(stdout, "underscore@1.5.1 node_modules/underscore\n")
+ var index = fs.readFileSync(
+ path.join(cwd, "node_modules", "underscore", "index.js"),
+ "utf8"
+ )
+ t.equal(index, "module.exports = require('./underscore');\n")
+ t.end()
+ })
+})
+
+test("cleanup", function (t) {
+ server.close()
+ rimraf.sync(cache)
+ rimraf.sync(cwd)
+ t.end()
+})
diff --git a/deps/npm/test/tap/cache-shasum-fork/underscore-1.5.1.tgz b/deps/npm/test/tap/cache-shasum-fork/underscore-1.5.1.tgz
new file mode 100644
index 0000000000..5aca6247ac
--- /dev/null
+++ b/deps/npm/test/tap/cache-shasum-fork/underscore-1.5.1.tgz
Binary files differ
diff --git a/deps/npm/test/tap/cache-shasum.js b/deps/npm/test/tap/cache-shasum.js
index 7450d3e608..c7784ecff5 100644
--- a/deps/npm/test/tap/cache-shasum.js
+++ b/deps/npm/test/tap/cache-shasum.js
@@ -10,7 +10,7 @@ var spawn = require("child_process").spawn
var sha = require("sha")
var server
-test("mock reg", function(t) {
+test("mock reg", function (t) {
rimraf.sync(cache)
mkdirp.sync(cache)
mr(common.port, function (s) {
@@ -20,7 +20,7 @@ test("mock reg", function(t) {
})
})
-test("npm cache add request", function(t) {
+test("npm cache add request", function (t) {
var c = spawn(process.execPath, [
npm, "cache", "add", "request@2.27.0",
"--cache=" + cache,
@@ -29,17 +29,17 @@ test("npm cache add request", function(t) {
])
c.stderr.pipe(process.stderr)
- c.stdout.on("data", function(d) {
+ c.stdout.on("data", function (d) {
t.fail("Should not get data on stdout: " + d)
})
- c.on("close", function(code) {
+ c.on("close", function (code) {
t.notOk(code, "exit ok")
t.end()
})
})
-test("compare", function(t) {
+test("compare", function (t) {
var d = path.resolve(__dirname, "cache-shasum/request")
var p = path.resolve(d, "2.27.0/package.tgz")
var r = require("./cache-shasum/localhost_1337/request/.cache.json")
@@ -52,7 +52,7 @@ test("compare", function(t) {
})
})
-test("cleanup", function(t) {
+test("cleanup", function (t) {
server.close()
rimraf.sync(cache)
t.end()
diff --git a/deps/npm/test/tap/circular-dep.js b/deps/npm/test/tap/circular-dep.js
index 533f46451c..60487dd381 100644
--- a/deps/npm/test/tap/circular-dep.js
+++ b/deps/npm/test/tap/circular-dep.js
@@ -17,12 +17,12 @@ test("installing a package that depends on the current package", function (t) {
setup(function () {
npm.install("optimist", function (err) {
if (err) return t.fail(err)
- npm.dedupe(function(err) {
+ npm.dedupe(function (err) {
if (err) return t.fail(err)
t.ok(existsSync(path.resolve(pkg,
"minimist", "node_modules", "optimist",
"node_modules", "minimist"
- )))
+ )), "circular dependency uncircled")
cleanup()
server.close()
})
diff --git a/deps/npm/test/tap/config-basic.js b/deps/npm/test/tap/config-basic.js
new file mode 100644
index 0000000000..d5a950a8e5
--- /dev/null
+++ b/deps/npm/test/tap/config-basic.js
@@ -0,0 +1,66 @@
+var test = require("tap").test
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+var path = require("path")
+
+var projectData = {
+ "save-prefix": "~",
+ "proprietary-attribs": false
+}
+
+var ucData = common.ucData
+var envData = common.envData
+var envDataFix = common.envDataFix
+
+var gcData = { "package-config:foo": "boo" }
+
+var biData = {}
+
+var cli = { foo: "bar", umask: 022 }
+
+var expectList =
+[ cli,
+ envDataFix,
+ projectData,
+ ucData,
+ gcData,
+ biData ]
+
+var expectSources = {
+ cli: { data: cli },
+ env: {
+ data: envDataFix,
+ source: envData,
+ prefix: ""
+ },
+ project: {
+ path: path.resolve(__dirname, "..", "..", ".npmrc"),
+ type: "ini",
+ data: projectData
+ },
+ user: {
+ path: common.userconfig,
+ type: "ini",
+ data: ucData
+ },
+ global: {
+ path: common.globalconfig,
+ type: "ini",
+ data: gcData
+ },
+ builtin: { data: biData }
+}
+
+test("no builtin", function (t) {
+ npmconf.load(cli, function (er, conf) {
+ if (er) throw er
+ t.same(conf.list, expectList)
+ t.same(conf.sources, expectSources)
+ t.same(npmconf.rootConf.list, [])
+ t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
+ t.equal(conf.root, npmconf.defs.defaults)
+ t.equal(conf.get("umask"), 022)
+ t.equal(conf.get("heading"), "npm")
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-builtin.js b/deps/npm/test/tap/config-builtin.js
new file mode 100644
index 0000000000..5a1589ff6a
--- /dev/null
+++ b/deps/npm/test/tap/config-builtin.js
@@ -0,0 +1,68 @@
+var test = require("tap").test
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+var path = require("path")
+
+var ucData = common.ucData
+
+var envData = common.envData
+var envDataFix = common.envDataFix
+
+var gcData = { "package-config:foo": "boo" }
+
+var biData = { "builtin-config": true }
+
+var cli = { foo: "bar", heading: "foo", "git-tag-version": false }
+
+var projectData = {
+ "save-prefix": "~",
+ "proprietary-attribs": false
+}
+
+var expectList = [
+ cli,
+ envDataFix,
+ projectData,
+ ucData,
+ gcData,
+ biData
+]
+
+var expectSources = {
+ cli: { data: cli },
+ env: {
+ data: envDataFix,
+ source: envData,
+ prefix: ""
+ },
+ project: {
+ path: path.resolve(__dirname, "..", "..", ".npmrc"),
+ type: "ini",
+ data: projectData
+ },
+ user: {
+ path: common.userconfig,
+ type: "ini",
+ data: ucData
+ },
+ global: {
+ path: common.globalconfig,
+ type: "ini",
+ data: gcData
+ },
+ builtin: { data: biData }
+}
+
+test("with builtin", function (t) {
+ npmconf.load(cli, common.builtin, function (er, conf) {
+ if (er) throw er
+ t.same(conf.list, expectList)
+ t.same(conf.sources, expectSources)
+ t.same(npmconf.rootConf.list, [])
+ t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
+ t.equal(conf.root, npmconf.defs.defaults)
+ t.equal(conf.get("heading"), "foo")
+ t.equal(conf.get("git-tag-version"), false)
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-certfile.js b/deps/npm/test/tap/config-certfile.js
new file mode 100644
index 0000000000..25de9963a9
--- /dev/null
+++ b/deps/npm/test/tap/config-certfile.js
@@ -0,0 +1,18 @@
+require("./00-config-setup.js")
+
+var path = require("path")
+var fs = require("fs")
+var test = require("tap").test
+var npmconf = require("../../lib/config/core.js")
+
+test("cafile loads as ca", function (t) {
+ var cafile = path.join(__dirname, "..", "fixtures", "config", "multi-ca")
+
+ npmconf.load({cafile: cafile}, function (er, conf) {
+ if (er) throw er
+
+ t.same(conf.get("cafile"), cafile)
+ t.same(conf.get("ca").join("\n"), fs.readFileSync(cafile, "utf8").trim())
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-credentials.js b/deps/npm/test/tap/config-credentials.js
new file mode 100644
index 0000000000..c24bb7e1b2
--- /dev/null
+++ b/deps/npm/test/tap/config-credentials.js
@@ -0,0 +1,295 @@
+var test = require("tap").test
+
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+
+var URI = "https://registry.lvh.me:8661/"
+
+test("getting scope with no credentials set", function (t) {
+ npmconf.load({}, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var basic = conf.getCredentialsByURI(URI)
+ t.equal(basic.scope, "//registry.lvh.me:8661/", "nerfed URL extracted")
+
+ t.end()
+ })
+})
+
+test("trying to set credentials with no URI", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.throws(function () {
+ conf.setCredentialsByURI()
+ }, "enforced missing URI")
+
+ t.end()
+ })
+})
+
+test("set with missing credentials object", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.throws(function () {
+ conf.setCredentialsByURI(URI)
+ }, "enforced missing credentials")
+
+ t.end()
+ })
+})
+
+test("set with empty credentials object", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.throws(function () {
+ conf.setCredentialsByURI(URI, {})
+ }, "enforced missing credentials")
+
+ t.end()
+ })
+})
+
+test("set with token", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ t.doesNotThrow(function () {
+ conf.setCredentialsByURI(URI, {token : "simple-token"})
+ }, "needs only token")
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : "simple-token",
+ username : undefined,
+ password : undefined,
+ email : undefined,
+ auth : undefined,
+ alwaysAuth : undefined
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got bearer token and scope")
+
+ t.end()
+ })
+})
+
+test("set with missing username", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ password : "password",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ t.throws(function () {
+ conf.setCredentialsByURI(URI, credentials)
+ }, "enforced missing email")
+
+ t.end()
+ })
+})
+
+test("set with missing password", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ t.throws(function () {
+ conf.setCredentialsByURI(URI, credentials)
+ }, "enforced missing email")
+
+ t.end()
+ })
+})
+
+test("set with missing email", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ password : "password"
+ }
+
+ t.throws(function () {
+ conf.setCredentialsByURI(URI, credentials)
+ }, "enforced missing email")
+
+ t.end()
+ })
+})
+
+test("set with old-style credentials", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ t.doesNotThrow(function () {
+ conf.setCredentialsByURI(URI, credentials)
+ }, "requires all of username, password, and email")
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : undefined,
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : false
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
+
+ t.end()
+ })
+})
+
+test("get old-style credentials for default registry", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ var actual = conf.getCredentialsByURI(conf.get("registry"))
+ var expected = {
+ scope : "//registry.npmjs.org/",
+ token : undefined,
+ password : "password",
+ username : "username",
+ email : "i@izs.me",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : false
+ }
+ t.same(actual, expected)
+ t.end()
+ })
+})
+
+test("set with always-auth enabled", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ alwaysAuth : true
+ }
+
+ conf.setCredentialsByURI(URI, credentials)
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : undefined,
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : true
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
+
+ t.end()
+ })
+})
+
+test("set with always-auth disabled", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ alwaysAuth : false
+ }
+
+ conf.setCredentialsByURI(URI, credentials)
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : undefined,
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : false
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
+
+ t.end()
+ })
+})
+
+test("set with global always-auth enabled", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+ var original = conf.get("always-auth")
+ conf.set("always-auth", true)
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ conf.setCredentialsByURI(URI, credentials)
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : undefined,
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : true
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
+
+ conf.set("always-auth", original)
+ t.end()
+ })
+})
+
+test("set with global always-auth disabled", function (t) {
+ npmconf.load(common.builtin, function (er, conf) {
+ t.ifError(er, "configuration loaded")
+ var original = conf.get("always-auth")
+ conf.set("always-auth", false)
+
+ var credentials = {
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net"
+ }
+
+ conf.setCredentialsByURI(URI, credentials)
+
+ var expected = {
+ scope : "//registry.lvh.me:8661/",
+ token : undefined,
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ auth : "dXNlcm5hbWU6cGFzc3dvcmQ=",
+ alwaysAuth : false
+ }
+
+ t.same(conf.getCredentialsByURI(URI), expected, "got credentials")
+
+ conf.set("always-auth", original)
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-malformed.js b/deps/npm/test/tap/config-malformed.js
new file mode 100644
index 0000000000..0450221462
--- /dev/null
+++ b/deps/npm/test/tap/config-malformed.js
@@ -0,0 +1,14 @@
+var test = require('tap').test
+
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+
+test('with malformed', function (t) {
+ npmconf.load({}, common.malformed, function (er, conf) {
+ t.ok(er, 'Expected parse error')
+ if (!(er && /Failed parsing JSON config key email/.test(er.message))) {
+ throw er
+ }
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-meta.js b/deps/npm/test/tap/config-meta.js
index 26ca6f2b05..faced80d99 100644
--- a/deps/npm/test/tap/config-meta.js
+++ b/deps/npm/test/tap/config-meta.js
@@ -51,16 +51,16 @@ test("get files", function (t) {
test("get lines", function (t) {
FILES.forEach(function (f) {
- var lines = fs.readFileSync(f, 'utf8').split(/\r|\n/)
+ var lines = fs.readFileSync(f, "utf8").split(/\r|\n/)
lines.forEach(function (l, i) {
var matches = l.split(/conf(?:ig)?\.get\(/g)
matches.shift()
matches.forEach(function (m) {
- m = m.split(')').shift()
+ m = m.split(")").shift()
var literal = m.match(/^['"].+['"]$/)
if (literal) {
m = m.slice(1, -1)
- if (!m.match(/^\_/) && m !== 'argv')
+ if (!m.match(/^\_/) && m !== "argv")
CONFS[m] = {
file: f,
line: i
@@ -81,48 +81,46 @@ test("get docs", function (t) {
for (var i = 0; i < d.length && d[i] !== "## Config Settings"; i++);
i++
// now gather up all the ^###\s lines until the next ^##\s
- var doclines = []
for (; i < d.length && !d[i].match(/^## /); i++) {
if (d[i].match(/^### /))
- DOC[ d[i].replace(/^### /, '').trim() ] = true
+ DOC[ d[i].replace(/^### /, "").trim() ] = true
}
t.pass("read the docs")
t.end()
})
test("check configs", function (t) {
- var defs = require("npmconf/config-defs.js")
+ var defs = require("../../lib/config/defaults.js")
var types = Object.keys(defs.types)
var defaults = Object.keys(defs.defaults)
-
- for (var c in CONFS) {
- if (CONFS[c].file.indexOf(lib) === 0) {
- t.ok(DOC[c], "should be documented " + c + " "
- + CONFS[c].file + ":" + CONFS[c].line)
- t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c)
- t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c)
+ for (var c1 in CONFS) {
+ if (CONFS[c1].file.indexOf(lib) === 0) {
+ t.ok(DOC[c1], "should be documented " + c1 + " "
+ + CONFS[c1].file + ":" + CONFS[c1].line)
+ t.ok(types.indexOf(c1) !== -1, "should be defined in npmconf " + c1)
+ t.ok(defaults.indexOf(c1) !== -1, "should have default in npmconf " + c1)
}
}
- for (var c in DOC) {
- if (c !== "versions" && c !== "version" && c !== "init.version") {
- t.ok(CONFS[c], "config in doc should be used somewhere " + c)
- t.ok(types.indexOf(c) !== -1, "should be defined in npmconf " + c)
- t.ok(defaults.indexOf(c) !== -1, "should have default in npmconf " + c)
+ for (var c2 in DOC) {
+ if (c2 !== "versions" && c2 !== "version" && c2 !== "init.version") {
+ t.ok(CONFS[c2], "config in doc should be used somewhere " + c2)
+ t.ok(types.indexOf(c2) !== -1, "should be defined in npmconf " + c2)
+ t.ok(defaults.indexOf(c2) !== -1, "should have default in npmconf " + c2)
}
}
- types.forEach(function(c) {
- if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) {
- t.ok(DOC[c], 'defined type should be documented ' + c)
- t.ok(CONFS[c], 'defined type should be used ' + c)
+ types.forEach(function (c) {
+ if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) {
+ t.ok(DOC[c], "defined type should be documented " + c)
+ t.ok(CONFS[c], "defined type should be used " + c)
}
})
- defaults.forEach(function(c) {
- if (!c.match(/^\_/) && c !== 'argv' && !c.match(/^versions?$/)) {
- t.ok(DOC[c], 'defaulted type should be documented ' + c)
- t.ok(CONFS[c], 'defaulted type should be used ' + c)
+ defaults.forEach(function (c) {
+ if (!c.match(/^\_/) && c !== "argv" && !c.match(/^versions?$/)) {
+ t.ok(DOC[c], "defaulted type should be documented " + c)
+ t.ok(CONFS[c], "defaulted type should be used " + c)
}
})
diff --git a/deps/npm/test/tap/config-project.js b/deps/npm/test/tap/config-project.js
new file mode 100644
index 0000000000..337355bf28
--- /dev/null
+++ b/deps/npm/test/tap/config-project.js
@@ -0,0 +1,66 @@
+var test = require("tap").test
+var path = require("path")
+var fix = path.resolve(__dirname, "..", "fixtures", "config")
+var projectRc = path.resolve(fix, ".npmrc")
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+
+var projectData = { just: "testing" }
+
+var ucData = common.ucData
+var envData = common.envData
+var envDataFix = common.envDataFix
+
+var gcData = { "package-config:foo": "boo" }
+
+var biData = {}
+
+var cli = { foo: "bar", umask: 022, prefix: fix }
+
+var expectList = [
+ cli,
+ envDataFix,
+ projectData,
+ ucData,
+ gcData,
+ biData
+]
+
+var expectSources = {
+ cli: { data: cli },
+ env: {
+ data: envDataFix,
+ source: envData,
+ prefix: ""
+ },
+ project: {
+ path: projectRc,
+ type: "ini",
+ data: projectData
+ },
+ user: {
+ path: common.userconfig,
+ type: "ini",
+ data: ucData
+ },
+ global: {
+ path: common.globalconfig,
+ type: "ini",
+ data: gcData
+ },
+ builtin: { data: biData }
+}
+
+test("no builtin", function (t) {
+ npmconf.load(cli, function (er, conf) {
+ if (er) throw er
+ t.same(conf.list, expectList)
+ t.same(conf.sources, expectSources)
+ t.same(npmconf.rootConf.list, [])
+ t.equal(npmconf.rootConf.root, npmconf.defs.defaults)
+ t.equal(conf.root, npmconf.defs.defaults)
+ t.equal(conf.get("umask"), 022)
+ t.equal(conf.get("heading"), "npm")
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-save.js b/deps/npm/test/tap/config-save.js
new file mode 100644
index 0000000000..88526a38af
--- /dev/null
+++ b/deps/npm/test/tap/config-save.js
@@ -0,0 +1,88 @@
+var fs = require("fs")
+var ini = require("ini")
+var test = require("tap").test
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+
+var expectConf = [
+ "globalconfig = " + common.globalconfig,
+ "email = i@izs.me",
+ "env-thing = asdf",
+ "init.author.name = Isaac Z. Schlueter",
+ "init.author.email = i@izs.me",
+ "init.author.url = http://blog.izs.me/",
+ "init.version = 1.2.3",
+ "proprietary-attribs = false",
+ "npm:publishtest = true",
+ "_npmjs.org:couch = https://admin:password@localhost:5984/registry",
+ "npm-www:nocache = 1",
+ "sign-git-tag = false",
+ "message = v%s",
+ "strict-ssl = false",
+ "_auth = dXNlcm5hbWU6cGFzc3dvcmQ=",
+ "",
+ "[_token]",
+ "AuthSession = yabba-dabba-doodle",
+ "version = 1",
+ "expires = 1345001053415",
+ "path = /",
+ "httponly = true",
+ ""
+].join("\n")
+
+var expectFile = [
+ "globalconfig = " + common.globalconfig,
+ "email = i@izs.me",
+ "env-thing = asdf",
+ "init.author.name = Isaac Z. Schlueter",
+ "init.author.email = i@izs.me",
+ "init.author.url = http://blog.izs.me/",
+ "init.version = 1.2.3",
+ "proprietary-attribs = false",
+ "npm:publishtest = true",
+ "_npmjs.org:couch = https://admin:password@localhost:5984/registry",
+ "npm-www:nocache = 1",
+ "sign-git-tag = false",
+ "message = v%s",
+ "strict-ssl = false",
+ "_auth = dXNlcm5hbWU6cGFzc3dvcmQ=",
+ "",
+ "[_token]",
+ "AuthSession = yabba-dabba-doodle",
+ "version = 1",
+ "expires = 1345001053415",
+ "path = /",
+ "httponly = true",
+ ""
+].join("\n")
+
+test("saving configs", function (t) {
+ npmconf.load(function (er, conf) {
+ if (er)
+ throw er
+ conf.set("sign-git-tag", false, "user")
+ conf.del("nodedir")
+ conf.del("tmp")
+ var foundConf = ini.stringify(conf.sources.user.data)
+ t.same(ini.parse(foundConf), ini.parse(expectConf))
+ fs.unlinkSync(common.userconfig)
+ conf.save("user", function (er) {
+ if (er)
+ throw er
+ var uc = fs.readFileSync(conf.get("userconfig"), "utf8")
+ t.same(ini.parse(uc), ini.parse(expectFile))
+ t.end()
+ })
+ })
+})
+
+test("setting prefix", function (t) {
+ npmconf.load(function (er, conf) {
+ if (er)
+ throw er
+
+ conf.prefix = "newvalue"
+ t.same(conf.prefix, "newvalue")
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/config-semver-tag.js b/deps/npm/test/tap/config-semver-tag.js
new file mode 100644
index 0000000000..4ce1cb219e
--- /dev/null
+++ b/deps/npm/test/tap/config-semver-tag.js
@@ -0,0 +1,27 @@
+var util = require("util")
+var test = require("tap").test
+var npmconf = require("../../lib/config/core.js")
+var common = require("./00-config-setup.js")
+
+var cli = { tag: "v2.x" }
+
+var log = require("npmlog")
+
+test("tag cannot be a SemVer", function (t) {
+ var messages = []
+ log.warn = function (m) {
+ messages.push(m + " " + util.format.apply(util, [].slice.call(arguments, 1)))
+ }
+
+ var expect = [
+ 'invalid config tag="v2.x"',
+ "invalid config Tag must not be a SemVer range"
+ ]
+
+ npmconf.load(cli, common.builtin, function (er, conf) {
+ if (er) throw er
+ t.equal(conf.get("tag"), "latest")
+ t.same(messages, expect)
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/dedupe.js b/deps/npm/test/tap/dedupe.js
index b4b7495aa8..c0a648e738 100644
--- a/deps/npm/test/tap/dedupe.js
+++ b/deps/npm/test/tap/dedupe.js
@@ -2,17 +2,26 @@ var test = require("tap").test
, fs = require("fs")
, path = require("path")
, existsSync = fs.existsSync || path.existsSync
- , npm = require("../../")
, rimraf = require("rimraf")
, mr = require("npm-registry-mock")
- , common = require('../common-tap.js')
+ , common = require("../common-tap.js")
+
+var EXEC_OPTS = {}
test("dedupe finds the common module and moves it up one level", function (t) {
setup(function (s) {
- npm.install(".", function (err) {
- if (err) return t.fail(err)
- npm.dedupe(function(err) {
- if (err) return t.fail(err)
+ common.npm(
+ [
+ "install", ".",
+ "--registry", common.registry
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ t.ifError(err, "successfully installed directory")
+ t.equal(code, 0, "npm install exited with code")
+ common.npm(["dedupe"], {}, function (err, code) {
+ t.ifError(err, "successfully deduped against previous install")
+ t.notOk(code, "npm dedupe exited with code")
t.ok(existsSync(path.join(__dirname, "dedupe", "node_modules", "minimist")))
t.ok(!existsSync(path.join(__dirname, "dedupe", "node_modules", "checker")))
s.close() // shutdown mock registry.
@@ -25,10 +34,8 @@ test("dedupe finds the common module and moves it up one level", function (t) {
function setup (cb) {
process.chdir(path.join(__dirname, "dedupe"))
mr(common.port, function (s) { // create mock registry.
- npm.load({registry: common.registry}, function() {
- rimraf.sync(path.join(__dirname, "dedupe", "node_modules"))
- fs.mkdirSync(path.join(__dirname, "dedupe", "node_modules"))
- cb(s)
- })
+ rimraf.sync(path.join(__dirname, "dedupe", "node_modules"))
+ fs.mkdirSync(path.join(__dirname, "dedupe", "node_modules"))
+ cb(s)
})
}
diff --git a/deps/npm/test/tap/dev-dep-duplicate/desired-ls-results.json b/deps/npm/test/tap/dev-dep-duplicate/desired-ls-results.json
new file mode 100644
index 0000000000..355039a092
--- /dev/null
+++ b/deps/npm/test/tap/dev-dep-duplicate/desired-ls-results.json
@@ -0,0 +1,9 @@
+{
+ "name": "dev-dep-duplicate",
+ "version": "0.0.0",
+ "dependencies": {
+ "underscore": {
+ "version": "1.5.1"
+ }
+ }
+}
diff --git a/deps/npm/test/tap/dev-dep-duplicate/package.json b/deps/npm/test/tap/dev-dep-duplicate/package.json
new file mode 100644
index 0000000000..87061b9d54
--- /dev/null
+++ b/deps/npm/test/tap/dev-dep-duplicate/package.json
@@ -0,0 +1,11 @@
+{
+ "author": "Anders Janmyr",
+ "name": "dev-dep-duplicate",
+ "version": "0.0.0",
+ "dependencies": {
+ "underscore": "1.5.1"
+ },
+ "devDependencies": {
+ "underscore": "1.3.1"
+ }
+}
diff --git a/deps/npm/test/tap/false_name.js b/deps/npm/test/tap/false_name.js
index 5ab1a67ecc..b02eafec99 100644
--- a/deps/npm/test/tap/false_name.js
+++ b/deps/npm/test/tap/false_name.js
@@ -11,41 +11,45 @@ var test = require("tap").test
, fs = require("fs")
, path = require("path")
, existsSync = fs.existsSync || path.existsSync
- , spawn = require("child_process").spawn
- , npm = require("../../")
, rimraf = require("rimraf")
, common = require("../common-tap.js")
, mr = require("npm-registry-mock")
- , pkg = __dirname + "/false_name"
+ , pkg = path.resolve(__dirname, "false_name")
+ , cache = path.resolve(pkg, "cache")
+ , nodeModules = path.resolve(pkg, "node_modules")
-test("not every pkg.name can be required", function (t) {
- rimraf.sync(pkg + "/cache")
+var EXEC_OPTS = { cwd: pkg }
- t.plan(1)
+test("setup", function(t) {
+ cleanup()
+ fs.mkdirSync(nodeModules)
+ t.end()
+})
+
+test("not every pkg.name can be required", function (t) {
+ t.plan(3)
mr(common.port, function (s) {
- setup(function () {
- npm.install(".", function (err) {
- if (err) return t.fail(err)
- s.close()
- t.ok(existsSync(pkg + "/node_modules/test-package-with-one-dep/" +
- "node_modules/test-package"))
- })
+ common.npm([
+ "install", ".",
+ "--cache", cache,
+ "--registry", common.registry
+ ], EXEC_OPTS, function (err, code) {
+ s.close()
+ t.ifErr(err, "install finished without error")
+ t.equal(code, 0, "install exited ok")
+ t.ok(existsSync(path.resolve(pkg,
+ "node_modules/test-package-with-one-dep",
+ "node_modules/test-package")))
})
})
})
+function cleanup() {
+ rimraf.sync(cache)
+ rimraf.sync(nodeModules)
+}
+
test("cleanup", function (t) {
- rimraf.sync(pkg + "/cache")
- rimraf.sync(pkg + "/node_modules")
+ cleanup()
t.end()
})
-
-function setup (cb) {
- process.chdir(pkg)
- npm.load({cache: pkg + "/cache", registry: common.registry},
- function () {
- rimraf.sync(pkg + "/node_modules")
- fs.mkdirSync(pkg + "/node_modules")
- cb()
- })
-}
diff --git a/deps/npm/test/tap/git-cache-locking.js b/deps/npm/test/tap/git-cache-locking.js
index b9b328f30c..39f8b279c3 100644
--- a/deps/npm/test/tap/git-cache-locking.js
+++ b/deps/npm/test/tap/git-cache-locking.js
@@ -1,10 +1,8 @@
var test = require("tap").test
+ , common = require("../common-tap")
, path = require("path")
, rimraf = require("rimraf")
, mkdirp = require("mkdirp")
- , spawn = require("child_process").spawn
- , npm = require.resolve("../../bin/npm-cli.js")
- , node = process.execPath
, pkg = path.resolve(__dirname, "git-cache-locking")
, tmp = path.join(pkg, "tmp")
, cache = path.join(pkg, "cache")
@@ -12,10 +10,7 @@ var test = require("tap").test
test("setup", function (t) {
rimraf.sync(pkg)
- mkdirp.sync(pkg)
- mkdirp.sync(cache)
- mkdirp.sync(tmp)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
t.end()
})
@@ -26,27 +21,28 @@ test("git-cache-locking: install a git dependency", function (t) {
// package c depends on a.git#master and b.git#master
// package b depends on a.git#master
- var child = spawn(node, [npm, "install", "git://github.com/nigelzor/npm-4503-c.git"], {
+ common.npm([
+ "install",
+ "git://github.com/nigelzor/npm-4503-c.git"
+ ], {
cwd: pkg,
env: {
- npm_config_cache: cache,
- npm_config_tmp: tmp,
- npm_config_prefix: pkg,
- npm_config_global: "false",
+ "npm_config_cache": cache,
+ "npm_config_tmp": tmp,
+ "npm_config_prefix": pkg,
+ "npm_config_global": "false",
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH
- },
- stdio: "inherit"
- })
-
- child.on("close", function (code) {
+ }
+ }, function (err, code) {
+ t.ifErr(err, "npm install finished without error")
t.equal(0, code, "npm install should succeed")
t.end()
})
})
-test('cleanup', function(t) {
+test("cleanup", function(t) {
rimraf.sync(pkg)
t.end()
})
diff --git a/deps/npm/test/tap/git-cache-no-hooks.js b/deps/npm/test/tap/git-cache-no-hooks.js
new file mode 100644
index 0000000000..32731fa1b0
--- /dev/null
+++ b/deps/npm/test/tap/git-cache-no-hooks.js
@@ -0,0 +1,63 @@
+var test = require("tap").test
+ , fs = require("fs")
+ , path = require("path")
+ , rimraf = require("rimraf")
+ , mkdirp = require("mkdirp")
+ , spawn = require("child_process").spawn
+ , npmCli = require.resolve("../../bin/npm-cli.js")
+ , node = process.execPath
+ , pkg = path.resolve(__dirname, "git-cache-no-hooks")
+ , tmp = path.join(pkg, "tmp")
+ , cache = path.join(pkg, "cache")
+
+
+test("setup", function (t) {
+ rimraf.sync(pkg)
+ mkdirp.sync(pkg)
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
+ t.end()
+})
+
+test("git-cache-no-hooks: install a git dependency", function (t) {
+
+ // disable git integration tests on Travis.
+ if (process.env.TRAVIS) return t.end()
+
+ var command = [ npmCli
+ , "install"
+ , "git://github.com/nigelzor/npm-4503-a.git"
+ ]
+ var child = spawn(node, command, {
+ cwd: pkg,
+ env: {
+ "npm_config_cache" : cache,
+ "npm_config_tmp" : tmp,
+ "npm_config_prefix" : pkg,
+ "npm_config_global" : "false",
+ "npm_config_umask" : "00",
+ HOME : process.env.HOME,
+ Path : process.env.PATH,
+ PATH : process.env.PATH
+ },
+ stdio: "inherit"
+ })
+
+ child.on("close", function (code) {
+ t.equal(code, 0, "npm install should succeed")
+
+ // verify permissions on git hooks
+ var repoDir = "git-github-com-nigelzor-npm-4503-a-git-40c5cb24"
+ var hooksPath = path.join(cache, "_git-remotes", repoDir, "hooks")
+ fs.readdir(hooksPath, function (err) {
+ t.equal(err && err.code, "ENOENT", "hooks are not brought along with repo")
+ t.end()
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ rimraf.sync(pkg)
+ t.end()
+})
diff --git a/deps/npm/test/tap/git-cache-permissions.js b/deps/npm/test/tap/git-cache-permissions.js
deleted file mode 100644
index 27905fba5e..0000000000
--- a/deps/npm/test/tap/git-cache-permissions.js
+++ /dev/null
@@ -1,80 +0,0 @@
-var test = require("tap").test
- , fs = require("fs")
- , path = require("path")
- , rimraf = require("rimraf")
- , mkdirp = require("mkdirp")
- , spawn = require("child_process").spawn
- , npm = require("../../lib/npm")
- , npmCli = require.resolve("../../bin/npm-cli.js")
- , node = process.execPath
- , pkg = path.resolve(__dirname, "git-cache-permissions")
- , tmp = path.join(pkg, "tmp")
- , cache = path.join(pkg, "cache")
-
-
-test("setup", function (t) {
- rimraf.sync(pkg)
- mkdirp.sync(pkg)
- mkdirp.sync(cache)
- mkdirp.sync(tmp)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
- t.end()
-})
-
-test("git-cache-permissions: install a git dependency", function (t) {
-
- // disable git integration tests on Travis.
- if (process.env.TRAVIS) return t.end()
-
- var command = [ npmCli
- , "install"
- , "git://github.com/nigelzor/npm-4503-a.git"
- ]
- var child = spawn(node, command, {
- cwd: pkg,
- env: {
- npm_config_cache: cache,
- npm_config_tmp: tmp,
- npm_config_prefix: pkg,
- npm_config_global: "false",
- npm_config_umask: "00",
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH
- },
- stdio: "inherit"
- })
-
- child.on("close", function (code) {
- t.equal(code, 0, "npm install should succeed")
-
- // verify permissions on git hooks
- var repoDir = "git-github-com-nigelzor-npm-4503-a-git-40c5cb24"
- var hooksPath = path.join(cache, "_git-remotes", repoDir, "hooks")
- fs.readdir(hooksPath, function (err, files) {
- if (err) {
- t.ok(false, "error reading hooks: " + err)
- t.end()
- }
-
- files.forEach(function (file) {
- var stats = fs.statSync(path.join(hooksPath, file))
- var message = "hook [" + file + "] should have correct permissions"
-
- // Possible error conditions and the resulting file modes on hooks
- // npm.modes.file is used directly -> "100666"
- // permissions are left untouched -> "100755"
- // we do not want permissions left untouched because of
- // https://github.com/npm/npm/issues/3117
- t.equal(stats.mode.toString(8), "100777", message)
- })
-
- t.end()
- })
- })
-})
-
-test('cleanup', function(t) {
- rimraf.sync(pkg)
- t.end()
-})
diff --git a/deps/npm/test/tap/global-prefix-set-in-userconfig.js b/deps/npm/test/tap/global-prefix-set-in-userconfig.js
index 85fa4f610a..f820a27727 100644
--- a/deps/npm/test/tap/global-prefix-set-in-userconfig.js
+++ b/deps/npm/test/tap/global-prefix-set-in-userconfig.js
@@ -15,9 +15,9 @@ test("setup", function (t) {
test("run command", function (t) {
var args = ["prefix", "-g", "--userconfig=" + rcfile]
- common.npm(args, {env: {}}, function (er, code, so, se) {
+ common.npm(args, {env: {}}, function (er, code, so) {
if (er) throw er
- t.equal(code, 0)
+ t.notOk(code, "npm prefix exited with code 0")
t.equal(so.trim(), prefix)
t.end()
})
diff --git a/deps/npm/test/tap/ignore-install-link.js b/deps/npm/test/tap/ignore-install-link.js
index 44ae541538..45db51d30f 100644
--- a/deps/npm/test/tap/ignore-install-link.js
+++ b/deps/npm/test/tap/ignore-install-link.js
@@ -52,7 +52,7 @@ test("ignore install if package is linked", function (t) {
stdio: "inherit"
}, function (er, code) {
if (er) throw er
- t.equal(code, 0)
+ t.equal(code, 0, "npm install exited with code")
t.end()
})
})
diff --git a/deps/npm/test/tap/ignore-scripts.js b/deps/npm/test/tap/ignore-scripts.js
index 0115b7571d..9526443e92 100644
--- a/deps/npm/test/tap/ignore-scripts.js
+++ b/deps/npm/test/tap/ignore-scripts.js
@@ -1,24 +1,24 @@
+var common = require("../common-tap")
var test = require("tap").test
-var npm = require.resolve("../../bin/npm-cli.js")
-
-var spawn = require("child_process").spawn
-var node = process.execPath
+var path = require("path")
// ignore-scripts/package.json has scripts that always exit with non-zero error
// codes. The "install" script is omitted so that npm tries to run node-gyp,
// which should also fail.
-var pkg = __dirname + "/ignore-scripts"
+var pkg = path.resolve(__dirname, "ignore-scripts")
-test("ignore-scripts: install using the option", function(t) {
- createChild([npm, "install", "--ignore-scripts"]).on("close", function(code) {
- t.equal(code, 0)
+test("ignore-scripts: install using the option", function (t) {
+ createChild(["install", "--ignore-scripts"], function (err, code) {
+ t.ifError(err, "install with scripts ignored finished successfully")
+ t.equal(code, 0, "npm install exited with code")
t.end()
})
})
-test("ignore-scripts: install NOT using the option", function(t) {
- createChild([npm, "install"]).on("close", function(code) {
- t.notEqual(code, 0)
+test("ignore-scripts: install NOT using the option", function (t) {
+ createChild(["install"], function (err, code) {
+ t.ifError(err, "install with scripts successful")
+ t.notEqual(code, 0, "npm install exited with code")
t.end()
})
})
@@ -34,39 +34,40 @@ var scripts = [
"prerestart", "restart", "postrestart"
]
-scripts.forEach(function(script) {
- test("ignore-scripts: run-script "+script+" using the option", function(t) {
- createChild([npm, "--ignore-scripts", "run-script", script])
- .on("close", function(code) {
- t.equal(code, 0)
- t.end()
- })
+scripts.forEach(function (script) {
+ test("ignore-scripts: run-script "+script+" using the option", function (t) {
+ createChild(["--ignore-scripts", "run-script", script], function (err, code) {
+ t.ifError(err, "run-script " + script + " with ignore-scripts successful")
+ t.equal(code, 0, "npm run-script exited with code")
+ t.end()
+ })
})
})
-scripts.forEach(function(script) {
- test("ignore-scripts: run-script "+script+" NOT using the option", function(t) {
- createChild([npm, "run-script", script]).on("close", function(code) {
- t.notEqual(code, 0)
+scripts.forEach(function (script) {
+ test("ignore-scripts: run-script "+script+" NOT using the option", function (t) {
+ createChild(["run-script", script], function (err, code) {
+ t.ifError(err, "run-script " + script + " finished successfully")
+ t.notEqual(code, 0, "npm run-script exited with code")
t.end()
})
})
})
-function createChild (args) {
+function createChild (args, cb) {
var env = {
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH,
- npm_config_loglevel: "silent"
+ "npm_config_loglevel": "silent"
}
if (process.platform === "win32")
env.npm_config_cache = "%APPDATA%\\npm-cache"
- return spawn(node, args, {
+ return common.npm(args, {
cwd: pkg,
stdio: "inherit",
env: env
- })
+ }, cb)
}
diff --git a/deps/npm/test/tap/ignore-shrinkwrap.js b/deps/npm/test/tap/ignore-shrinkwrap.js
index ce1c66425c..6744a868a2 100644
--- a/deps/npm/test/tap/ignore-shrinkwrap.js
+++ b/deps/npm/test/tap/ignore-shrinkwrap.js
@@ -1,10 +1,9 @@
var common = require("../common-tap.js")
var test = require("tap").test
-var pkg = './ignore-shrinkwrap'
+var pkg = require("path").join(__dirname,"ignore-shrinkwrap")
var mr = require("npm-registry-mock")
-var child
var spawn = require("child_process").spawn
var npm = require.resolve("../../bin/npm-cli.js")
var node = process.execPath
@@ -18,7 +17,7 @@ var customMocks = {
test("ignore-shrinkwrap: using the option", function (t) {
mr({port: common.port, mocks: customMocks}, function (s) {
- s._server.on("request", function (req, res) {
+ s._server.on("request", function (req) {
switch (req.url) {
case "/shrinkwrap.js":
t.fail()
@@ -28,7 +27,7 @@ test("ignore-shrinkwrap: using the option", function (t) {
}
})
var child = createChild(true)
- child.on("close", function (m) {
+ child.on("close", function () {
s.close()
t.end()
})
@@ -37,7 +36,7 @@ test("ignore-shrinkwrap: using the option", function (t) {
test("ignore-shrinkwrap: NOT using the option", function (t) {
mr({port: common.port, mocks: customMocks}, function (s) {
- s._server.on("request", function (req, res) {
+ s._server.on("request", function (req) {
switch (req.url) {
case "/shrinkwrap.js":
t.pass("shrinkwrap used")
@@ -47,7 +46,7 @@ test("ignore-shrinkwrap: NOT using the option", function (t) {
}
})
var child = createChild(false)
- child.on("close", function (m) {
+ child.on("close", function () {
s.close()
t.end()
})
@@ -65,13 +64,12 @@ function createChild (ignoreShrinkwrap) {
return spawn(node, args, {
cwd: pkg,
env: {
- npm_config_registry: common.registry,
- npm_config_cache_lock_stale: 1000,
- npm_config_cache_lock_wait: 1000,
+ "npm_config_registry": common.registry,
+ "npm_config_cache_lock_stale": 1000,
+ "npm_config_cache_lock_wait": 1000,
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH
}
})
-
}
diff --git a/deps/npm/test/tap/install-at-locally.js b/deps/npm/test/tap/install-at-locally.js
index f6290e1089..02874d0cd8 100644
--- a/deps/npm/test/tap/install-at-locally.js
+++ b/deps/npm/test/tap/install-at-locally.js
@@ -1,42 +1,42 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var path = require('path')
-var fs = require('fs')
-var rimraf = require('rimraf')
-var mkdirp = require('mkdirp')
-var pkg = path.join(__dirname, 'install-at-locally')
+var common = require("../common-tap.js")
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var pkg = path.join(__dirname, "install-at-locally")
+
+var EXEC_OPTS = { }
test("setup", function (t) {
mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
process.chdir(pkg)
t.end()
})
-test('"npm install ./package@1.2.3" should install local pkg', function(t) {
- npm.load(function() {
- npm.commands.install(['./package@1.2.3'], function(err) {
- var p = path.resolve(pkg, 'node_modules/install-at-locally/package.json')
- t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
- t.end()
- })
+test("\"npm install ./package@1.2.3\" should install local pkg", function(t) {
+ common.npm(["install", "./package@1.2.3"], EXEC_OPTS, function(err, code) {
+ var p = path.resolve(pkg, "node_modules/install-at-locally/package.json")
+ t.ifError(err, "install local package successful")
+ t.equal(code, 0, "npm install exited with code")
+ t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
+ t.end()
})
})
-test('"npm install install/at/locally@./package@1.2.3" should install local pkg', function(t) {
- npm.load(function() {
- npm.commands.install(['./package@1.2.3'], function(err) {
- var p = path.resolve(pkg, 'node_modules/install-at-locally/package.json')
- t.ok(JSON.parse(fs.readFileSync(p, 'utf8')))
- t.end()
- })
+test("\"npm install install/at/locally@./package@1.2.3\" should install local pkg", function(t) {
+ common.npm(["install", "./package@1.2.3"], EXEC_OPTS, function(err, code) {
+ var p = path.resolve(pkg, "node_modules/install-at-locally/package.json")
+ t.ifError(err, "install local package in explicit directory successful")
+ t.equal(code, 0, "npm install exited with code")
+ t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
+ t.end()
})
})
-test('cleanup', function(t) {
+test("cleanup", function(t) {
process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, 'node_modules'))
+ rimraf.sync(path.resolve(pkg, "node_modules"))
t.end()
})
-
diff --git a/deps/npm/test/tap/install-cli-production.js b/deps/npm/test/tap/install-cli-production.js
new file mode 100644
index 0000000000..00c9355270
--- /dev/null
+++ b/deps/npm/test/tap/install-cli-production.js
@@ -0,0 +1,44 @@
+var common = require("../common-tap.js")
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var pkg = path.join(__dirname, "install-cli-production")
+
+var EXEC_OPTS = {
+ cwd: pkg
+}
+
+test("setup", function(t) {
+ mkdirp.sync(pkg)
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
+ process.chdir(pkg)
+ t.end()
+})
+
+test("\"npm install --production\" should install dependencies", function(t) {
+ common.npm(["install", "--production"], EXEC_OPTS, function(err, code) {
+ t.ifError(err, "install production successful")
+ t.equal(code, 0, "npm install exited with code")
+ var p = path.resolve(pkg, "node_modules/dependency/package.json")
+ t.ok(JSON.parse(fs.readFileSync(p, "utf8")))
+ t.end()
+ })
+})
+
+test("\"npm install --production\" should not install dev dependencies", function(t) {
+ common.npm(["install", "--production"], EXEC_OPTS, function(err, code) {
+ t.ifError(err, "install production successful")
+ t.equal(code, 0, "npm install exited with code")
+ var p = path.resolve(pkg, "node_modules/dev-dependency/package.json")
+ t.ok(!fs.existsSync(p), "")
+ t.end()
+ })
+})
+
+test("cleanup", function(t) {
+ process.chdir(__dirname)
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ t.end()
+})
diff --git a/deps/npm/test/tap/install-cli-production/dependency/package.json b/deps/npm/test/tap/install-cli-production/dependency/package.json
new file mode 100644
index 0000000000..6ee6be0c3b
--- /dev/null
+++ b/deps/npm/test/tap/install-cli-production/dependency/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "dependency",
+ "description": "fixture",
+ "version": "0.0.0"
+}
diff --git a/deps/npm/test/tap/install-cli-production/dev-dependency/package.json b/deps/npm/test/tap/install-cli-production/dev-dependency/package.json
new file mode 100644
index 0000000000..a6a8f69763
--- /dev/null
+++ b/deps/npm/test/tap/install-cli-production/dev-dependency/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "dev-dependency",
+ "description": "fixture",
+ "version": "0.0.0"
+}
diff --git a/deps/npm/test/tap/install-cli-production/package.json b/deps/npm/test/tap/install-cli-production/package.json
new file mode 100644
index 0000000000..8f2f0e2ec2
--- /dev/null
+++ b/deps/npm/test/tap/install-cli-production/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "install-cli-production",
+ "description": "fixture",
+ "version": "0.0.0",
+ "scripts": {
+ "prepublish": "exit 123"
+ },
+ "dependencies": {
+ "dependency": "file:./dependency"
+ },
+ "devDependencies": {
+ "dev-dependency": "file:./dev-dependency"
+ }
+}
diff --git a/deps/npm/test/tap/install-cli-unicode.js b/deps/npm/test/tap/install-cli-unicode.js
index bb9b4f5eed..7318deffca 100644
--- a/deps/npm/test/tap/install-cli-unicode.js
+++ b/deps/npm/test/tap/install-cli-unicode.js
@@ -1,23 +1,24 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var mkdirp = require('mkdirp')
-var mr = require('npm-registry-mock')
-var exec = require('child_process').exec
+var common = require("../common-tap.js")
+var test = require("tap").test
+var mr = require("npm-registry-mock")
+var path = require("path")
-var pkg = __dirname + '/install-cli'
-var NPM_BIN = __dirname + '/../../bin/npm-cli.js'
+var pkg = path.resolve(__dirname, "install-cli")
function hasOnlyAscii (s) {
- return /^[\000-\177]*$/.test(s) ;
+ return /^[\000-\177]*$/.test(s)
}
-test('does not use unicode with --unicode false', function (t) {
- t.plan(3)
+var EXEC_OPTS = {
+ cwd : pkg
+}
+
+test("does not use unicode with --unicode false", function (t) {
+ t.plan(5)
mr(common.port, function (s) {
- exec('node ' + NPM_BIN + ' install --unicode false read', {
- cwd: pkg
- }, function(err, stdout) {
+ common.npm(["install", "--unicode", "false", "read"], EXEC_OPTS, function (err, code, stdout) {
+ t.ifError(err, "install package read without unicode success")
+ t.notOk(code, "npm install exited with code 0")
t.ifError(err)
t.ok(stdout, stdout.length)
t.ok(hasOnlyAscii(stdout))
@@ -26,11 +27,11 @@ test('does not use unicode with --unicode false', function (t) {
})
})
-test('cleanup', function (t) {
+test("cleanup", function (t) {
mr(common.port, function (s) {
- exec('node ' + NPM_BIN + ' uninstall read', {
- cwd: pkg
- }, function(err, stdout) {
+ common.npm(["uninstall", "read"], EXEC_OPTS, function (err, code) {
+ t.ifError(err, "uninstall read package success")
+ t.notOk(code, "npm uninstall exited with code 0")
s.close()
})
})
diff --git a/deps/npm/test/tap/install-from-local.js b/deps/npm/test/tap/install-from-local.js
index 2dc3b57721..d1fbb3b909 100644
--- a/deps/npm/test/tap/install-from-local.js
+++ b/deps/npm/test/tap/install-from-local.js
@@ -1,33 +1,34 @@
+var common = require("../common-tap")
var test = require("tap").test
-var npm = require("../../")
var path = require("path")
var fs = require("fs")
var rimraf = require("rimraf")
var pkg = path.join(__dirname, "install-from-local", "package-with-local-paths")
+var EXEC_OPTS = { }
+
test("setup", function (t) {
process.chdir(pkg)
t.end()
})
test('"npm install" should install local packages', function (t) {
- npm.load({loglevel : "silent"}, function () {
- npm.commands.install(["."], function (err) {
- t.ifError(err, "local packages installed")
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
- t.ok(
- JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")),
- "package with local dependency installed"
- )
+ common.npm(["install", "."], EXEC_OPTS, function (err, code) {
+ t.ifError(err, "error should not exist")
+ t.notOk(code, "npm install exited with code 0")
+ var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
+ t.ok(
+ JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")),
+ "package with local dependency installed"
+ )
- var devDependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
- t.ok(
- JSON.parse(fs.readFileSync(devDependencyPackageJson, "utf8")),
- "package with local dev dependency installed"
- )
+ var devDependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
+ t.ok(
+ JSON.parse(fs.readFileSync(devDependencyPackageJson, "utf8")),
+ "package with local dev dependency installed"
+ )
- t.end()
- })
+ t.end()
})
})
diff --git a/deps/npm/test/tap/install-from-local/package-scoped-dependency/package.json b/deps/npm/test/tap/install-from-local/package-scoped-dependency/package.json
new file mode 100644
index 0000000000..ec3e13214e
--- /dev/null
+++ b/deps/npm/test/tap/install-from-local/package-scoped-dependency/package.json
@@ -0,0 +1,5 @@
+{
+ "name": "@scoped/package",
+ "version": "0.0.0",
+ "description": "Test for local installs"
+}
diff --git a/deps/npm/test/tap/install-from-local/package-with-scoped-paths/package.json b/deps/npm/test/tap/install-from-local/package-with-scoped-paths/package.json
new file mode 100644
index 0000000000..262aa57e06
--- /dev/null
+++ b/deps/npm/test/tap/install-from-local/package-with-scoped-paths/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "package-with-scoped-paths",
+ "version": "0.0.0",
+ "dependencies": {
+ "package-local-dependency": "file:../package-local-dependency",
+ "@scoped/package-scoped-dependency": "file:../package-scoped-dependency"
+ }
+}
diff --git a/deps/npm/test/tap/install-save-exact.js b/deps/npm/test/tap/install-save-exact.js
index c9f4866601..ef785f240e 100644
--- a/deps/npm/test/tap/install-save-exact.js
+++ b/deps/npm/test/tap/install-save-exact.js
@@ -1,40 +1,41 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var path = require('path')
-var fs = require('fs')
-var rimraf = require('rimraf')
-var mkdirp = require('mkdirp')
-var pkg = path.join(__dirname, 'install-save-exact')
+var common = require("../common-tap.js")
+var test = require("tap").test
+var npm = require("../../")
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var pkg = path.join(__dirname, "install-save-exact")
var mr = require("npm-registry-mock")
test("setup", function (t) {
mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
process.chdir(pkg)
t.end()
})
-test('"npm install --save --save-exact should install local pkg', function(t) {
+test("\"npm install --save --save-exact\" should install local pkg", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save', true)
- npm.config.set('save-exact', true)
- npm.commands.install(['underscore@1.3.1'], function(err) {
+ npm.config.set("save", true)
+ npm.config.set("save-exact", true)
+ npm.commands.install(["underscore@1.3.1"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ p = path.resolve(pkg, "package.json")
+ var pkgJson = JSON.parse(fs.readFileSync(p, "utf8"))
t.deepEqual(pkgJson.dependencies, {
- 'underscore': '1.3.1'
- }, 'Underscore dependency should specify exactly 1.3.1')
- npm.config.set('save', undefined)
- npm.config.set('save-exact', undefined)
+ "underscore": "1.3.1"
+ }, "Underscore dependency should specify exactly 1.3.1")
+ npm.config.set("save", undefined)
+ npm.config.set("save-exact", undefined)
s.close()
t.end()
})
@@ -42,50 +43,50 @@ test('"npm install --save --save-exact should install local pkg', function(t) {
})
})
-test('"npm install --save-dev --save-exact should install local pkg', function(t) {
+test("\"npm install --save-dev --save-exact\" should install local pkg", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save-dev', true)
- npm.config.set('save-exact', true)
- npm.commands.install(['underscore@1.3.1'], function(err) {
+ npm.config.set("save-dev", true)
+ npm.config.set("save-exact", true)
+ npm.commands.install(["underscore@1.3.1"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ p = path.resolve(pkg, "package.json")
+ var pkgJson = JSON.parse(fs.readFileSync(p, "utf8"))
console.log(pkgJson)
t.deepEqual(pkgJson.devDependencies, {
- 'underscore': '1.3.1'
- }, 'underscore devDependency should specify exactly 1.3.1')
+ "underscore": "1.3.1"
+ }, "underscore devDependency should specify exactly 1.3.1")
s.close()
- npm.config.set('save-dev', undefined)
- npm.config.set('save-exact', undefined)
+ npm.config.set("save-dev", undefined)
+ npm.config.set("save-exact", undefined)
t.end()
})
})
})
})
-test('cleanup', function(t) {
+test("cleanup", function (t) {
process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, 'node_modules'))
- rimraf.sync(path.resolve(pkg, 'cache'))
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ rimraf.sync(path.resolve(pkg, "cache"))
resetPackageJSON(pkg)
t.end()
})
function resetPackageJSON(pkg) {
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
delete pkgJson.dependencies
delete pkgJson.devDependencies
delete pkgJson.optionalDependencies
var json = JSON.stringify(pkgJson, null, 2) + "\n"
- fs.writeFileSync(pkg + '/package.json', json, "ascii")
+ var p = path.resolve(pkg, "package.json")
+ fs.writeFileSync(p, json, "ascii")
}
-
-
diff --git a/deps/npm/test/tap/install-save-local.js b/deps/npm/test/tap/install-save-local.js
index 52396f4bed..2a1f839984 100644
--- a/deps/npm/test/tap/install-save-local.js
+++ b/deps/npm/test/tap/install-save-local.js
@@ -1,58 +1,55 @@
+var common = require("../common-tap.js")
var test = require("tap").test
-var npm = require("../../")
var path = require("path")
var fs = require("fs")
var rimraf = require("rimraf")
var pkg = path.join(__dirname, "install-save-local", "package")
+var EXEC_OPTS = { }
+
test("setup", function (t) {
resetPackageJSON(pkg)
process.chdir(pkg)
t.end()
})
-test('"npm install --save ../local/path" should install local package and save to package.json', function(t) {
- resetPackageJSON(pkg)
- npm.load({loglevel : "silent"}, function() {
- npm.config.set("save", true)
- npm.commands.install(["../package-local-dependency"], function(err) {
- t.ifError(err)
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
+test('"npm install --save ../local/path" should install local package and save to package.json', function (t) {
+ resetPackageJSON(pkg)
+ common.npm(["install", "--save", "../package-local-dependency"], EXEC_OPTS, function (err, code) {
+ t.ifError(err)
+ t.notOk(code, "npm install exited with code 0")
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.dependencies, {
- "package-local-dependency": "file:../package-local-dependency"
- })
- npm.config.set("save", undefined)
+ var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dependency/package.json")
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
- t.end()
- })
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
+ t.deepEqual(pkgJson.dependencies, {
+ "package-local-dependency": "file:../package-local-dependency"
+ })
+ t.end()
})
})
-test('"npm install --save-dev ../local/path" should install local package and save to package.json', function(t) {
+test('"npm install --save-dev ../local/path" should install local package and save to package.json', function (t) {
resetPackageJSON(pkg)
- npm.load({loglevel : "silent"}, function() {
- npm.config.set("save-dev", true)
- npm.commands.install(["../package-local-dev-dependency"], function(err) {
- t.ifError(err)
+ common.npm(["install", "--save-dev", "../package-local-dev-dependency"], EXEC_OPTS, function (err, code) {
+ t.ifError(err)
+ t.notOk(code, "npm install exited with code 0")
- var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
- t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
+ var dependencyPackageJson = path.resolve(pkg, "node_modules/package-local-dev-dependency/package.json")
+ t.ok(JSON.parse(fs.readFileSync(dependencyPackageJson, "utf8")))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.deepEqual(pkgJson.devDependencies, {
- "package-local-dev-dependency": "file:../package-local-dev-dependency"
- })
- npm.config.set("save", undefined)
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
+ t.deepEqual(pkgJson.devDependencies, {
+ "package-local-dev-dependency": "file:../package-local-dev-dependency"
+ })
- t.end()
- })
+ t.end()
})
})
-test("cleanup", function(t) {
+
+test("cleanup", function (t) {
resetPackageJSON(pkg)
process.chdir(__dirname)
rimraf.sync(path.resolve(pkg, "node_modules"))
diff --git a/deps/npm/test/tap/install-save-prefix.js b/deps/npm/test/tap/install-save-prefix.js
index 0e78005b6e..d4efef4b61 100644
--- a/deps/npm/test/tap/install-save-prefix.js
+++ b/deps/npm/test/tap/install-save-prefix.js
@@ -1,39 +1,39 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var path = require('path')
-var fs = require('fs')
-var rimraf = require('rimraf')
-var mkdirp = require('mkdirp')
-var pkg = path.join(__dirname, 'install-save-prefix')
+var common = require("../common-tap.js")
+var test = require("tap").test
+var npm = require("../../")
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var pkg = path.join(__dirname, "install-save-prefix")
var mr = require("npm-registry-mock")
test("setup", function (t) {
mkdirp.sync(pkg)
- mkdirp.sync(path.resolve(pkg, 'node_modules'))
+ mkdirp.sync(path.resolve(pkg, "node_modules"))
process.chdir(pkg)
t.end()
})
-test('"npm install --save with default save-prefix should install local pkg versioned to allow minor updates', function(t) {
+test("npm install --save with default save-prefix should install local pkg versioned to allow minor updates", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- 'save-prefix': '^',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ "save-prefix": "^",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save', true)
- npm.commands.install(['underscore@latest'], function(err) {
+ npm.config.set("save", true)
+ npm.commands.install(["underscore@latest"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
t.deepEqual(pkgJson.dependencies, {
- 'underscore': '^1.5.1'
- }, 'Underscore dependency should specify ^1.5.1')
- npm.config.set('save', undefined)
+ "underscore": "^1.5.1"
+ }, "Underscore dependency should specify ^1.5.1")
+ npm.config.set("save", undefined)
s.close()
t.end()
})
@@ -41,25 +41,25 @@ test('"npm install --save with default save-prefix should install local pkg vers
})
})
-test('"npm install --save-dev with default save-prefix should install local pkg to dev dependencies versioned to allow minor updates', function(t) {
+test("npm install --save-dev with default save-prefix should install local pkg to dev dependencies versioned to allow minor updates", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- 'save-prefix': '^',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ "save-prefix": "^",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save-dev', true)
- npm.commands.install(['underscore@1.3.1'], function(err) {
+ npm.config.set("save-dev", true)
+ npm.commands.install(["underscore@1.3.1"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
t.deepEqual(pkgJson.devDependencies, {
- 'underscore': '^1.3.1'
- }, 'Underscore devDependency should specify ^1.3.1')
- npm.config.set('save-dev', undefined)
+ "underscore": "^1.3.1"
+ }, "Underscore devDependency should specify ^1.3.1")
+ npm.config.set("save-dev", undefined)
s.close()
t.end()
})
@@ -67,26 +67,26 @@ test('"npm install --save-dev with default save-prefix should install local pkg
})
})
-test('"npm install --save with "~" save-prefix should install local pkg versioned to allow patch updates', function(t) {
+test("npm install --save with \"~\" save-prefix should install local pkg versioned to allow patch updates", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save', true)
- npm.config.set('save-prefix', '~')
- npm.commands.install(['underscore@1.3.1'], function(err) {
+ npm.config.set("save", true)
+ npm.config.set("save-prefix", "~")
+ npm.commands.install(["underscore@1.3.1"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
t.deepEqual(pkgJson.dependencies, {
- 'underscore': '~1.3.1'
- }, 'Underscore dependency should specify ~1.3.1')
- npm.config.set('save', undefined)
- npm.config.set('save-prefix', undefined)
+ "underscore": "~1.3.1"
+ }, "Underscore dependency should specify ~1.3.1")
+ npm.config.set("save", undefined)
+ npm.config.set("save-prefix", undefined)
s.close()
t.end()
})
@@ -94,26 +94,26 @@ test('"npm install --save with "~" save-prefix should install local pkg versione
})
})
-test('"npm install --save-dev with "~" save-prefix should install local pkg to dev dependencies versioned to allow patch updates', function(t) {
+test("npm install --save-dev with \"~\" save-prefix should install local pkg to dev dependencies versioned to allow patch updates", function (t) {
resetPackageJSON(pkg)
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
- registry: common.registry }, function(err) {
+ loglevel: "silent",
+ registry: common.registry }, function (err) {
t.ifError(err)
- npm.config.set('save-dev', true)
- npm.config.set('save-prefix', '~')
- npm.commands.install(['underscore@1.3.1'], function(err) {
+ npm.config.set("save-dev", true)
+ npm.config.set("save-prefix", "~")
+ npm.commands.install(["underscore@1.3.1"], function (err) {
t.ifError(err)
- var p = path.resolve(pkg, 'node_modules/underscore/package.json')
+ var p = path.resolve(pkg, "node_modules/underscore/package.json")
t.ok(JSON.parse(fs.readFileSync(p)))
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
t.deepEqual(pkgJson.devDependencies, {
- 'underscore': '~1.3.1'
- }, 'Underscore devDependency should specify ~1.3.1')
- npm.config.set('save-dev', undefined)
- npm.config.set('save-prefix', undefined)
+ "underscore": "~1.3.1"
+ }, "Underscore devDependency should specify ~1.3.1")
+ npm.config.set("save-dev", undefined)
+ npm.config.set("save-prefix", undefined)
s.close()
t.end()
})
@@ -121,21 +121,19 @@ test('"npm install --save-dev with "~" save-prefix should install local pkg to d
})
})
-test('cleanup', function(t) {
+test("cleanup", function (t) {
process.chdir(__dirname)
- rimraf.sync(path.resolve(pkg, 'node_modules'))
- rimraf.sync(path.resolve(pkg, 'cache'))
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ rimraf.sync(path.resolve(pkg, "cache"))
resetPackageJSON(pkg)
t.end()
})
function resetPackageJSON(pkg) {
- var pkgJson = JSON.parse(fs.readFileSync(pkg + '/package.json', 'utf8'))
+ var pkgJson = JSON.parse(fs.readFileSync(pkg + "/package.json", "utf8"))
delete pkgJson.dependencies
delete pkgJson.devDependencies
delete pkgJson.optionalDependencies
var json = JSON.stringify(pkgJson, null, 2) + "\n"
- fs.writeFileSync(pkg + '/package.json', json, "ascii")
+ fs.writeFileSync(pkg + "/package.json", json, "ascii")
}
-
-
diff --git a/deps/npm/test/tap/install-scoped-already-installed.js b/deps/npm/test/tap/install-scoped-already-installed.js
new file mode 100644
index 0000000000..a355a4a50b
--- /dev/null
+++ b/deps/npm/test/tap/install-scoped-already-installed.js
@@ -0,0 +1,86 @@
+var common = require("../common-tap")
+var existsSync = require("fs").existsSync
+var join = require("path").join
+
+var test = require("tap").test
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+
+var pkg = join(__dirname, "install-from-local", "package-with-scoped-paths")
+var modules = join(pkg, "node_modules")
+
+var EXEC_OPTS = {
+ cwd : pkg
+}
+
+test("setup", function (t) {
+ rimraf.sync(modules)
+ rimraf.sync(join(pkg, "cache"))
+ process.chdir(pkg)
+ mkdirp.sync(modules)
+ t.end()
+})
+
+test("installing already installed local scoped package", function (t) {
+ common.npm(["install", "--loglevel", "silent"], EXEC_OPTS, function (err, code, stdout) {
+ var installed = parseNpmInstallOutput(stdout)
+ t.ifError(err, "error should not exist")
+ t.notOk(code, "npm install exited with code 0")
+ t.ifError(err, "install ran to completion without error")
+ t.ok(
+ existsSync(join(modules, "@scoped", "package", "package.json")),
+ "package installed"
+ )
+ t.ok(
+ contains(installed, "node_modules/@scoped/package"),
+ "installed @scoped/package"
+ )
+ t.ok(
+ contains(installed, "node_modules/package-local-dependency"),
+ "installed package-local-dependency"
+ )
+
+ common.npm(["install", "--loglevel", "silent"], EXEC_OPTS, function (err, code, stdout) {
+ installed = parseNpmInstallOutput(stdout)
+ t.ifError(err, "error should not exist")
+ t.notOk(code, "npm install exited with code 0")
+
+ t.ifError(err, "install ran to completion without error")
+
+ t.ok(
+ existsSync(join(modules, "@scoped", "package", "package.json")),
+ "package installed"
+ )
+
+ t.notOk(
+ contains(installed, "node_modules/@scoped/package"),
+ "did not reinstall @scoped/package"
+ )
+ t.notOk(
+ contains(installed, "node_modules/package-local-dependency"),
+ "did not reinstall package-local-dependency"
+ )
+ t.end()
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ process.chdir(__dirname)
+ rimraf.sync(join(modules))
+ rimraf.sync(join(pkg, "cache"))
+ t.end()
+})
+
+function contains(list, element) {
+ for (var i=0; i < list.length; ++i) {
+ if (list[i] === element) {
+ return true
+ }
+ }
+ return false
+}
+
+function parseNpmInstallOutput(stdout) {
+ return stdout.trim().split(/\n\n|\s+/)
+}
diff --git a/deps/npm/test/tap/install-scoped-link.js b/deps/npm/test/tap/install-scoped-link.js
index c411b664d7..b1e6ca0b22 100644
--- a/deps/npm/test/tap/install-scoped-link.js
+++ b/deps/npm/test/tap/install-scoped-link.js
@@ -1,18 +1,18 @@
-var exec = require("child_process").exec
+var common = require("../common-tap.js")
var existsSync = require("fs").existsSync
var join = require("path").join
-// var resolve = require("path").resolve
+var exec = require("child_process").exec
var test = require("tap").test
var rimraf = require("rimraf")
var mkdirp = require("mkdirp")
-var npm = require("../../")
-
var pkg = join(__dirname, "install-scoped")
var work = join(__dirname, "install-scoped-TEST")
var modules = join(work, "node_modules")
+var EXEC_OPTS = {}
+
test("setup", function (t) {
mkdirp.sync(modules)
process.chdir(work)
@@ -21,31 +21,30 @@ test("setup", function (t) {
})
test("installing package with links", function (t) {
- npm.load(function() {
- npm.commands.install([pkg], function (err) {
- t.ifError(err, "install ran to completion without error")
-
- t.ok(
- existsSync(join(modules, "@scoped", "package", "package.json")),
- "package installed"
- )
- t.ok(existsSync(join(modules, ".bin")), "binary link directory exists")
-
- var hello = join(modules, ".bin", "hello")
- t.ok(existsSync(hello), "binary link exists")
-
- exec("node " + hello, function (err, stdout, stderr) {
- t.ifError(err, "command ran fine")
- t.notOk(stderr, "got no error output back")
- t.equal(stdout, "hello blrbld\n", "output was as expected")
-
- t.end()
- })
+ common.npm(["install", pkg], EXEC_OPTS, function (err, code) {
+ t.ifError(err, "install ran to completion without error")
+ t.notOk(code, "npm install exited with code 0")
+
+ t.ok(
+ existsSync(join(modules, "@scoped", "package", "package.json")),
+ "package installed"
+ )
+ t.ok(existsSync(join(modules, ".bin")), "binary link directory exists")
+
+ var hello = join(modules, ".bin", "hello")
+ t.ok(existsSync(hello), "binary link exists")
+
+ exec("node " + hello, function (err, stdout, stderr) {
+ t.ifError(err, "command ran fine")
+ t.notOk(stderr, "got no error output back")
+ t.equal(stdout, "hello blrbld\n", "output was as expected")
+
+ t.end()
})
})
})
-test("cleanup", function(t) {
+test("cleanup", function (t) {
process.chdir(__dirname)
rimraf.sync(work)
t.end()
diff --git a/deps/npm/test/tap/install-with-dev-dep-duplicate.js b/deps/npm/test/tap/install-with-dev-dep-duplicate.js
new file mode 100644
index 0000000000..d0f86aa77a
--- /dev/null
+++ b/deps/npm/test/tap/install-with-dev-dep-duplicate.js
@@ -0,0 +1,57 @@
+var npm = npm = require("../../")
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var osenv = require("osenv")
+var rimraf = require("rimraf")
+var mr = require("npm-registry-mock")
+var common = require("../common-tap.js")
+
+var pkg = path.resolve(__dirname, "dev-dep-duplicate")
+var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json")
+
+test("prefers version from dependencies over devDependencies", function (t) {
+ t.plan(1)
+
+ mr(common.port, function (s) {
+ setup(function (err) {
+ if (err) return t.fail(err)
+
+ npm.install(".", function (err) {
+ if (err) return t.fail(err)
+
+ npm.commands.ls([], true, function (err, _, results) {
+ if (err) return t.fail(err)
+
+ fs.readFile(desiredResultsPath, function (err, desired) {
+ if (err) return t.fail(err)
+
+ t.deepEqual(results, JSON.parse(desired))
+ s.close()
+ t.end()
+ })
+ })
+ })
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
+})
+
+
+function setup (cb) {
+ cleanup()
+ process.chdir(pkg)
+
+ var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry}
+ npm.load(opts, cb)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ rimraf.sync(path.resolve(pkg, "cache"))
+}
diff --git a/deps/npm/test/tap/invalid-cmd-exit-code.js b/deps/npm/test/tap/invalid-cmd-exit-code.js
index 14db8669e9..c9918e5a79 100644
--- a/deps/npm/test/tap/invalid-cmd-exit-code.js
+++ b/deps/npm/test/tap/invalid-cmd-exit-code.js
@@ -1,10 +1,9 @@
var test = require("tap").test
-var node = process.execPath
var common = require("../common-tap.js")
var opts = { cwd: process.cwd() }
-test("npm asdf should return exit code 1", function(t) {
+test("npm asdf should return exit code 1", function (t) {
common.npm(["asdf"], opts, function (er, c) {
if (er) throw er
t.ok(c, "exit code should not be zero")
@@ -12,7 +11,7 @@ test("npm asdf should return exit code 1", function(t) {
})
})
-test("npm help should return exit code 0", function(t) {
+test("npm help should return exit code 0", function (t) {
common.npm(["help"], opts, function (er, c) {
if (er) throw er
t.equal(c, 0, "exit code should be 0")
@@ -20,7 +19,7 @@ test("npm help should return exit code 0", function(t) {
})
})
-test("npm help fadf should return exit code 0", function(t) {
+test("npm help fadf should return exit code 0", function (t) {
common.npm(["help", "fadf"], opts, function (er, c) {
if (er) throw er
t.equal(c, 0, "exit code should be 0")
diff --git a/deps/npm/test/tap/lifecycle-path.js b/deps/npm/test/tap/lifecycle-path.js
index 34684a0c39..cf4bbdc99c 100644
--- a/deps/npm/test/tap/lifecycle-path.js
+++ b/deps/npm/test/tap/lifecycle-path.js
@@ -2,7 +2,6 @@ var test = require("tap").test
var common = require("../common-tap.js")
var path = require("path")
var rimraf = require("rimraf")
-var mkdirp = require("mkdirp")
var pkg = path.resolve(__dirname, "lifecycle-path")
var fs = require("fs")
var link = path.resolve(pkg, "node-bin")
@@ -28,7 +27,7 @@ test("make sure the path is correct", function (t) {
PATH: PATH,
stdio: [ 0, "pipe", 2 ]
}
- }, function (er, code, stdout, stderr) {
+ }, function (er, code, stdout) {
if (er) throw er
t.equal(code, 0, "exit code")
// remove the banner, we just care about the last line
@@ -58,4 +57,3 @@ test("clean", function (t) {
rimraf.sync(link)
t.end()
})
-
diff --git a/deps/npm/test/tap/lifecycle.js b/deps/npm/test/tap/lifecycle.js
index 288329c244..aa0efc5266 100644
--- a/deps/npm/test/tap/lifecycle.js
+++ b/deps/npm/test/tap/lifecycle.js
@@ -1,12 +1,12 @@
var test = require("tap").test
-var npm = require('../../')
-var lifecycle = require('../../lib/utils/lifecycle')
+var npm = require("../../")
+var lifecycle = require("../../lib/utils/lifecycle")
test("lifecycle: make env correctly", function (t) {
- npm.load({enteente: Infinity}, function() {
+ npm.load({enteente: Infinity}, function () {
var env = lifecycle.makeEnv({}, null, process.env)
- t.equal('Infinity', env.npm_config_enteente)
+ t.equal("Infinity", env.npm_config_enteente)
t.end()
})
})
diff --git a/deps/npm/test/tap/locker.js b/deps/npm/test/tap/locker.js
new file mode 100644
index 0000000000..bc43c30e95
--- /dev/null
+++ b/deps/npm/test/tap/locker.js
@@ -0,0 +1,89 @@
+var test = require("tap").test
+ , path = require("path")
+ , fs = require("graceful-fs")
+ , crypto = require("crypto")
+ , rimraf = require("rimraf")
+ , osenv = require("osenv")
+ , mkdirp = require("mkdirp")
+ , npm = require("../../")
+ , locker = require("../../lib/utils/locker.js")
+ , lock = locker.lock
+ , unlock = locker.unlock
+
+var pkg = path.join(__dirname, "/locker")
+ , cache = path.join(pkg, "/cache")
+ , tmp = path.join(pkg, "/tmp")
+ , nm = path.join(pkg, "/node_modules")
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}
+
+test("setup", function (t) {
+ cleanup()
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
+ t.end()
+})
+
+test("locking file puts lock in correct place", function (t) {
+ npm.load({cache: cache, tmpdir: tmp}, function (er) {
+ t.ifError(er, "npm bootstrapped OK")
+
+ var n = "correct"
+ , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
+ , p = path.resolve(nm, n)
+ , h = crypto.createHash("sha1").update(p).digest("hex")
+ , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock"
+ , v = path.join(cache, "_locks", l)
+
+ lock(nm, n, function (er) {
+ t.ifError(er, "locked path")
+
+ fs.exists(v, function (found) {
+ t.ok(found, "lock found OK")
+
+ unlock(nm, n, function (er) {
+ t.ifError(er, "unlocked path")
+
+ fs.exists(v, function (found) {
+ t.notOk(found, "lock deleted OK")
+ t.end()
+ })
+ })
+ })
+ })
+ })
+})
+
+test("unlocking out of order errors out", function (t) {
+ npm.load({cache: cache, tmpdir: tmp}, function (er) {
+ t.ifError(er, "npm bootstrapped OK")
+
+ var n = "busted"
+ , c = n.replace(/[^a-zA-Z0-9]+/g, "-").replace(/^-+|-+$/g, "")
+ , p = path.resolve(nm, n)
+ , h = crypto.createHash("sha1").update(p).digest("hex")
+ , l = c.substr(0, 24)+"-"+h.substr(0, 16)+".lock"
+ , v = path.join(cache, "_locks", l)
+
+ fs.exists(v, function (found) {
+ t.notOk(found, "no lock to unlock")
+
+ t.throws(function () {
+ unlock(nm, n, function () {
+ t.fail("shouldn't get here")
+ t.end()
+ })
+ }, "blew up as expected")
+
+ t.end()
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
+})
diff --git a/deps/npm/test/tap/login-always-auth.js b/deps/npm/test/tap/login-always-auth.js
new file mode 100644
index 0000000000..8311096c2e
--- /dev/null
+++ b/deps/npm/test/tap/login-always-auth.js
@@ -0,0 +1,142 @@
+var fs = require("fs")
+var path = require("path")
+var rimraf = require("rimraf")
+var mr = require("npm-registry-mock")
+
+var test = require("tap").test
+var common = require("../common-tap.js")
+
+var opts = {cwd : __dirname}
+var outfile = path.resolve(__dirname, "_npmrc")
+var responses = {
+ "Username" : "u\n",
+ "Password" : "p\n",
+ "Email" : "u@p.me\n"
+}
+
+function mocks(server) {
+ server.filteringRequestBody(function (r) {
+ if (r.match(/\"_id\":\"org\.couchdb\.user:u\"/)) {
+ return "auth"
+ }
+ })
+ server.put("/-/user/org.couchdb.user:u", "auth")
+ .reply(201, {username : "u", password : "p", email : "u@p.me"})
+}
+
+test("npm login", function (t) {
+ mr({port : common.port, mocks : mocks}, function (s) {
+ var runner = common.npm(
+ [
+ "login",
+ "--registry", common.registry,
+ "--loglevel", "silent",
+ "--userconfig", outfile
+ ],
+ opts,
+ function (err, code) {
+ t.notOk(code, "exited OK")
+ t.notOk(err, "no error output")
+ var config = fs.readFileSync(outfile, "utf8")
+ t.like(config, /:always-auth=false/, "always-auth is scoped and false (by default)")
+ s.close()
+ rimraf(outfile, function (err) {
+ t.ifError(err, "removed config file OK")
+ t.end()
+ })
+ })
+
+ var o = "", e = "", remaining = Object.keys(responses).length
+ runner.stdout.on("data", function (chunk) {
+ remaining--
+ o += chunk
+
+ var label = chunk.toString("utf8").split(":")[0]
+ runner.stdin.write(responses[label])
+
+ if (remaining === 0) runner.stdin.end()
+ })
+ runner.stderr.on("data", function (chunk) { e += chunk })
+ })
+})
+
+test("npm login --always-auth", function (t) {
+ mr({port : common.port, mocks : mocks}, function (s) {
+ var runner = common.npm(
+ [
+ "login",
+ "--registry", common.registry,
+ "--loglevel", "silent",
+ "--userconfig", outfile,
+ "--always-auth"
+ ],
+ opts,
+ function (err, code) {
+ t.notOk(code, "exited OK")
+ t.notOk(err, "no error output")
+ var config = fs.readFileSync(outfile, "utf8")
+ t.like(config, /:always-auth=true/, "always-auth is scoped and true")
+ s.close()
+ rimraf(outfile, function (err) {
+ t.ifError(err, "removed config file OK")
+ t.end()
+ })
+ })
+
+ var o = "", e = "", remaining = Object.keys(responses).length
+ runner.stdout.on("data", function (chunk) {
+ remaining--
+ o += chunk
+
+ var label = chunk.toString("utf8").split(":")[0]
+ runner.stdin.write(responses[label])
+
+ if (remaining === 0) runner.stdin.end()
+ })
+ runner.stderr.on("data", function (chunk) { e += chunk })
+ })
+})
+
+test("npm login --no-always-auth", function (t) {
+ mr({port : common.port, mocks : mocks}, function (s) {
+ var runner = common.npm(
+ [
+ "login",
+ "--registry", common.registry,
+ "--loglevel", "silent",
+ "--userconfig", outfile,
+ "--no-always-auth"
+ ],
+ opts,
+ function (err, code) {
+ t.notOk(code, "exited OK")
+ t.notOk(err, "no error output")
+ var config = fs.readFileSync(outfile, "utf8")
+ t.like(config, /:always-auth=false/, "always-auth is scoped and false")
+ s.close()
+ rimraf(outfile, function (err) {
+ t.ifError(err, "removed config file OK")
+ t.end()
+ })
+ })
+
+ var o = "", e = "", remaining = Object.keys(responses).length
+ runner.stdout.on("data", function (chunk) {
+ remaining--
+ o += chunk
+
+ var label = chunk.toString("utf8").split(":")[0]
+ runner.stdin.write(responses[label])
+
+ if (remaining === 0) runner.stdin.end()
+ })
+ runner.stderr.on("data", function (chunk) { e += chunk })
+ })
+})
+
+
+test("cleanup", function (t) {
+ rimraf.sync(outfile)
+ t.pass("cleaned up")
+ t.end()
+})
diff --git a/deps/npm/test/tap/ls-depth-cli.js b/deps/npm/test/tap/ls-depth-cli.js
index fcbc4364fa..89c4cc3547 100644
--- a/deps/npm/test/tap/ls-depth-cli.js
+++ b/deps/npm/test/tap/ls-depth-cli.js
@@ -1,31 +1,27 @@
-var common = require('../common-tap')
- , test = require('tap').test
- , path = require('path')
- , rimraf = require('rimraf')
- , osenv = require('osenv')
- , mkdirp = require('mkdirp')
- , pkg = __dirname + '/ls-depth'
- , cache = pkg + '/cache'
- , tmp = pkg + '/tmp'
- , node = process.execPath
- , npm = path.resolve(__dirname, '../../cli.js')
- , mr = require('npm-registry-mock')
+var common = require("../common-tap")
+ , test = require("tap").test
+ , path = require("path")
+ , rimraf = require("rimraf")
+ , osenv = require("osenv")
+ , mkdirp = require("mkdirp")
+ , pkg = path.resolve(__dirname, "ls-depth")
+ , mr = require("npm-registry-mock")
, opts = {cwd: pkg}
function cleanup () {
process.chdir(osenv.tmpdir())
- rimraf.sync(pkg + '/cache')
- rimraf.sync(pkg + '/tmp')
- rimraf.sync(pkg + '/node_modules')
+ rimraf.sync(pkg + "/cache")
+ rimraf.sync(pkg + "/tmp")
+ rimraf.sync(pkg + "/node_modules")
}
-test('setup', function (t) {
+test("setup", function (t) {
cleanup()
- mkdirp.sync(pkg + '/cache')
- mkdirp.sync(pkg + '/tmp')
+ mkdirp.sync(pkg + "/cache")
+ mkdirp.sync(pkg + "/tmp")
mr(common.port, function (s) {
- var cmd = ['install', '--registry=' + common.registry]
+ var cmd = ["install", "--registry=" + common.registry]
common.npm(cmd, opts, function (er, c) {
if (er) throw er
t.equal(c, 0)
@@ -35,8 +31,8 @@ test('setup', function (t) {
})
})
-test('npm ls --depth=0', function (t) {
- common.npm(['ls', '--depth=0'], opts, function (er, c, out) {
+test("npm ls --depth=0", function (t) {
+ common.npm(["ls", "--depth=0"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 0)
t.has(out, /test-package-with-one-dep@0\.0\.0/
@@ -47,8 +43,8 @@ test('npm ls --depth=0', function (t) {
})
})
-test('npm ls --depth=1', function (t) {
- common.npm(['ls', '--depth=1'], opts, function (er, c, out) {
+test("npm ls --depth=1", function (t) {
+ common.npm(["ls", "--depth=1"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 0)
t.has(out, /test-package-with-one-dep@0\.0\.0/
@@ -59,10 +55,10 @@ test('npm ls --depth=1', function (t) {
})
})
-test('npm ls --depth=Infinity', function (t) {
+test("npm ls --depth=Infinity", function (t) {
// travis has a preconfigured depth=0, in general we can not depend
// on the default value in all environments, so explictly set it here
- common.npm(['ls', '--depth=Infinity'], opts, function (er, c, out) {
+ common.npm(["ls", "--depth=Infinity"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 0)
t.has(out, /test-package-with-one-dep@0\.0\.0/
@@ -73,7 +69,7 @@ test('npm ls --depth=Infinity', function (t) {
})
})
-test('cleanup', function (t) {
+test("cleanup", function (t) {
cleanup()
t.end()
})
diff --git a/deps/npm/test/tap/ls-depth-unmet.js b/deps/npm/test/tap/ls-depth-unmet.js
index 1ac85efc94..37a0cb5fea 100644
--- a/deps/npm/test/tap/ls-depth-unmet.js
+++ b/deps/npm/test/tap/ls-depth-unmet.js
@@ -1,31 +1,30 @@
-var common = require('../common-tap')
- , test = require('tap').test
- , path = require('path')
- , rimraf = require('rimraf')
- , osenv = require('osenv')
- , mkdirp = require('mkdirp')
- , pkg = __dirname + '/ls-depth-unmet'
- , cache = pkg + '/cache'
- , tmp = pkg + '/tmp'
- , node = process.execPath
- , npm = path.resolve(__dirname, '../../cli.js')
- , mr = require('npm-registry-mock')
+var common = require("../common-tap")
+ , test = require("tap").test
+ , path = require("path")
+ , rimraf = require("rimraf")
+ , osenv = require("osenv")
+ , mkdirp = require("mkdirp")
+ , pkg = path.resolve(__dirname, "ls-depth-unmet")
+ , mr = require("npm-registry-mock")
, opts = {cwd: pkg}
+ , cache = path.resolve(pkg, "cache")
+ , tmp = path.resolve(pkg, "tmp")
+ , nodeModules = path.resolve(pkg, "node_modules")
function cleanup () {
process.chdir(osenv.tmpdir())
- rimraf.sync(pkg + '/cache')
- rimraf.sync(pkg + '/tmp')
- rimraf.sync(pkg + '/node_modules')
+ rimraf.sync(cache)
+ rimraf.sync(tmp)
+ rimraf.sync(nodeModules)
}
-test('setup', function (t) {
+test("setup", function (t) {
cleanup()
- mkdirp.sync(pkg + '/cache')
- mkdirp.sync(pkg + '/tmp')
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
mr(common.port, function (s) {
- var cmd = ['install', 'underscore@1.3.1', 'mkdirp', 'test-package-with-one-dep', '--registry=' + common.registry]
+ var cmd = ["install", "underscore@1.3.1", "mkdirp", "test-package-with-one-dep", "--registry=" + common.registry]
common.npm(cmd, opts, function (er, c) {
if (er) throw er
t.equal(c, 0)
@@ -35,8 +34,8 @@ test('setup', function (t) {
})
})
-test('npm ls --depth=0', function (t) {
- common.npm(['ls', '--depth=0'], opts, function (er, c, out) {
+test("npm ls --depth=0", function (t) {
+ common.npm(["ls", "--depth=0"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 1)
t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
@@ -53,8 +52,8 @@ test('npm ls --depth=0', function (t) {
})
})
-test('npm ls --depth=1', function (t) {
- common.npm(['ls', '--depth=1'], opts, function (er, c, out) {
+test("npm ls --depth=1", function (t) {
+ common.npm(["ls", "--depth=1"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 1)
t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
@@ -71,10 +70,10 @@ test('npm ls --depth=1', function (t) {
})
})
-test('npm ls --depth=Infinity', function (t) {
+test("npm ls --depth=Infinity", function (t) {
// travis has a preconfigured depth=0, in general we can not depend
// on the default value in all environments, so explictly set it here
- common.npm(['ls', '--depth=Infinity'], opts, function (er, c, out) {
+ common.npm(["ls", "--depth=Infinity"], opts, function (er, c, out) {
if (er) throw er
t.equal(c, 1)
t.has(out, /UNMET DEPENDENCY optimist@0\.6\.0/
@@ -91,7 +90,7 @@ test('npm ls --depth=Infinity', function (t) {
})
})
-test('cleanup', function (t) {
+test("cleanup", function (t) {
cleanup()
t.end()
})
diff --git a/deps/npm/test/tap/ls-no-results.js b/deps/npm/test/tap/ls-no-results.js
index 9792774c69..10f3ce0014 100644
--- a/deps/npm/test/tap/ls-no-results.js
+++ b/deps/npm/test/tap/ls-no-results.js
@@ -1,11 +1,11 @@
-var test = require('tap').test
-var spawn = require('child_process').spawn
+var test = require("tap").test
+var spawn = require("child_process").spawn
var node = process.execPath
-var npm = require.resolve('../../')
-var args = [ npm, 'ls', 'ceci n’est pas une package' ]
-test('ls exits non-zero when nothing found', function (t) {
+var npm = require.resolve("../../")
+var args = [ npm, "ls", "ceci n’est pas une package" ]
+test("ls exits non-zero when nothing found", function (t) {
var child = spawn(node, args)
- child.on('exit', function (code) {
+ child.on("exit", function (code) {
t.notEqual(code, 0)
t.end()
})
diff --git a/deps/npm/test/tap/noargs-install-config-save.js b/deps/npm/test/tap/noargs-install-config-save.js
index c821000c2f..328da7d17b 100644
--- a/deps/npm/test/tap/noargs-install-config-save.js
+++ b/deps/npm/test/tap/noargs-install-config-save.js
@@ -11,8 +11,8 @@ var mr = require("npm-registry-mock")
var spawn = require("child_process").spawn
var node = process.execPath
-var pkg = process.env.npm_config_tmp || "/tmp"
-pkg += path.sep + "noargs-install-config-save"
+var pkg = path.resolve(process.env.npm_config_tmp || "/tmp",
+ "noargs-install-config-save")
function writePackageJson() {
rimraf.sync(pkg)
@@ -26,14 +26,14 @@ function writePackageJson() {
"devDependencies": {
"underscore": "1.3.1"
}
- }), 'utf8')
+ }), "utf8")
}
function createChild (args) {
var env = {
- npm_config_save: true,
- npm_config_registry: common.registry,
- npm_config_cache: pkg + "/cache",
+ "npm_config_save": true,
+ "npm_config_registry": common.registry,
+ "npm_config_cache": pkg + "/cache",
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH
@@ -56,7 +56,7 @@ test("does not update the package.json with empty arguments", function (t) {
var child = createChild([npm, "install"])
child.on("close", function () {
var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.ok(text.indexOf('"dependencies') === -1)
+ t.ok(text.indexOf("\"dependencies") === -1)
s.close()
t.end()
})
@@ -71,7 +71,7 @@ test("updates the package.json (adds dependencies) with an argument", function (
var child = createChild([npm, "install", "underscore"])
child.on("close", function () {
var text = JSON.stringify(fs.readFileSync(pkg + "/package.json", "utf8"))
- t.ok(text.indexOf('"dependencies') !== -1)
+ t.ok(text.indexOf("\"dependencies") !== -1)
s.close()
t.end()
})
diff --git a/deps/npm/test/tap/npm-api-not-loaded-error.js b/deps/npm/test/tap/npm-api-not-loaded-error.js
index 3fd0731103..afedfbcd07 100644
--- a/deps/npm/test/tap/npm-api-not-loaded-error.js
+++ b/deps/npm/test/tap/npm-api-not-loaded-error.js
@@ -21,7 +21,7 @@ test("calling set/get on config pre-load should throw", function (t) {
t.ok(threw, "get before load should throw")
}
- var threw = true
+ threw = true
try {
npm.config.set("foo", "bar")
threw = false
diff --git a/deps/npm/test/tap/optional-metadep-rollback-collision.js b/deps/npm/test/tap/optional-metadep-rollback-collision.js
index 29db793bc4..f8645840bd 100644
--- a/deps/npm/test/tap/optional-metadep-rollback-collision.js
+++ b/deps/npm/test/tap/optional-metadep-rollback-collision.js
@@ -25,7 +25,7 @@ test("go go test racer", function (t) {
stdio: [ 0, "pipe", 2 ]
}, function (er, code, sout) {
if (er) throw er
- t.equal(code, 0)
+ t.notOk(code, "npm install exited with code 0")
t.equal(sout, "ok\nok\n")
t.notOk(/not ok/.test(sout), "should not contain the string 'not ok'")
t.end()
diff --git a/deps/npm/test/tap/outdated-color.js b/deps/npm/test/tap/outdated-color.js
index f20bcea93c..4e90277fe2 100644
--- a/deps/npm/test/tap/outdated-color.js
+++ b/deps/npm/test/tap/outdated-color.js
@@ -1,15 +1,17 @@
var common = require("../common-tap.js")
var test = require("tap").test
-var npm = require("../../")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
-var exec = require('child_process').exec
-var mr = require("npm-registry-mock")
+var path = require("path")
+
+var pkg = path.resolve(__dirname, "outdated")
+var cache = path.resolve(pkg, "cache")
+mkdirp.sync(cache)
-var pkg = __dirname + '/outdated'
-var NPM_BIN = __dirname + '/../../bin/npm-cli.js'
-mkdirp.sync(pkg + "/cache")
+var EXEC_OPTS = {
+ cwd: pkg
+}
function hasControlCodes(str) {
return str.length !== ansiTrim(str).length
@@ -17,20 +19,26 @@ function hasControlCodes(str) {
function ansiTrim (str) {
var r = new RegExp("\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|" +
- "\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)", "g");
+ "\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)", "g")
return str.replace(r, "")
}
// note hard to automate tests for color = true
// as npm kills the color config when it detects
-// it's not running in a tty
+// it"s not running in a tty
test("does not use ansi styling", function (t) {
- t.plan(3)
+ t.plan(4)
mr(common.port, function (s) { // create mock registry.
- exec('node ' + NPM_BIN + ' outdated --registry ' + common.registry + ' --color false underscore', {
- cwd: pkg
- }, function(err, stdout) {
+ common.npm(
+ [
+ "outdated",
+ "--registry", common.registry,
+ "underscore"
+ ],
+ EXEC_OPTS,
+ function (err, code, stdout) {
t.ifError(err)
+ t.notOk(code, "npm outdated exited with code 0")
t.ok(stdout, stdout.length)
t.ok(!hasControlCodes(stdout))
s.close()
@@ -39,6 +47,6 @@ test("does not use ansi styling", function (t) {
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/outdated-depth.js b/deps/npm/test/tap/outdated-depth.js
index 7ccc0c6254..112f363aa5 100644
--- a/deps/npm/test/tap/outdated-depth.js
+++ b/deps/npm/test/tap/outdated-depth.js
@@ -1,37 +1,39 @@
-var common = require('../common-tap')
- , path = require('path')
- , test = require('tap').test
- , rimraf = require('rimraf')
- , npm = require('../../')
- , mr = require('npm-registry-mock')
- , pkg = path.resolve(__dirname, 'outdated-depth')
+var common = require("../common-tap")
+ , path = require("path")
+ , test = require("tap").test
+ , rimraf = require("rimraf")
+ , npm = require("../../")
+ , mr = require("npm-registry-mock")
+ , pkg = path.resolve(__dirname, "outdated-depth")
+ , cache = path.resolve(pkg, "cache")
+ , nodeModules = path.resolve(pkg, "node_modules")
function cleanup () {
- rimraf.sync(pkg + '/node_modules')
- rimraf.sync(pkg + '/cache')
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
}
-test('outdated depth zero', function (t) {
+test("outdated depth zero", function (t) {
var expected = [
pkg,
- 'underscore',
- '1.3.1',
- '1.3.1',
- '1.5.1',
- '1.3.1'
+ "underscore",
+ "1.3.1",
+ "1.3.1",
+ "1.5.1",
+ "1.3.1"
]
process.chdir(pkg)
mr(common.port, function (s) {
npm.load({
- cache: pkg + '/cache'
- , loglevel: 'silent'
+ cache: cache
+ , loglevel: "silent"
, registry: common.registry
, depth: 0
}
, function () {
- npm.install('.', function (er) {
+ npm.install(".", function (er) {
if (er) throw new Error(er)
npm.outdated(function (err, d) {
if (err) throw new Error(err)
diff --git a/deps/npm/test/tap/outdated-git.js b/deps/npm/test/tap/outdated-git.js
index 11c2040227..cc89ff19d9 100644
--- a/deps/npm/test/tap/outdated-git.js
+++ b/deps/npm/test/tap/outdated-git.js
@@ -3,28 +3,29 @@ var test = require("tap").test
var npm = require("../../")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
-var mr = require("npm-registry-mock")
+var path = require("path")
// config
-var pkg = __dirname + "/outdated-git"
-mkdirp.sync(pkg + "/cache")
+var pkg = path.resolve(__dirname, "outdated-git")
+var cache = path.resolve(pkg, "cache")
+mkdirp.sync(cache)
test("dicovers new versions in outdated", function (t) {
process.chdir(pkg)
t.plan(5)
- npm.load({cache: pkg + "/cache", registry: common.registry}, function () {
+ npm.load({cache: cache, registry: common.registry}, function () {
npm.commands.outdated([], function (er, d) {
- t.equal('git', d[0][3])
- t.equal('git', d[0][4])
- t.equal('git://github.com/robertkowalski/foo-private.git', d[0][5])
- t.equal('git://user:pass@github.com/robertkowalski/foo-private.git', d[1][5])
- t.equal('git+https://github.com/robertkowalski/foo', d[2][5])
+ t.equal("git", d[0][3])
+ t.equal("git", d[0][4])
+ t.equal("git://github.com/robertkowalski/foo-private.git", d[0][5])
+ t.equal("git://user:pass@github.com/robertkowalski/foo-private.git", d[1][5])
+ t.equal("git+https://github.com/robertkowalski/foo", d[2][5])
})
})
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/outdated-include-devdependencies.js b/deps/npm/test/tap/outdated-include-devdependencies.js
index b78948a24e..bdb656ff18 100644
--- a/deps/npm/test/tap/outdated-include-devdependencies.js
+++ b/deps/npm/test/tap/outdated-include-devdependencies.js
@@ -4,15 +4,17 @@ var npm = require("../../")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
+var path = require("path")
// config
-var pkg = __dirname + '/outdated-include-devdependencies'
-mkdirp.sync(pkg + "/cache")
+var pkg = path.resolve(__dirname, "outdated-include-devdependencies")
+var cache = path.resolve(pkg, "cache")
+mkdirp.sync(cache)
test("includes devDependencies in outdated", function (t) {
process.chdir(pkg)
mr(common.port, function (s) {
- npm.load({cache: pkg + "/cache", registry: common.registry}, function () {
+ npm.load({cache: cache, registry: common.registry}, function () {
npm.outdated(function (er, d) {
t.equal("1.5.1", d[0][3])
s.close()
@@ -23,6 +25,6 @@ test("includes devDependencies in outdated", function (t) {
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/outdated-json.js b/deps/npm/test/tap/outdated-json.js
index 7c19561ee3..b874f28e69 100644
--- a/deps/npm/test/tap/outdated-json.js
+++ b/deps/npm/test/tap/outdated-json.js
@@ -5,29 +5,29 @@ var common = require("../common-tap.js")
, mr = require("npm-registry-mock")
, path = require("path")
, osenv = require("osenv")
- , spawn = require('child_process').spawn
+ , spawn = require("child_process").spawn
, node = process.execPath
- , npmc = require.resolve('../../')
- , pkg = path.resolve(__dirname, 'outdated-new-versions')
+ , npmc = require.resolve("../../")
+ , pkg = path.resolve(__dirname, "outdated-new-versions")
, args = [ npmc
- , 'outdated'
- , '--json'
- , '--silent'
- , '--registry=' + common.registry
- , '--cache=' + pkg + '/cache'
+ , "outdated"
+ , "--json"
+ , "--silent"
+ , "--registry=" + common.registry
+ , "--cache=" + pkg + "/cache"
]
var expected = { underscore:
- { current: '1.3.3'
- , wanted: '1.3.3'
- , latest: '1.5.1'
- , location: 'node_modules' + path.sep + 'underscore'
+ { current: "1.3.3"
+ , wanted: "1.3.3"
+ , latest: "1.5.1"
+ , location: "node_modules" + path.sep + "underscore"
}
, request:
- { current: '0.9.5'
- , wanted: '0.9.5'
- , latest: '2.27.0'
- , location: 'node_modules' + path.sep + 'request'
+ { current: "0.9.5"
+ , wanted: "0.9.5"
+ , latest: "2.27.0"
+ , location: "node_modules" + path.sep + "request"
}
}
@@ -38,18 +38,19 @@ test("it should log json data", function (t) {
mr(common.port, function (s) {
npm.load({
cache: pkg + "/cache",
- loglevel: 'silent',
+ loglevel: "silent",
registry: common.registry }
, function () {
npm.install(".", function (err) {
+ t.ifError(err, "error should not exist")
var child = spawn(node, args)
- , out = ''
+ , out = ""
child.stdout
- .on('data', function (buf) {
+ .on("data", function (buf) {
out += buf.toString()
})
.pipe(process.stdout)
- child.on('exit', function () {
+ child.on("exit", function () {
out = JSON.parse(out)
t.deepEqual(out, expected)
s.close()
diff --git a/deps/npm/test/tap/outdated-new-versions.js b/deps/npm/test/tap/outdated-new-versions.js
index 1779736177..cb7eaa4733 100644
--- a/deps/npm/test/tap/outdated-new-versions.js
+++ b/deps/npm/test/tap/outdated-new-versions.js
@@ -3,11 +3,13 @@ var test = require("tap").test
var npm = require("../../")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
+var path = require("path")
var mr = require("npm-registry-mock")
-var pkg = __dirname + "/outdated-new-versions"
-mkdirp.sync(pkg + "/cache")
+var pkg = path.resolve(__dirname, "outdated-new-versions")
+var cache = path.resolve(pkg, "cache")
+mkdirp.sync(cache)
test("dicovers new versions in outdated", function (t) {
@@ -15,7 +17,7 @@ test("dicovers new versions in outdated", function (t) {
t.plan(2)
mr(common.port, function (s) {
- npm.load({cache: pkg + "/cache", registry: common.registry}, function () {
+ npm.load({cache: cache, registry: common.registry}, function () {
npm.outdated(function (er, d) {
for (var i = 0; i < d.length; i++) {
if (d[i][1] === "underscore")
@@ -31,6 +33,6 @@ test("dicovers new versions in outdated", function (t) {
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/outdated-notarget.js b/deps/npm/test/tap/outdated-notarget.js
index 782f6f7d59..f1032eab37 100644
--- a/deps/npm/test/tap/outdated-notarget.js
+++ b/deps/npm/test/tap/outdated-notarget.js
@@ -11,12 +11,12 @@ var pkg = path.resolve(__dirname, "outdated-notarget")
var cache = path.resolve(pkg, "cache")
var mr = require("npm-registry-mock")
-test("outdated-target: if no viable version is found, show error", function(t) {
+test("outdated-target: if no viable version is found, show error", function (t) {
t.plan(1)
setup()
- mr({port: common.port}, function(s) {
- npm.load({ cache: cache, registry: common.registry}, function() {
- npm.commands.update(function(er) {
+ mr({port: common.port}, function (s) {
+ npm.load({ cache: cache, registry: common.registry}, function () {
+ npm.commands.update(function (er) {
t.equal(er.code, "ETARGET")
s.close()
t.end()
@@ -25,7 +25,7 @@ test("outdated-target: if no viable version is found, show error", function(t) {
})
})
-test("cleanup", function(t) {
+test("cleanup", function (t) {
process.chdir(osenv.tmpdir())
rimraf.sync(pkg)
t.end()
diff --git a/deps/npm/test/tap/outdated.js b/deps/npm/test/tap/outdated.js
index dddec77ea2..9f4b14d1f3 100644
--- a/deps/npm/test/tap/outdated.js
+++ b/deps/npm/test/tap/outdated.js
@@ -1,14 +1,14 @@
var common = require("../common-tap.js")
-var fs = require("fs")
var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")
+var path = require("path")
var mr = require("npm-registry-mock")
// config
-var pkg = __dirname + '/outdated'
-
-var path = require("path")
+var pkg = path.resolve(__dirname, "outdated")
+var cache = path.resolve(pkg, "cache")
+var nodeModules = path.resolve(pkg, "node_modules")
test("it should not throw", function (t) {
cleanup()
@@ -33,13 +33,15 @@ test("it should not throw", function (t) {
}
mr(common.port, function (s) {
npm.load({
- cache: pkg + "/cache",
- loglevel: 'silent',
+ cache: "cache",
+ loglevel: "silent",
parseable: true,
registry: common.registry }
, function () {
npm.install(".", function (err) {
+ t.ifError(err, "install success")
npm.outdated(function (er, d) {
+ t.ifError(er, "outdated success")
console.log = originalLog
t.same(output, expOut)
t.same(d, expData)
@@ -57,6 +59,6 @@ test("cleanup", function (t) {
})
function cleanup () {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
}
diff --git a/deps/npm/test/tap/pack-scoped.js b/deps/npm/test/tap/pack-scoped.js
index 05a77a0f0f..5c351339cb 100644
--- a/deps/npm/test/tap/pack-scoped.js
+++ b/deps/npm/test/tap/pack-scoped.js
@@ -1,10 +1,10 @@
// verify that prepublish runs on pack and publish
var test = require("tap").test
+var common = require("../common-tap")
var fs = require("graceful-fs")
var join = require("path").join
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
-var path = require("path")
var pkg = join(__dirname, "scoped_package")
var manifest = join(pkg, "package.json")
@@ -19,6 +19,8 @@ var data = {
test("setup", function (t) {
var n = 0
+ rimraf.sync(pkg)
+
mkdirp(pkg, then())
mkdirp(cache, then())
mkdirp(tmp, then())
@@ -26,7 +28,7 @@ test("setup", function (t) {
function then () {
n++
return function (er) {
- if (er) throw er
+ t.ifError(er)
if (--n === 0) next()
}
}
@@ -36,7 +38,7 @@ test("setup", function (t) {
}
function done (er) {
- if (er) throw er
+ t.ifError(er)
t.pass("setup done")
t.end()
@@ -44,9 +46,6 @@ test("setup", function (t) {
})
test("test", function (t) {
- var spawn = require("child_process").spawn
- var node = process.execPath
- var npm = path.resolve(__dirname, "../../cli.js")
var env = {
"npm_config_cache" : cache,
"npm_config_tmp" : tmp,
@@ -58,34 +57,25 @@ test("test", function (t) {
if (!/^npm_config_/.test(i)) env[i] = process.env[i]
}
- var child = spawn(node, [npm, "pack"], {cwd : pkg, env : env})
-
- child.stdout.setEncoding("utf8")
- child.stderr.on("data", onerr)
- child.stdout.on("data", ondata)
- child.on("close", onend)
-
- var c = "", e = ""
- function ondata (chunk) { c += chunk }
- function onerr (chunk) { e += chunk }
-
- function onend () {
- if (e) {
- throw new Error("got stderr data: " + JSON.stringify("" + e))
- }
- c = c.trim()
+ common.npm([
+ "pack",
+ "--loglevel", "warn"
+ ], {
+ cwd: pkg,
+ env: env
+ }, function(err, code, stdout, stderr) {
+ t.ifErr(err, "npm pack finished without error")
+ t.equal(code, 0, "npm pack exited ok")
+ t.notOk(stderr, "got stderr data: " + JSON.stringify("" + stderr))
+ stdout = stdout.trim()
var regex = new RegExp("scope-generic-package-90000.100001.5.tgz", "ig")
-
- t.ok(c.match(regex), "found package")
+ t.ok(stdout.match(regex), "found package")
t.end()
- }
+ })
})
test("cleanup", function (t) {
- rimraf(pkg, function (er) {
- if (er) throw er
-
- t.pass("cleaned up")
- t.end()
- })
+ rimraf.sync(pkg)
+ t.pass("cleaned up")
+ t.end()
})
diff --git a/deps/npm/test/tap/peer-deps-invalid.js b/deps/npm/test/tap/peer-deps-invalid.js
index c287365501..098f3ccb18 100644
--- a/deps/npm/test/tap/peer-deps-invalid.js
+++ b/deps/npm/test/tap/peer-deps-invalid.js
@@ -1,18 +1,20 @@
-var common = require('../common-tap.js')
+var common = require("../common-tap")
var fs = require("fs")
var path = require("path")
var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")
var mr = require("npm-registry-mock")
-var pkg = __dirname + "/peer-deps-invalid"
+var pkg = path.resolve(__dirname, "peer-deps-invalid")
+var cache = path.resolve(pkg, "cache")
+var nodeModules = path.resolve(pkg, "node_modules")
var okFile = fs.readFileSync(path.join(pkg, "file-ok.js"), "utf8")
var failFile = fs.readFileSync(path.join(pkg, "file-fail.js"), "utf8")
test("installing dependencies that have conflicting peerDependencies", function (t) {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
process.chdir(pkg)
var customMocks = {
@@ -23,7 +25,7 @@ test("installing dependencies that have conflicting peerDependencies", function
}
mr({port: common.port, mocks: customMocks}, function (s) { // create mock registry.
npm.load({
- cache: pkg + "/cache",
+ cache: cache,
registry: common.registry
}, function () {
npm.commands.install([], function (err) {
@@ -40,7 +42,7 @@ test("installing dependencies that have conflicting peerDependencies", function
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/peer-deps-toplevel.js b/deps/npm/test/tap/peer-deps-toplevel.js
new file mode 100644
index 0000000000..30ab657dc8
--- /dev/null
+++ b/deps/npm/test/tap/peer-deps-toplevel.js
@@ -0,0 +1,55 @@
+var npm = npm = require("../../")
+var test = require("tap").test
+var path = require("path")
+var fs = require("fs")
+var osenv = require("osenv")
+var rimraf = require("rimraf")
+var mr = require("npm-registry-mock")
+var common = require("../common-tap.js")
+
+var pkg = path.resolve(__dirname, "peer-deps-toplevel")
+var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json")
+
+test("installs the peer dependency directory structure", function (t) {
+ mr(common.port, function (s) {
+ setup(function (err) {
+ t.ifError(err, "setup ran successfully")
+
+ npm.install(".", function (err) {
+ t.ifError(err, "packages were installed")
+
+ npm.commands.ls([], true, function (err, _, results) {
+ t.ifError(err, "listed tree without problems")
+
+ fs.readFile(desiredResultsPath, function (err, desired) {
+ t.ifError(err, "read desired results")
+
+ t.deepEqual(results, JSON.parse(desired), "got expected output from ls")
+ s.close()
+ t.end()
+ })
+ })
+ })
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
+})
+
+
+function setup (cb) {
+ cleanup()
+ process.chdir(pkg)
+
+ var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry}
+ npm.load(opts, cb)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(path.resolve(pkg, "node_modules"))
+ rimraf.sync(path.resolve(pkg, "cache"))
+}
diff --git a/deps/npm/test/tap/peer-deps-toplevel/desired-ls-results.json b/deps/npm/test/tap/peer-deps-toplevel/desired-ls-results.json
new file mode 100644
index 0000000000..28eff4c6d1
--- /dev/null
+++ b/deps/npm/test/tap/peer-deps-toplevel/desired-ls-results.json
@@ -0,0 +1,20 @@
+{
+ "name": "npm-test-peer-deps-toplevel",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps": {
+ "version": "0.0.0",
+ "dependencies": {
+ "underscore": {
+ "version": "1.3.1"
+ }
+ }
+ },
+ "mkdirp": {
+ "version": "0.3.5"
+ },
+ "request": {
+ "version": "0.9.5"
+ }
+ }
+}
diff --git a/deps/npm/test/tap/peer-deps-toplevel/package.json b/deps/npm/test/tap/peer-deps-toplevel/package.json
new file mode 100644
index 0000000000..ab77daeec3
--- /dev/null
+++ b/deps/npm/test/tap/peer-deps-toplevel/package.json
@@ -0,0 +1,11 @@
+{
+ "author": "Domenic Denicola",
+ "name": "npm-test-peer-deps-toplevel",
+ "version": "0.0.0",
+ "dependencies": {
+ "npm-test-peer-deps": "*"
+ },
+ "peerDependencies": {
+ "mkdirp": "*"
+ }
+}
diff --git a/deps/npm/test/tap/peer-deps-without-package-json.js b/deps/npm/test/tap/peer-deps-without-package-json.js
index ce01be4d08..eb000782f9 100644
--- a/deps/npm/test/tap/peer-deps-without-package-json.js
+++ b/deps/npm/test/tap/peer-deps-without-package-json.js
@@ -1,37 +1,39 @@
-var common = require('../common-tap.js')
+var common = require("../common-tap")
var fs = require("fs")
var path = require("path")
var test = require("tap").test
var rimraf = require("rimraf")
var npm = require("../../")
var mr = require("npm-registry-mock")
-var pkg = __dirname + "/peer-deps-without-package-json"
+var pkg = path.resolve(__dirname, "peer-deps-without-package-json")
+var cache = path.resolve(pkg, "cache")
+var nodeModules = path.resolve(pkg, "node_modules")
var js = fs.readFileSync(path.join(pkg, "file-js.js"), "utf8")
test("installing a peerDependencies-using package without a package.json present (GH-3049)", function (t) {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
- fs.mkdirSync(pkg + "/node_modules")
+ fs.mkdirSync(nodeModules)
process.chdir(pkg)
var customMocks = {
"get": {
- "/ok.js": [200, js],
+ "/ok.js": [200, js]
}
}
mr({port: common.port, mocks: customMocks}, function (s) { // create mock registry.
npm.load({
registry: common.registry,
- cache: pkg + "/cache"
+ cache: cache
}, function () {
npm.install(common.registry + "/ok.js", function (err) {
if (err) {
t.fail(err)
} else {
- t.ok(fs.existsSync(pkg + "/node_modules/npm-test-peer-deps-file"))
- t.ok(fs.existsSync(pkg + "/node_modules/underscore"))
+ t.ok(fs.existsSync(path.join(nodeModules, "/npm-test-peer-deps-file")))
+ t.ok(fs.existsSync(path.join(nodeModules, "/underscore")))
}
t.end()
s.close() // shutdown mock registry.
@@ -41,7 +43,7 @@ test("installing a peerDependencies-using package without a package.json present
})
test("cleanup", function (t) {
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ rimraf.sync(nodeModules)
+ rimraf.sync(cache)
t.end()
})
diff --git a/deps/npm/test/tap/peer-deps.js b/deps/npm/test/tap/peer-deps.js
index 097a921791..6e60fc1032 100644
--- a/deps/npm/test/tap/peer-deps.js
+++ b/deps/npm/test/tap/peer-deps.js
@@ -11,8 +11,6 @@ var pkg = path.resolve(__dirname, "peer-deps")
var desiredResultsPath = path.resolve(pkg, "desired-ls-results.json")
test("installs the peer dependency directory structure", function (t) {
- t.plan(1)
-
mr(common.port, function (s) {
setup(function (err) {
if (err) return t.fail(err)
@@ -46,7 +44,7 @@ function setup (cb) {
cleanup()
process.chdir(pkg)
- var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry};
+ var opts = { cache: path.resolve(pkg, "cache"), registry: common.registry}
npm.load(opts, cb)
}
diff --git a/deps/npm/test/tap/prepublish.js b/deps/npm/test/tap/prepublish.js
index ad71eab5cd..36391beeb3 100644
--- a/deps/npm/test/tap/prepublish.js
+++ b/deps/npm/test/tap/prepublish.js
@@ -1,10 +1,10 @@
// verify that prepublish runs on pack and publish
+var common = require("../common-tap")
var test = require("tap").test
var fs = require("graceful-fs")
var join = require("path").join
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
-var path = require("path")
var pkg = join(__dirname, "prepublish_package")
var tmp = join(pkg, "tmp")
@@ -12,6 +12,7 @@ var cache = join(pkg, "cache")
test("setup", function (t) {
var n = 0
+ cleanup()
mkdirp(pkg, then())
mkdirp(cache, then())
mkdirp(tmp, then())
@@ -38,9 +39,6 @@ test("setup", function (t) {
})
test("test", function (t) {
- var spawn = require("child_process").spawn
- var node = process.execPath
- var npm = path.resolve(__dirname, "../../cli.js")
var env = {
"npm_config_cache" : cache,
"npm_config_tmp" : tmp,
@@ -51,27 +49,16 @@ test("test", function (t) {
if (!/^npm_config_/.test(i))
env[i] = process.env[i]
}
- var child = spawn(node, [npm, "pack"], {
- cwd: pkg,
- env: env
- })
- child.stdout.setEncoding("utf8")
- child.stderr.on("data", onerr)
- child.stdout.on("data", ondata)
- child.on("close", onend)
- var c = ""
- , e = ""
- function ondata (chunk) {
- c += chunk
- }
- function onerr (chunk) {
- e += chunk
- }
- function onend () {
- if (e) {
- throw new Error("got stderr data: " + JSON.stringify("" + e))
- }
- c = c.trim()
+
+ common.npm([
+ "pack",
+ "--loglevel", "warn"
+ ], { cwd: pkg, env: env }, function(err, code, stdout, stderr) {
+ t.equal(code, 0, "pack finished successfully")
+ t.ifErr(err, "pack finished successfully")
+
+ t.notOk(stderr, "got stderr data:" + JSON.stringify("" + stderr))
+ var c = stdout.trim()
var regex = new RegExp("" +
"> npm-test-prepublish@1.2.5 prepublish [^\\r\\n]+\\r?\\n" +
"> echo ok\\r?\\n" +
@@ -81,14 +68,15 @@ test("test", function (t) {
t.ok(c.match(regex))
t.end()
- }
+ })
})
test("cleanup", function (t) {
- rimraf(pkg, function (er) {
- if (er) throw er
-
- t.pass("cleaned up")
- t.end()
- })
+ cleanup()
+ t.pass("cleaned up")
+ t.end()
})
+
+function cleanup() {
+ rimraf.sync(pkg)
+}
diff --git a/deps/npm/test/tap/prune.js b/deps/npm/test/tap/prune.js
index a303d840c0..24edf5e618 100644
--- a/deps/npm/test/tap/prune.js
+++ b/deps/npm/test/tap/prune.js
@@ -1,16 +1,17 @@
var test = require("tap").test
+var common = require("../common-tap")
var fs = require("fs")
-var node = process.execPath
-var npm = require.resolve("../../bin/npm-cli.js")
var rimraf = require("rimraf")
var mr = require("npm-registry-mock")
-var common = require("../common-tap.js")
-var spawn = require("child_process").spawn
var env = process.env
-process.env.npm_config_depth = "Infinity"
+var path = require("path")
-var pkg = __dirname + "/prune"
-var cache = pkg + "/cache"
+var pkg = path.resolve(__dirname, "prune")
+var cache = path.resolve(pkg, "cache")
+var nodeModules = path.resolve(pkg, "node_modules")
+
+var EXEC_OPTS = { cwd: pkg, env: env }
+EXEC_OPTS.env.npm_config_depth = "Infinity"
var server
@@ -22,38 +23,43 @@ test("reg mock", function (t) {
})
})
+function cleanup () {
+ rimraf.sync(cache)
+ rimraf.sync(nodeModules)
+}
+
+test("setup", function (t) {
+ cleanup()
+ t.pass("setup")
+ t.end()
+})
test("npm install", function (t) {
- rimraf.sync(pkg + "/node_modules")
- var c = spawn(node, [
- npm, "install",
- "--cache=" + cache,
- "--registry=" + common.registry,
- "--loglevel=silent",
- "--production=false"
- ], { cwd: pkg, env: env })
- c.stderr.on("data", function(d) {
- t.fail("Should not get data on stderr: " + d)
- })
- c.on("close", function(code) {
+ common.npm([
+ "install",
+ "--cache", cache,
+ "--registry", common.registry,
+ "--loglevel", "silent",
+ "--production", "false"
+ ], EXEC_OPTS, function (err, code, stdout, stderr) {
+ t.ifErr(err, "install finished successfully")
t.notOk(code, "exit ok")
+ t.notOk(stderr, "Should not get data on stderr: " + stderr)
t.end()
})
})
test("npm install test-package", function (t) {
- var c = spawn(node, [
- npm, "install", "test-package",
- "--cache=" + cache,
- "--registry=" + common.registry,
- "--loglevel=silent",
- "--production=false"
- ], { cwd: pkg, env: env })
- c.stderr.on("data", function(d) {
- t.fail("Should not get data on stderr: " + d)
- })
- c.on("close", function(code) {
+ common.npm([
+ "install", "test-package",
+ "--cache", cache,
+ "--registry", common.registry,
+ "--loglevel", "silent",
+ "--production", "false"
+ ], EXEC_OPTS, function (err, code, stdout, stderr) {
+ t.ifErr(err, "install finished successfully")
t.notOk(code, "exit ok")
+ t.notOk(stderr, "Should not get data on stderr: " + stderr)
t.end()
})
})
@@ -65,16 +71,14 @@ test("verify installs", function (t) {
})
test("npm prune", function (t) {
- var c = spawn(node, [
- npm, "prune",
- "--loglevel=silent",
- "--production=false"
- ], { cwd: pkg, env: env })
- c.stderr.on("data", function(d) {
- t.fail("Should not get data on stderr: " + d)
- })
- c.on("close", function(code) {
+ common.npm([
+ "prune",
+ "--loglevel", "silent",
+ "--production", "false"
+ ], EXEC_OPTS, function (err, code, stdout, stderr) {
+ t.ifErr(err, "prune finished successfully")
t.notOk(code, "exit ok")
+ t.notOk(stderr, "Should not get data on stderr: " + stderr)
t.end()
})
})
@@ -86,16 +90,14 @@ test("verify installs", function (t) {
})
test("npm prune", function (t) {
- var c = spawn(node, [
- npm, "prune",
- "--loglevel=silent",
+ common.npm([
+ "prune",
+ "--loglevel", "silent",
"--production"
- ], { cwd: pkg, env: env })
- c.stderr.on("data", function(d) {
- t.fail("Should not get data on stderr: " + d)
- })
- c.on("close", function(code) {
+ ], EXEC_OPTS, function (err, code, stderr) {
+ t.ifErr(err, "prune finished successfully")
t.notOk(code, "exit ok")
+ t.equal(stderr, "unbuild mkdirp@0.3.5\n")
t.end()
})
})
@@ -108,8 +110,7 @@ test("verify installs", function (t) {
test("cleanup", function (t) {
server.close()
- rimraf.sync(pkg + "/node_modules")
- rimraf.sync(pkg + "/cache")
+ cleanup()
t.pass("cleaned up")
t.end()
})
diff --git a/deps/npm/test/tap/publish-config.js b/deps/npm/test/tap/publish-config.js
index 39d6e83113..9e537a9206 100644
--- a/deps/npm/test/tap/publish-config.js
+++ b/deps/npm/test/tap/publish-config.js
@@ -1,11 +1,11 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var fs = require('fs')
-var osenv = require('osenv')
-var pkg = process.env.npm_config_tmp || '/tmp'
-pkg += '/npm-test-publish-config'
+var common = require("../common-tap.js")
+var test = require("tap").test
+var fs = require("fs")
+var osenv = require("osenv")
+var pkg = process.env.npm_config_tmp || "/tmp"
+pkg += "/npm-test-publish-config"
-require('mkdirp').sync(pkg)
+require("mkdirp").sync(pkg)
fs.writeFileSync(pkg + "/package.json", JSON.stringify({
name: "npm-test-publish-config",
@@ -19,21 +19,19 @@ fs.writeFileSync(pkg + "/fixture_npmrc",
"//localhost:1337/:_password = " + new Buffer("feast").toString("base64") + "\n" +
"registry = http://localhost:1337/")
-var spawn = require('child_process').spawn
-var npm = require.resolve('../../bin/npm-cli.js')
-var node = process.execPath
-
test(function (t) {
var child
- require('http').createServer(function (req, res) {
- t.pass('got request on the fakey fake registry')
+ require("http").createServer(function (req, res) {
+ t.pass("got request on the fakey fake registry")
t.end()
this.close()
res.statusCode = 500
- res.end('{"error":"sshhh. naptime nao. \\^O^/ <(YAWWWWN!)"}')
+ res.end(JSON.stringify({
+ error: "sshhh. naptime nao. \\^O^/ <(YAWWWWN!)"
+ }))
child.kill()
}).listen(common.port, function () {
- t.pass('server is listening')
+ t.pass("server is listening")
// don't much care about listening to the child's results
// just wanna make sure it hits the server we just set up.
@@ -42,17 +40,20 @@ test(function (t) {
// itself functions normally.
//
// Make sure that we don't sit around waiting for lock files
- child = spawn(node, [npm, "publish", "--userconfig=" + pkg + "/fixture_npmrc"], {
+ child = common.npm(["publish", "--userconfig=" + pkg + "/fixture_npmrc"], {
cwd: pkg,
stdio: "inherit",
env: {
- npm_config_cache_lock_stale: 1000,
- npm_config_cache_lock_wait: 1000,
+ "npm_config_cache_lock_stale": 1000,
+ "npm_config_cache_lock_wait": 1000,
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH,
USERPROFILE: osenv.home()
}
+ }, function (err, code) {
+ t.ifError(err, "publish command finished successfully")
+ t.notOk(code, "npm install exited with code 0")
})
})
})
diff --git a/deps/npm/test/tap/publish-scoped.js b/deps/npm/test/tap/publish-scoped.js
index 7547c91f1b..2658c8dd2b 100644
--- a/deps/npm/test/tap/publish-scoped.js
+++ b/deps/npm/test/tap/publish-scoped.js
@@ -11,6 +11,14 @@ var common = require("../common-tap.js")
var pkg = path.join(__dirname, "prepublish_package")
+// TODO: nock uses setImmediate, breaks 0.8: replace with mockRegistry
+if (!global.setImmediate) {
+ global.setImmediate = function () {
+ var args = [arguments[0], 0].concat([].slice.call(arguments, 1))
+ setTimeout.apply(this, args)
+ }
+}
+
test("setup", function (t) {
mkdirp(path.join(pkg, "cache"), next)
@@ -34,7 +42,9 @@ test("setup", function (t) {
})
test("npm publish should honor scoping", function (t) {
- var put = nock(common.registry).put("/@bigco%2fpublish-organized").reply(201, {ok: true})
+ var put = nock(common.registry)
+ .put("/@bigco%2fpublish-organized")
+ .reply(201, verify)
var configuration = {
cache : path.join(pkg, "cache"),
@@ -59,9 +69,29 @@ test("npm publish should honor scoping", function (t) {
t.end()
})
}
+
+ function verify (_, body) {
+ t.doesNotThrow(function () {
+ var parsed = JSON.parse(body)
+ var current = parsed.versions["1.2.5"]
+ t.equal(
+ current._npmVersion,
+ require(path.resolve(__dirname, "../../package.json")).version,
+ "npm version is correct"
+ )
+
+ t.equal(
+ current._nodeVersion,
+ process.versions.node,
+ "node version is correct"
+ )
+ }, "converted body back into object")
+
+ return {ok: true}
+ }
})
-test("cleanup", function(t) {
+test("cleanup", function (t) {
process.chdir(__dirname)
rimraf(pkg, function (er) {
t.ifError(er)
diff --git a/deps/npm/test/tap/pwd-prefix.js b/deps/npm/test/tap/pwd-prefix.js
index e041552e7d..237096e0a2 100644
--- a/deps/npm/test/tap/pwd-prefix.js
+++ b/deps/npm/test/tap/pwd-prefix.js
@@ -14,9 +14,9 @@ commands.forEach(function (cmd) {
var stdout, stderr
test(cmd + " in root", function (t) {
- common.npm([cmd], {cwd: root}, function(er, code, so, se) {
+ common.npm([cmd], {cwd: root}, function (er, code, so, se) {
if (er) throw er
- t.equal(code, 0)
+ t.notOk(code, "npm " + cmd + " exited with code 0")
stdout = so
stderr = se
t.end()
@@ -24,9 +24,9 @@ commands.forEach(function (cmd) {
})
test(cmd + " in lib", function (t) {
- common.npm([cmd], {cwd: lib}, function(er, code, so, se) {
+ common.npm([cmd], {cwd: lib}, function (er, code, so, se) {
if (er) throw er
- t.equal(code, 0)
+ t.notOk(code, "npm " + cmd + " exited with code 0")
t.equal(so, stdout)
t.equal(se, stderr)
t.end()
diff --git a/deps/npm/test/tap/referer.js b/deps/npm/test/tap/referer.js
index 1b55ab0261..c1b173d976 100644
--- a/deps/npm/test/tap/referer.js
+++ b/deps/npm/test/tap/referer.js
@@ -1,18 +1,17 @@
var common = require("../common-tap.js")
var test = require("tap").test
var http = require("http")
-var server
test("should send referer http header", function (t) {
- var server = http.createServer(function (q, s) {
+ http.createServer(function (q, s) {
t.equal(q.headers.referer, "install foo")
s.statusCode = 404
s.end(JSON.stringify({error: "whatever"}))
this.close()
}).listen(common.port, function () {
- var reg = "--registry=http://localhost:" + common.port
- var args = [ "install", "foo", reg ]
- common.npm(args, {}, function (er, code, so, se) {
+ var reg = "http://localhost:" + common.port
+ var args = [ "install", "foo", "--registry", reg ]
+ common.npm(args, {}, function (er, code) {
if (er) {
throw er
}
diff --git a/deps/npm/test/tap/registry.js b/deps/npm/test/tap/registry.js
index adcb8f48b1..20e7bbe811 100644
--- a/deps/npm/test/tap/registry.js
+++ b/deps/npm/test/tap/registry.js
@@ -1,63 +1,75 @@
// Run all the tests in the `npm-registry-couchapp` suite
// This verifies that the server-side stuff still works.
+var common = require("../common-tap")
var test = require("tap").test
-var spawn = require("child_process").spawn
var npmExec = require.resolve("../../bin/npm-cli.js")
var path = require("path")
var ca = path.resolve(__dirname, "../../node_modules/npm-registry-couchapp")
var which = require("which")
-which("couchdb", function(er, couch) {
- if (er) {
- return test("need couchdb", function (t) {
- t.fail("need couch to run test: " + er.message)
- t.end()
- })
- } else {
- runTests()
- }
-})
+var v = process.versions.node.split(".").map(function (n) { return parseInt(n, 10) })
+if (v[0] === 0 && v[1] < 10) {
+ console.error(
+ "WARNING: need a recent Node for npm-registry-couchapp tests to run, have",
+ process.versions.node
+ )
+}
+else {
+ which("couchdb", function (er) {
+ if (er) {
+ console.error("WARNING: need couch to run test: " + er.message)
+ }
+ else {
+ runTests()
+ }
+ })
+}
+
function runTests () {
var env = {}
for (var i in process.env) env[i] = process.env[i]
env.npm = npmExec
- spawn(process.execPath, [
- npmExec, "install"
- ], {
+ var opts = {
cwd: ca,
stdio: "inherit"
- }).on("close", function (code, sig) {
- if (code || sig) {
+ }
+ common.npm(["install"], opts, function (err, code) {
+ if (err) { throw err }
+ if (code) {
return test("need install to work", function (t) {
- t.fail("install failed with: " + (code || sig))
+ t.fail("install failed with: " + code)
t.end()
})
} else {
-
- spawn(process.execPath, [
- npmExec, "test"
- ], {
+ opts = {
cwd: ca,
env: env,
stdio: "inherit"
- }).on("close", function (code, sig) {
- spawn(process.execPath, [
- npmExec, "prune", "--production"
- ], {
+ }
+ common.npm(["test"], opts, function (err, code) {
+ if (err) { throw err }
+ if (code) {
+ return test("need test to work", function (t) {
+ t.fail("test failed with: " + code)
+ t.end()
+ })
+ }
+ opts = {
cwd: ca,
env: env,
stdio: "inherit"
- }).on("close", function (code2, sig2) {
- process.exit(code || code2 || 0)
+ }
+ common.npm(["prune", "--production"], opts, function (err, code) {
+ if (err) { throw err }
+ process.exit(code || 0)
})
})
}
-
})
}
diff --git a/deps/npm/test/tap/repo.js b/deps/npm/test/tap/repo.js
index bf7b574f86..caae7d3c3f 100644
--- a/deps/npm/test/tap/repo.js
+++ b/deps/npm/test/tap/repo.js
@@ -33,7 +33,7 @@ test("npm repo underscore", function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 0, 'exit ok')
var res = fs.readFileSync(outFile, 'ascii')
s.close()
@@ -52,7 +52,7 @@ test('npm repo optimist - github (https://)', function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 0, 'exit ok')
var res = fs.readFileSync(outFile, 'ascii')
s.close()
@@ -70,7 +70,7 @@ test("npm repo npm-test-peer-deps - no repo", function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 1, 'exit not ok')
s.close()
t.end()
@@ -85,7 +85,7 @@ test("npm repo test-repo-url-http - non-github (http://)", function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 0, 'exit ok')
var res = fs.readFileSync(outFile, 'ascii')
s.close()
@@ -103,7 +103,7 @@ test("npm repo test-repo-url-https - non-github (https://)", function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 0, 'exit ok')
var res = fs.readFileSync(outFile, 'ascii')
s.close()
@@ -121,7 +121,7 @@ test("npm repo test-repo-url-ssh - non-github (ssh://)", function (t) {
'--registry=' + common.registry,
'--loglevel=silent',
'--browser=' + __dirname + '/_script.sh'
- ], opts, function(err, code, stdout, stderr) {
+ ], opts, function (err, code, stdout, stderr) {
t.equal(code, 0, 'exit ok')
var res = fs.readFileSync(outFile, 'ascii')
s.close()
diff --git a/deps/npm/test/tap/run-script.js b/deps/npm/test/tap/run-script.js
index a308b5ffe9..6ce361968d 100644
--- a/deps/npm/test/tap/run-script.js
+++ b/deps/npm/test/tap/run-script.js
@@ -1,62 +1,84 @@
-var common = require('../common-tap')
- , test = require('tap').test
- , path = require('path')
- , spawn = require('child_process').spawn
- , rimraf = require('rimraf')
- , mkdirp = require('mkdirp')
- , pkg = __dirname + '/run-script'
- , cache = pkg + '/cache'
- , tmp = pkg + '/tmp'
- , node = process.execPath
- , npm = path.resolve(__dirname, '../../cli.js')
+var common = require("../common-tap")
+ , test = require("tap").test
+ , path = require("path")
+ , rimraf = require("rimraf")
+ , mkdirp = require("mkdirp")
+ , pkg = path.resolve(__dirname, "run-script")
+ , cache = path.resolve(pkg, "cache")
+ , tmp = path.resolve(pkg, "tmp")
, opts = { cwd: pkg }
function testOutput (t, command, er, code, stdout, stderr) {
+ var lines
+
if (er)
throw er
if (stderr)
- throw new Error('npm ' + command + ' stderr: ' + stderr.toString())
+ throw new Error("npm " + command + " stderr: " + stderr.toString())
+
+ lines = stdout.trim().split("\n")
+ stdout = lines.filter(function(line) {
+ return line.trim() !== "" && line[0] !== '>'
+ }).join(';')
- stdout = stdout.trim().split('\n')
- stdout = stdout[stdout.length - 1]
t.equal(stdout, command)
t.end()
}
function cleanup () {
- rimraf.sync(pkg + '/cache')
- rimraf.sync(pkg + '/tmp')
+ rimraf.sync(cache)
+ rimraf.sync(tmp)
}
-test('setup', function (t) {
+test("setup", function (t) {
cleanup()
- mkdirp.sync(pkg + '/cache')
- mkdirp.sync(pkg + '/tmp')
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
t.end()
})
-test('npm run-script', function (t) {
- common.npm(['run-script', 'start'], opts, testOutput.bind(null, t, "start"))
+test("npm run-script", function (t) {
+ common.npm(["run-script", "start"], opts, testOutput.bind(null, t, "start"))
})
-test('npm run-script with args', function (t) {
+test("npm run-script with args", function (t) {
common.npm(["run-script", "start", "--", "stop"], opts, testOutput.bind(null, t, "stop"))
})
-test('npm run-script with args that contain spaces', function(t) {
+test("npm run-script with args that contain spaces", function (t) {
common.npm(["run-script", "start", "--", "hello world"], opts, testOutput.bind(null, t, "hello world"))
})
-test('npm run-script with args that contain single quotes', function(t) {
+test("npm run-script with args that contain single quotes", function (t) {
common.npm(["run-script", "start", "--", "they're awesome"], opts, testOutput.bind(null, t, "they're awesome"))
})
-test('npm run-script with args that contain double quotes', function(t) {
+test("npm run-script with args that contain double quotes", function (t) {
common.npm(["run-script", "start", "--", "what's \"up\"?"], opts, testOutput.bind(null, t, "what's \"up\"?"))
})
-test('cleanup', function (t) {
+test("npm run-script with pre script", function (t) {
+ common.npm(["run-script", "with-post"], opts, testOutput.bind(null, t, "main;post"))
+})
+
+test("npm run-script with post script", function (t) {
+ common.npm(["run-script", "with-pre"], opts, testOutput.bind(null, t, "pre;main"))
+})
+
+test("npm run-script with both pre and post script", function (t) {
+ common.npm(["run-script", "with-both"], opts, testOutput.bind(null, t, "pre;main;post"))
+})
+
+test("npm run-script with both pre and post script and with args", function (t) {
+ common.npm(["run-script", "with-both", "--", "an arg"], opts, testOutput.bind(null, t, "pre;an arg;post"))
+})
+
+test("npm run-script explicitly call pre script with arg", function (t) {
+ common.npm(["run-script", "prewith-pre", "--", "an arg"], opts, testOutput.bind(null, t, "an arg"))
+})
+
+test("cleanup", function (t) {
cleanup()
t.end()
})
diff --git a/deps/npm/test/tap/run-script/package.json b/deps/npm/test/tap/run-script/package.json
index 49b8636683..afa0e3f0c8 100644
--- a/deps/npm/test/tap/run-script/package.json
+++ b/deps/npm/test/tap/run-script/package.json
@@ -1,6 +1,13 @@
{"name":"runscript"
,"version":"1.2.3"
,"scripts":{
- "start":"node -e 'console.log(process.argv[1] || \"start\")'"
+ "start":"node -e 'console.log(process.argv[1] || \"start\")'",
+ "prewith-pre":"node -e 'console.log(process.argv[1] || \"pre\")'",
+ "with-pre":"node -e 'console.log(process.argv[1] || \"main\")'",
+ "with-post":"node -e 'console.log(process.argv[1] || \"main\")'",
+ "postwith-post":"node -e 'console.log(process.argv[1] || \"post\")'",
+ "prewith-both":"node -e 'console.log(process.argv[1] || \"pre\")'",
+ "with-both":"node -e 'console.log(process.argv[1] || \"main\")'",
+ "postwith-both":"node -e 'console.log(process.argv[1] || \"post\")'"
}
}
diff --git a/deps/npm/test/tap/scripts-whitespace-windows.js b/deps/npm/test/tap/scripts-whitespace-windows.js
index 97bed98cb7..44170af5b9 100644
--- a/deps/npm/test/tap/scripts-whitespace-windows.js
+++ b/deps/npm/test/tap/scripts-whitespace-windows.js
@@ -1,71 +1,54 @@
-var test = require('tap').test
-var path = require('path')
-var npm = path.resolve(__dirname, '../../cli.js')
-var pkg = __dirname + '/scripts-whitespace-windows'
-var tmp = pkg + '/tmp'
-var cache = pkg + '/cache'
-var modules = pkg + '/node_modules'
-var dep = pkg + '/dep'
-
-var mkdirp = require('mkdirp')
-var rimraf = require('rimraf')
-var node = process.execPath
-var spawn = require('child_process').spawn
-
-test('setup', function (t) {
+var test = require("tap").test
+var common = require("../common-tap")
+var path = require("path")
+var pkg = path.resolve(__dirname, "scripts-whitespace-windows")
+var tmp = path.resolve(pkg, "tmp")
+var cache = path.resolve(pkg, "cache")
+var modules = path.resolve(pkg, "node_modules")
+var dep = path.resolve(pkg, "dep")
+
+var mkdirp = require("mkdirp")
+var rimraf = require("rimraf")
+
+test("setup", function (t) {
+ cleanup()
mkdirp.sync(cache)
mkdirp.sync(tmp)
- rimraf.sync(modules)
- var env = {
- npm_config_cache: cache,
- npm_config_tmp: tmp,
- npm_config_prefix: pkg,
- npm_config_global: 'false'
- }
-
- var child = spawn(node, [npm, 'i', dep], {
+ common.npm(["i", dep], {
cwd: pkg,
- env: env
- })
-
- child.stdout.setEncoding('utf8')
- child.stderr.on('data', function(chunk) {
- throw new Error('got stderr data: ' + JSON.stringify('' + chunk))
- })
- child.on('close', function () {
+ env: {
+ "npm_config_cache": cache,
+ "npm_config_tmp": tmp,
+ "npm_config_prefix": pkg,
+ "npm_config_global": "false"
+ }
+ }, function (err, code, stdout, stderr) {
+ t.ifErr(err, "npm i " + dep + " finished without error")
+ t.equal(code, 0, "npm i " + dep + " exited ok")
+ t.notOk(stderr, "no output stderr")
t.end()
})
})
-test('test', function (t) {
-
- var child = spawn(node, [npm, 'run', 'foo'], {
- cwd: pkg,
- env: process.env
- })
-
- child.stdout.setEncoding('utf8')
- child.stderr.on('data', function(chunk) {
- throw new Error('got stderr data: ' + JSON.stringify('' + chunk))
+test("test", function (t) {
+ common.npm(["run", "foo"], { cwd: pkg }, function (err, code, stdout, stderr) {
+ t.ifErr(err, "npm run finished without error")
+ t.equal(code, 0, "npm run exited ok")
+ t.notOk(stderr, "no output stderr: ", stderr)
+ stdout = stdout.trim()
+ t.ok(/npm-test-fine/.test(stdout))
+ t.end()
})
- child.stdout.on('data', ondata)
- child.on('close', onend)
- var c = ''
- function ondata (chunk) {
- c += chunk
- }
- function onend () {
- c = c.trim()
+})
- t.ok(/npm-test-fine/.test(c))
- t.end()
- }
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
})
-test('cleanup', function (t) {
+function cleanup() {
rimraf.sync(cache)
rimraf.sync(tmp)
rimraf.sync(modules)
- t.end()
-})
+}
diff --git a/deps/npm/test/tap/search.js b/deps/npm/test/tap/search.js
new file mode 100644
index 0000000000..d4c5669733
--- /dev/null
+++ b/deps/npm/test/tap/search.js
@@ -0,0 +1,265 @@
+var common = require("../common-tap.js")
+var test = require("tap").test
+var rimraf = require("rimraf")
+var mr = require("npm-registry-mock")
+var fs = require("fs")
+var path = require("path")
+var pkg = path.resolve(__dirname, "search")
+var cache = path.resolve(pkg, "cache")
+var registryCache = path.resolve(cache, "localhost_1337", "-", "all")
+var cacheJsonFile = path.resolve(registryCache, ".cache.json")
+var mkdirp = require("mkdirp")
+
+var timeMock = {
+ epoch: 1411727900,
+ future: 1411727900+100,
+ all: 1411727900+25,
+ since: 0 // filled by since server callback
+}
+
+var EXEC_OPTS = {}
+
+function cleanupCache() {
+ rimraf.sync(cache)
+}
+function cleanup () { cleanupCache() }
+
+function setupCache() {
+ mkdirp.sync(cache)
+ mkdirp.sync(registryCache)
+ var res = fs.writeFileSync(cacheJsonFile, stringifyUpdated(timeMock.epoch))
+ if (res) throw new Error("Creating cache file failed")
+}
+
+var mocks = {
+ /* Since request, always response with an _update time > the time requested */
+ sinceFuture: function(server) {
+ server.filteringPathRegEx(/startkey=[^&]*/g, function(s) {
+ var _allMock = JSON.parse(JSON.stringify(allMock))
+ timeMock.since = _allMock._updated = s.replace("startkey=", "")
+ server.get("/-/all/since?stale=update_after&" + s)
+ .reply(200, _allMock)
+ return s
+ })
+ },
+ allFutureUpdatedOnly: function(server) {
+ server.get("/-/all")
+ .reply(200, stringifyUpdated(timeMock.future))
+ },
+ all: function(server) {
+ server.get("/-/all")
+ .reply(200, allMock)
+ }
+}
+
+
+test("No previous cache, init cache triggered by first search", function(t) {
+ cleanupCache()
+
+ mr({ port: common.port, mocks: mocks.allFutureUpdatedOnly }, function (s) {
+ common.npm([
+ "search", "do not do extra search work on my behalf",
+ "--registry", common.registry,
+ "--cache", cache,
+ "--loglevel", "silent",
+ "--color", "always"
+ ],
+ EXEC_OPTS,
+ function(err, code) {
+ s.close()
+ t.equal(code, 0, "search finished successfully")
+ t.ifErr(err, "search finished successfully")
+
+ t.ok(fs.existsSync(cacheJsonFile),
+ cacheJsonFile + " expected to have been created")
+ var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, "utf8"))
+ t.equal(cacheData._updated, String(timeMock.future))
+ t.end()
+ })
+ })
+})
+
+test("previous cache, _updated set, should trigger since request", function(t) {
+ cleanupCache()
+ setupCache()
+
+ function m(server) {
+ [ mocks.all, mocks.sinceFuture ].forEach(function(m) {
+ m(server)
+ })
+ }
+ mr({ port: common.port, mocks: m }, function (s) {
+ common.npm([
+ "search", "do not do extra search work on my behalf",
+ "--registry", common.registry,
+ "--cache", cache,
+ "--loglevel", "silly",
+ "--color", "always"
+ ],
+ EXEC_OPTS,
+ function(err, code) {
+ s.close()
+ t.equal(code, 0, "search finished successfully")
+ t.ifErr(err, "search finished successfully")
+
+ var cacheData = JSON.parse(fs.readFileSync(cacheJsonFile, "utf8"))
+ t.equal(cacheData._updated,
+ timeMock.since,
+ "cache update time gotten from since response")
+ cleanupCache()
+ t.end()
+ })
+ })
+})
+
+
+var searches = [
+ {
+ term: "f36b6a6123da50959741e2ce4d634f96ec668c56",
+ description: "non-regex",
+ location: 241
+ },
+ {
+ term: "/f36b6a6123da50959741e2ce4d634f96ec668c56/",
+ description: "regex",
+ location: 241
+ }
+]
+
+searches.forEach(function(search) {
+ test(search.description + " search in color", function(t) {
+ cleanupCache()
+ mr({ port: common.port, mocks: mocks.all }, function (s) {
+ common.npm([
+ "search", search.term,
+ "--registry", common.registry,
+ "--cache", cache,
+ "--loglevel", "silent",
+ "--color", "always"
+ ],
+ EXEC_OPTS,
+ function(err, code, stdout) {
+ s.close()
+ t.equal(code, 0, "search finished successfully")
+ t.ifErr(err, "search finished successfully")
+ // \033 == \u001B
+ var markStart = "\u001B\\[[0-9][0-9]m"
+ var markEnd = "\u001B\\[0m"
+
+ var re = new RegExp(markStart + ".*?" + markEnd)
+
+ var cnt = stdout.search(re)
+ t.equal(cnt, search.location,
+ search.description + " search for " + search.term)
+ t.end()
+ })
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ cleanup()
+ t.end()
+})
+
+function stringifyUpdated(time) {
+ return JSON.stringify({ _updated : String(time) })
+}
+
+var allMock = {
+ "_updated": timeMock.all,
+ "generator-frontcow": {
+ "name": "generator-frontcow",
+ "description": "f36b6a6123da50959741e2ce4d634f96ec668c56 This is a fake description to ensure we do not accidentally search the real npm registry or use some kind of cache",
+ "dist-tags": {
+ "latest": "0.1.19"
+ },
+ "maintainers": [
+ {
+ "name": "bcabanes",
+ "email": "contact@benjamincabanes.com"
+ }
+ ],
+ "homepage": "https://github.com/bcabanes/generator-frontcow",
+ "keywords": [
+ "sass",
+ "frontend",
+ "yeoman-generator",
+ "atomic",
+ "design",
+ "sass",
+ "foundation",
+ "foundation5",
+ "atomic design",
+ "bourbon",
+ "polyfill",
+ "font awesome"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/bcabanes/generator-frontcow"
+ },
+ "author": {
+ "name": "ben",
+ "email": "contact@benjamincabanes.com",
+ "url": "https://github.com/bcabanes"
+ },
+ "bugs": {
+ "url": "https://github.com/bcabanes/generator-frontcow/issues"
+ },
+ "license": "MIT",
+ "readmeFilename": "README.md",
+ "time": {
+ "modified": "2014-10-03T02:26:18.406Z"
+ },
+ "versions": {
+ "0.1.19": "latest"
+ }
+ },
+ "marko": {
+ "name": "marko",
+ "description": "Marko is an extensible, streaming, asynchronous, high performance, HTML-based templating language that can be used in Node.js or in the browser.",
+ "dist-tags": {
+ "latest": "1.2.16"
+ },
+ "maintainers": [
+ {
+ "name": "pnidem",
+ "email": "pnidem@gmail.com"
+ },
+ {
+ "name": "philidem",
+ "email": "phillip.idem@gmail.com"
+ }
+ ],
+ "homepage": "https://github.com/raptorjs/marko",
+ "keywords": [
+ "templating",
+ "template",
+ "async",
+ "streaming"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/raptorjs/marko.git"
+ },
+ "author": {
+ "name": "Patrick Steele-Idem",
+ "email": "pnidem@gmail.com"
+ },
+ "bugs": {
+ "url": "https://github.com/raptorjs/marko/issues"
+ },
+ "license": "Apache License v2.0",
+ "readmeFilename": "README.md",
+ "users": {
+ "pnidem": true
+ },
+ "time": {
+ "modified": "2014-10-03T02:27:31.775Z"
+ },
+ "versions": {
+ "1.2.16": "latest"
+ }
+ }
+}
diff --git a/deps/npm/test/tap/semver-doc.js b/deps/npm/test/tap/semver-doc.js
index 5133f46599..963cace101 100644
--- a/deps/npm/test/tap/semver-doc.js
+++ b/deps/npm/test/tap/semver-doc.js
@@ -1,11 +1,11 @@
var test = require("tap").test
-test("semver doc is up to date", function(t) {
+test("semver doc is up to date", function (t) {
var path = require("path")
var moddoc = path.join(__dirname, "../../node_modules/semver/README.md")
var mydoc = path.join(__dirname, "../../doc/misc/semver.md")
var fs = require("fs")
- var mod = fs.readFileSync(moddoc, "utf8").replace(/semver\(1\)/, 'semver(7)')
+ var mod = fs.readFileSync(moddoc, "utf8").replace(/semver\(1\)/, "semver(7)")
var my = fs.readFileSync(mydoc, "utf8")
t.equal(my, mod)
t.end()
diff --git a/deps/npm/test/tap/semver-tag.js b/deps/npm/test/tap/semver-tag.js
index 7633e55426..03dcdf85b6 100644
--- a/deps/npm/test/tap/semver-tag.js
+++ b/deps/npm/test/tap/semver-tag.js
@@ -5,7 +5,7 @@ var test = require("tap").test
test("try to tag with semver range as tag name", function (t) {
var cmd = ["tag", "zzzz@1.2.3", "v2.x", "--registry=http://localhost"]
common.npm(cmd, {
- stdio: "pipe",
+ stdio: "pipe"
}, function (er, code, so, se) {
if (er) throw er
t.similar(se, /Tag name must not be a valid SemVer range: v2.x\n/)
diff --git a/deps/npm/test/tap/shrinkwrap-empty-deps.js b/deps/npm/test/tap/shrinkwrap-empty-deps.js
index 9ec8e71e0b..6be67af744 100644
--- a/deps/npm/test/tap/shrinkwrap-empty-deps.js
+++ b/deps/npm/test/tap/shrinkwrap-empty-deps.js
@@ -6,7 +6,8 @@ var test = require("tap").test
, fs = require("fs")
, osenv = require("osenv")
, rimraf = require("rimraf")
- , pkg = __dirname + "/shrinkwrap-empty-deps"
+ , pkg = path.resolve(__dirname, "shrinkwrap-empty-deps")
+ , cache = path.resolve(pkg, "cache")
test("returns a list of removed items", function (t) {
var desiredResultsPath = path.resolve(pkg, "npm-shrinkwrap.json")
@@ -36,7 +37,7 @@ test("returns a list of removed items", function (t) {
function setup (cb) {
cleanup()
process.chdir(pkg)
- npm.load({cache: pkg + "/cache", registry: common.registry}, function () {
+ npm.load({cache: cache, registry: common.registry}, function () {
cb()
})
}
diff --git a/deps/npm/test/tap/sorted-package-json.js b/deps/npm/test/tap/sorted-package-json.js
index 41c90855a8..1dec1d2ae1 100644
--- a/deps/npm/test/tap/sorted-package-json.js
+++ b/deps/npm/test/tap/sorted-package-json.js
@@ -30,11 +30,11 @@ test("sorting dependencies", function (t) {
var child = spawn(node, [npm, "install", "--save", "underscore@1.3.3"], {
cwd: pkg,
env: {
- npm_config_registry: common.registry,
- npm_config_cache: cache,
- npm_config_tmp: tmp,
- npm_config_prefix: pkg,
- npm_config_global: "false",
+ "npm_config_registry": common.registry,
+ "npm_config_cache": cache,
+ "npm_config_tmp": tmp,
+ "npm_config_prefix": pkg,
+ "npm_config_global": "false",
HOME: process.env.HOME,
Path: process.env.PATH,
PATH: process.env.PATH
@@ -42,6 +42,7 @@ test("sorting dependencies", function (t) {
})
child.on("close", function (code) {
+ t.equal(code, 0, "npm install exited with code")
var result = fs.readFileSync(packageJson).toString()
, resultAsJson = JSON.parse(result)
@@ -83,7 +84,7 @@ function setup() {
"underscore": "^1.3.3",
"request": "^0.9.0"
}
- }, null, 2), 'utf8')
+ }, null, 2), "utf8")
}
function cleanup() {
diff --git a/deps/npm/test/tap/spawn-enoent.js b/deps/npm/test/tap/spawn-enoent.js
index 7ea9dab560..20fed21bcf 100644
--- a/deps/npm/test/tap/spawn-enoent.js
+++ b/deps/npm/test/tap/spawn-enoent.js
@@ -26,7 +26,7 @@ test("enoent script", function (t) {
env: {
PATH: process.env.PATH,
Path: process.env.Path,
- npm_config_loglevel: "warn"
+ "npm_config_loglevel": "warn"
}
}, function (er, code, sout, serr) {
t.similar(serr, /npm ERR! Failed at the x@1\.2\.3 start script\./)
diff --git a/deps/npm/test/tap/startstop.js b/deps/npm/test/tap/startstop.js
index f056aa7892..334551ed29 100644
--- a/deps/npm/test/tap/startstop.js
+++ b/deps/npm/test/tap/startstop.js
@@ -1,22 +1,18 @@
-var common = require('../common-tap')
- , test = require('tap').test
- , path = require('path')
- , spawn = require('child_process').spawn
- , rimraf = require('rimraf')
- , mkdirp = require('mkdirp')
- , pkg = __dirname + '/startstop'
- , cache = pkg + '/cache'
- , tmp = pkg + '/tmp'
- , node = process.execPath
- , npm = path.resolve(__dirname, '../../cli.js')
+var common = require("../common-tap")
+ , test = require("tap").test
+ , path = require("path")
+ , rimraf = require("rimraf")
+ , mkdirp = require("mkdirp")
+ , pkg = path.resolve(__dirname, "startstop")
+ , cache = path.resolve(pkg, "cache")
+ , tmp = path.resolve(pkg, "tmp")
, opts = { cwd: pkg }
function testOutput (t, command, er, code, stdout, stderr) {
- if (er)
- throw er
+ t.notOk(code, "npm " + command + " exited with code 0")
if (stderr)
- throw new Error('npm ' + command + ' stderr: ' + stderr.toString())
+ throw new Error("npm " + command + " stderr: " + stderr.toString())
stdout = stdout.trim().split(/\n|\r/)
stdout = stdout[stdout.length - 1]
@@ -25,40 +21,40 @@ function testOutput (t, command, er, code, stdout, stderr) {
}
function cleanup () {
- rimraf.sync(pkg + '/cache')
- rimraf.sync(pkg + '/tmp')
+ rimraf.sync(cache)
+ rimraf.sync(tmp)
}
-test('setup', function (t) {
+test("setup", function (t) {
cleanup()
- mkdirp.sync(pkg + '/cache')
- mkdirp.sync(pkg + '/tmp')
+ mkdirp.sync(cache)
+ mkdirp.sync(tmp)
t.end()
})
-test('npm start', function (t) {
- common.npm(['start'], opts, testOutput.bind(null, t, "start"))
+test("npm start", function (t) {
+ common.npm(["start"], opts, testOutput.bind(null, t, "start"))
})
-test('npm stop', function (t) {
- common.npm(['stop'], opts, testOutput.bind(null, t, "stop"))
+test("npm stop", function (t) {
+ common.npm(["stop"], opts, testOutput.bind(null, t, "stop"))
})
-test('npm restart', function (t) {
- common.npm(['restart'], opts, function (er, c, stdout, stderr) {
+test("npm restart", function (t) {
+ common.npm(["restart"], opts, function (er, c, stdout) {
if (er)
throw er
- var output = stdout.split('\n').filter(function (val) {
+ var output = stdout.split("\n").filter(function (val) {
return val.match(/^s/)
})
- t.same(output.sort(), ['start', 'stop'].sort())
+ t.same(output.sort(), ["start", "stop"].sort())
t.end()
})
})
-test('cleanup', function (t) {
+test("cleanup", function (t) {
cleanup()
t.end()
})
diff --git a/deps/npm/test/tap/test-run-ls.js b/deps/npm/test/tap/test-run-ls.js
index 4c869e5e24..252c6e8f93 100644
--- a/deps/npm/test/tap/test-run-ls.js
+++ b/deps/npm/test/tap/test-run-ls.js
@@ -6,7 +6,7 @@ var testscript = require("../../package.json").scripts.test
var tsregexp = testscript.replace(/([\[\.\*\]])/g, "\\$1")
test("default", function (t) {
- common.npm(["run"], { cwd: cwd }, function (er, code, so, se) {
+ common.npm(["run"], { cwd: cwd }, function (er, code, so) {
if (er) throw er
t.notOk(code)
t.similar(so, new RegExp("\\n test\\n " + tsregexp + "\\n"))
@@ -15,7 +15,7 @@ test("default", function (t) {
})
test("parseable", function (t) {
- common.npm(["run", "-p"], { cwd: cwd }, function (er, code, so, se) {
+ common.npm(["run", "-p"], { cwd: cwd }, function (er, code, so) {
if (er) throw er
t.notOk(code)
t.similar(so, new RegExp("\\ntest:" + tsregexp + "\\n"))
@@ -24,7 +24,7 @@ test("parseable", function (t) {
})
test("parseable", function (t) {
- common.npm(["run", "--json"], { cwd: cwd }, function (er, code, so, se) {
+ common.npm(["run", "--json"], { cwd: cwd }, function (er, code, so) {
if (er) throw er
t.notOk(code)
t.equal(JSON.parse(so).test, testscript)
diff --git a/deps/npm/test/tap/uninstall-package.js b/deps/npm/test/tap/uninstall-package.js
index 0682701250..a0ba4c6c1a 100644
--- a/deps/npm/test/tap/uninstall-package.js
+++ b/deps/npm/test/tap/uninstall-package.js
@@ -3,7 +3,8 @@ var test = require("tap").test
, rimraf = require("rimraf")
, mr = require("npm-registry-mock")
, common = require("../common-tap.js")
- , pkg = __dirname + "/uninstall-package"
+ , path = require("path")
+ , pkg = path.join(__dirname, "uninstall-package")
test("returns a list of removed items", function (t) {
t.plan(1)
diff --git a/deps/npm/test/tap/unpack-foreign-tarball.js b/deps/npm/test/tap/unpack-foreign-tarball.js
index a03f9b17f4..d2e2e73c91 100644
--- a/deps/npm/test/tap/unpack-foreign-tarball.js
+++ b/deps/npm/test/tap/unpack-foreign-tarball.js
@@ -12,8 +12,8 @@ var tmp = path.resolve(dir, "tmp")
var pkg = path.resolve(nm, "npm-test-gitignore")
var env = {
- npm_config_cache: cache,
- npm_config_tmp: tmp
+ "npm_config_cache": cache,
+ "npm_config_tmp": tmp
}
var conf = {
@@ -22,36 +22,39 @@ var conf = {
stdio: [ "pipe", "pipe", 2 ]
}
+function verify (t, files, err, code) {
+ if (code) {
+ t.fail("exited with failure: " + code)
+ return t.end()
+ }
+ var actual = fs.readdirSync(pkg).sort()
+ var expect = files.concat([".npmignore", "package.json"]).sort()
+ t.same(actual, expect)
+ t.end()
+}
+
test("npmignore only", function (t) {
setup()
var file = path.resolve(dir, "npmignore.tgz")
- common.npm(["install", file], conf, function (code, stdout, stderr) {
- verify(t, code, ["foo"])
- })
+ common.npm(["install", file], conf, verify.bind(null, t, ["foo"]))
})
test("gitignore only", function (t) {
setup()
var file = path.resolve(dir, "gitignore.tgz")
- common.npm(["install", file], conf, function (code, stdout, stderr) {
- verify(t, code, ["foo"])
- })
+ common.npm(["install", file], conf, verify.bind(null, t, ["foo"]))
})
test("gitignore and npmignore", function (t) {
setup()
var file = path.resolve(dir, "gitignore-and-npmignore.tgz")
- common.npm(["install", file], conf, function (code, stdout, stderr) {
- verify(t, code, ["foo", "bar"])
- })
+ common.npm(["install", file], conf, verify.bind(null, t, ["foo", "bar"]))
})
test("gitignore and npmignore, not gzipped", function (t) {
setup()
var file = path.resolve(dir, "gitignore-and-npmignore.tar")
- common.npm(["install", file], conf, function (code, stdout, stderr) {
- verify(t, code, ["foo", "bar"])
- })
+ common.npm(["install", file], conf, verify.bind(null, t, ["foo", "bar"]))
})
test("clean", function (t) {
@@ -59,17 +62,6 @@ test("clean", function (t) {
t.end()
})
-function verify (t, code, files) {
- if (code) {
- t.fail("exited with failure: " + code)
- return t.end()
- }
- var actual = fs.readdirSync(pkg).sort()
- var expect = files.concat([".npmignore", "package.json"]).sort()
- t.same(actual, expect)
- t.end()
-}
-
function setup () {
clean()
mkdirp.sync(nm)
diff --git a/deps/npm/test/tap/update-save.js b/deps/npm/test/tap/update-save.js
index 6323ef8515..5f871b26c8 100644
--- a/deps/npm/test/tap/update-save.js
+++ b/deps/npm/test/tap/update-save.js
@@ -3,8 +3,8 @@ var test = require("tap").test
var npm = require("../../")
var mkdirp = require("mkdirp")
var rimraf = require("rimraf")
-var fs = require('fs')
-var path = require('path')
+var fs = require("fs")
+var path = require("path")
var mr = require("npm-registry-mock")
var PKG_DIR = path.resolve(__dirname, "update-save")
@@ -14,10 +14,10 @@ var MODULES_DIR = path.resolve(PKG_DIR, "node_modules")
var EXEC_OPTS = {
cwd: PKG_DIR,
- stdio: 'ignore',
+ stdio: "ignore",
env: {
- npm_config_registry: common.registry,
- npm_config_loglevel: 'verbose'
+ "npm_config_registry": common.registry,
+ "npm_config_loglevel": "verbose"
}
}
@@ -32,9 +32,9 @@ var DEFAULT_PKG = {
}
}
-var s = undefined // mock server reference
+var s // mock server reference
-test('setup', function (t) {
+test("setup", function (t) {
resetPackage()
mr(common.port, function (server) {
@@ -49,14 +49,14 @@ test('setup', function (t) {
test("update regular dependencies only", function (t) {
resetPackage()
- common.npm(['update', '--save'], EXEC_OPTS, function (err, code) {
+ common.npm(["update", "--save"], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.equal(code, 0)
+ t.notOk(code, "npm update exited with code 0")
- var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8'))
- t.deepEqual(pkgdata.dependencies, {mkdirp: '^0.3.5'}, 'only dependencies updated')
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched')
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be untouched')
+ var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
+ t.deepEqual(pkgdata.dependencies, {mkdirp: "^0.3.5"}, "only dependencies updated")
+ t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
+ t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
@@ -64,14 +64,14 @@ test("update regular dependencies only", function (t) {
test("update devDependencies only", function (t) {
resetPackage()
- common.npm(['update', '--save-dev'], EXEC_OPTS, function (err, code, stdout, stderr) {
+ common.npm(["update", "--save-dev"], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.equal(code, 0)
+ t.notOk(code, "npm update exited with code 0")
- var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8'))
- t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, 'dependencies should be untouched')
- t.deepEqual(pkgdata.devDependencies, {underscore: '^1.3.3'}, 'dev dependencies should be updated')
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be untouched')
+ var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
+ t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, "dependencies should be untouched")
+ t.deepEqual(pkgdata.devDependencies, {underscore: "^1.3.3"}, "dev dependencies should be updated")
+ t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
@@ -83,14 +83,14 @@ test("update optionalDependencies only", function (t) {
}
})
- common.npm(['update', '--save-optional'], EXEC_OPTS, function (err, code) {
+ common.npm(["update", "--save-optional"], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.equal(code, 0)
+ t.notOk(code, "npm update exited with code 0")
- var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8'))
- t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, 'dependencies should be untouched')
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched')
- t.deepEqual(pkgdata.optionalDependencies, {underscore: '^1.3.3'}, 'optional dependencies should be updated')
+ var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
+ t.deepEqual(pkgdata.dependencies, DEFAULT_PKG.dependencies, "dependencies should be untouched")
+ t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
+ t.deepEqual(pkgdata.optionalDependencies, {underscore: "^1.3.3"}, "optional dependencies should be updated")
t.end()
})
})
@@ -102,14 +102,14 @@ test("optionalDependencies are merged into dependencies during --save", function
}
})
- common.npm(['update', '--save'], EXEC_OPTS, function (err, code) {
+ common.npm(["update", "--save"], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.equal(code, 0)
+ t.notOk(code, "npm update exited with code 0")
- var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8'))
- t.deepEqual(pkgdata.dependencies, {mkdirp: '^0.3.5'}, 'dependencies should not include optional dependencies')
- t.deepEqual(pkgdata.devDependencies, pkg.devDependencies, 'dev dependencies should be untouched')
- t.deepEqual(pkgdata.optionalDependencies, pkg.optionalDependencies, 'optional dependencies should be untouched')
+ var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
+ t.deepEqual(pkgdata.dependencies, {mkdirp: "^0.3.5"}, "dependencies should not include optional dependencies")
+ t.deepEqual(pkgdata.devDependencies, pkg.devDependencies, "dev dependencies should be untouched")
+ t.deepEqual(pkgdata.optionalDependencies, pkg.optionalDependencies, "optional dependencies should be untouched")
t.end()
})
})
@@ -117,16 +117,16 @@ test("optionalDependencies are merged into dependencies during --save", function
test("semver prefix is replaced with configured save-prefix", function (t) {
resetPackage()
- common.npm(['update', '--save', '--save-prefix', '~'], EXEC_OPTS, function (err, code) {
+ common.npm(["update", "--save", "--save-prefix", "~"], EXEC_OPTS, function (err, code) {
t.ifError(err)
- t.equal(code, 0)
+ t.notOk(code, "npm update exited with code 0")
- var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8'))
+ var pkgdata = JSON.parse(fs.readFileSync(PKG, "utf8"))
t.deepEqual(pkgdata.dependencies, {
- mkdirp: '~0.3.5'
- }, 'dependencies should be updated')
- t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, 'dev dependencies should be untouched')
- t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, 'optional dependencies should be updated')
+ mkdirp: "~0.3.5"
+ }, "dependencies should be updated")
+ t.deepEqual(pkgdata.devDependencies, DEFAULT_PKG.devDependencies, "dev dependencies should be untouched")
+ t.deepEqual(pkgdata.optionalDependencies, DEFAULT_PKG.optionalDependencies, "optional dependencies should be updated")
t.end()
})
})
@@ -137,8 +137,8 @@ function resetPackage(extendWith) {
mkdirp.sync(CACHE_DIR)
var pkg = clone(DEFAULT_PKG)
extend(pkg, extendWith)
- for (key in extend) { pkg[key] = extend[key]}
- fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2), 'ascii')
+ for (var key in extend) { pkg[key] = extend[key]}
+ fs.writeFileSync(PKG, JSON.stringify(pkg, null, 2), "ascii")
return pkg
}
@@ -155,6 +155,6 @@ function clone(a) {
}
function extend(a, b) {
- for (key in b) { a[key] = b[key]}
+ for (var key in b) { a[key] = b[key]}
return a
}
diff --git a/deps/npm/test/tap/url-dependencies.js b/deps/npm/test/tap/url-dependencies.js
index 34a77f4bca..a77b3d380d 100644
--- a/deps/npm/test/tap/url-dependencies.js
+++ b/deps/npm/test/tap/url-dependencies.js
@@ -3,9 +3,6 @@ var rimraf = require("rimraf")
var path = require("path")
var osenv = require("osenv")
var mr = require("npm-registry-mock")
-var spawn = require("child_process").spawn
-var npm = require.resolve("../../bin/npm-cli.js")
-var node = process.execPath
var pkg = path.resolve(__dirname, "url-dependencies")
var common = require("../common-tap")
@@ -15,10 +12,10 @@ var mockRoutes = {
}
}
-test("url-dependencies: download first time", function(t) {
+test("url-dependencies: download first time", function (t) {
cleanup()
- performInstall(function(output){
+ performInstall(t, function (output){
if (!tarballWasFetched(output)){
t.fail("Tarball was not fetched")
} else {
@@ -28,11 +25,11 @@ test("url-dependencies: download first time", function(t) {
})
})
-test("url-dependencies: do not download subsequent times", function(t) {
+test("url-dependencies: do not download subsequent times", function (t) {
cleanup()
- performInstall(function(){
- performInstall(function(output){
+ performInstall(t, function () {
+ performInstall(t, function (output) {
if (tarballWasFetched(output)){
t.fail("Tarball was fetched second time around")
} else {
@@ -47,28 +44,25 @@ function tarballWasFetched(output){
return output.indexOf("http fetch GET " + common.registry + "/underscore/-/underscore-1.3.1.tgz") > -1
}
-function performInstall (cb) {
- mr({port: common.port, mocks: mockRoutes}, function(s){
- var output = ""
- , child = spawn(node, [npm, "install"], {
- cwd: pkg,
- env: {
- "npm_config_registry": common.registry,
- "npm_config_cache_lock_stale": 1000,
- "npm_config_cache_lock_wait": 1000,
- "npm_config_loglevel": "http",
- HOME: process.env.HOME,
- Path: process.env.PATH,
- PATH: process.env.PATH
- }
- })
-
- child.stderr.on("data", function(data){
- output += data.toString()
- })
- child.on("close", function () {
+function performInstall (t, cb) {
+ mr({port: common.port, mocks: mockRoutes}, function (s) {
+ var opts = {
+ cwd : pkg,
+ env: {
+ "npm_config_registry": common.registry,
+ "npm_config_cache_lock_stale": 1000,
+ "npm_config_cache_lock_wait": 1000,
+ "npm_config_loglevel": "http",
+ HOME: process.env.HOME,
+ Path: process.env.PATH,
+ PATH: process.env.PATH
+ }
+ }
+ common.npm(["install"], opts, function (err, code, stdout, stderr) {
+ t.ifError(err, "install success")
+ t.notOk(code, "npm install exited with code 0")
s.close()
- cb(output)
+ cb(stderr)
})
})
}
diff --git a/deps/npm/test/tap/version-no-git.js b/deps/npm/test/tap/version-no-git.js
new file mode 100644
index 0000000000..e5a5d23467
--- /dev/null
+++ b/deps/npm/test/tap/version-no-git.js
@@ -0,0 +1,54 @@
+var common = require("../common-tap.js")
+var test = require("tap").test
+var npm = require("../../")
+var osenv = require("osenv")
+var path = require("path")
+var fs = require("fs")
+var mkdirp = require("mkdirp")
+var rimraf = require("rimraf")
+var requireInject = require("require-inject")
+
+var pkg = path.resolve(__dirname, "version-no-git")
+var cache = path.resolve(pkg, "cache")
+var gitDir = path.resolve(pkg, ".git")
+
+test("npm version <semver> in a git repo without the git binary", function(t) {
+ setup()
+ npm.load({cache: cache, registry: common.registry}, function() {
+ var version = requireInject("../../lib/version", {
+ which: function(cmd, cb) {
+ process.nextTick(function() {
+ cb(new Error('ENOGIT!'))
+ })
+ }
+ })
+
+ version(["patch"], function(err) {
+ if (err) return t.fail("Error performing version patch")
+ var p = path.resolve(pkg, "package")
+ var testPkg = require(p)
+ t.equal("0.0.1", testPkg.version, "\"" + testPkg.version+"\" === \"0.0.1\"")
+ t.end()
+ })
+ })
+})
+
+test("cleanup", function(t) {
+ process.chdir(osenv.tmpdir())
+
+ rimraf.sync(pkg)
+ t.end()
+})
+
+function setup() {
+ mkdirp.sync(pkg)
+ mkdirp.sync(cache)
+ mkdirp.sync(gitDir)
+ fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({
+ author: "Terin Stock",
+ name: "version-no-git-test",
+ version: "0.0.0",
+ description: "Test for npm version if git binary doesn't exist"
+ }), "utf8")
+ process.chdir(pkg)
+}
diff --git a/deps/npm/test/tap/version-no-tags.js b/deps/npm/test/tap/version-no-tags.js
index e731c31544..cb6f195f8b 100644
--- a/deps/npm/test/tap/version-no-tags.js
+++ b/deps/npm/test/tap/version-no-tags.js
@@ -1,49 +1,47 @@
-var common = require('../common-tap.js')
-var test = require('tap').test
-var npm = require('../../')
-var npmc = require.resolve('../../')
-var osenv = require('osenv')
-var path = require('path')
-var fs = require('fs')
-var rimraf = require('rimraf')
-var mkdirp = require('mkdirp')
-var which = require('which')
-var util = require('util')
-var spawn = require('child_process').spawn
-var args = [ npmc
- , 'version'
- , 'patch'
- , '--no-git-tag-version'
- ]
-var pkg = __dirname + '/version-no-tags'
+var common = require("../common-tap.js")
+var test = require("tap").test
+var npm = require("../../")
+var osenv = require("osenv")
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var which = require("which")
+var spawn = require("child_process").spawn
+
+var pkg = path.resolve(__dirname, "version-no-tags")
+var cache = path.resolve(pkg, "cache")
test("npm version <semver> without git tag", function (t) {
setup()
- npm.load({ cache: pkg + '/cache', registry: common.registry}, function () {
- which('git', function(err, git) {
+ npm.load({ cache: cache, registry: common.registry}, function () {
+ which("git", function (err, git) {
+ t.ifError(err, "git found on system")
function tagExists(tag, _cb) {
- var child = spawn(git, ['tag', '-l', tag])
- var out = ''
- child.stdout.on('data', function(d) {
- out += data.toString()
+ var child1 = spawn(git, ["tag", "-l", tag])
+ var out = ""
+ child1.stdout.on("data", function (d) {
+ out += d.toString()
})
- child.on('exit', function() {
+ child1.on("exit", function () {
return _cb(null, Boolean(~out.indexOf(tag)))
})
}
- var child = spawn(git, ['init'])
- child.stdout.pipe(process.stdout)
- child.on('exit', function() {
- npm.config.set('git-tag-version', false)
- npm.commands.version(['patch'], function(err) {
- if (err) return t.fail('Error perform version patch')
- var testPkg = require(pkg+'/package')
- if (testPkg.version !== '0.0.1') t.fail(testPkg.version+' !== \'0.0.1\'')
- t.ok('0.0.1' === testPkg.version)
- tagExists('v0.0.1', function(err, exists) {
- t.equal(exists, false, 'git tag DOES exist')
- t.pass('git tag does not exist')
+ var child2 = spawn(git, ["init"])
+ child2.stdout.pipe(process.stdout)
+ child2.on("exit", function () {
+ npm.config.set("git-tag-version", false)
+ npm.commands.version(["patch"], function (err) {
+ if (err) return t.fail("Error perform version patch")
+ var p = path.resolve(pkg, "package")
+ var testPkg = require(p)
+ if (testPkg.version !== "0.0.1") t.fail(testPkg.version+" !== \"0.0.1\"")
+ t.equal("0.0.1", testPkg.version)
+ tagExists("v0.0.1", function (err, exists) {
+ t.ifError(err, "tag found to exist")
+ t.equal(exists, false, "git tag DOES exist")
+ t.pass("git tag does not exist")
t.end()
})
})
@@ -52,7 +50,7 @@ test("npm version <semver> without git tag", function (t) {
})
})
-test('cleanup', function(t) {
+test("cleanup", function (t) {
// windows fix for locked files
process.chdir(osenv.tmpdir())
@@ -62,12 +60,12 @@ test('cleanup', function(t) {
function setup() {
mkdirp.sync(pkg)
- mkdirp.sync(pkg + '/cache')
- fs.writeFileSync(pkg + '/package.json', JSON.stringify({
+ mkdirp.sync(cache)
+ fs.writeFileSync(path.resolve(pkg, "package.json"), JSON.stringify({
author: "Evan Lucas",
name: "version-no-tags-test",
version: "0.0.0",
description: "Test for git-tag-version flag"
- }), 'utf8')
+ }), "utf8")
process.chdir(pkg)
}
diff --git a/deps/npm/test/tap/view.js b/deps/npm/test/tap/view.js
new file mode 100644
index 0000000000..c36abfe1f6
--- /dev/null
+++ b/deps/npm/test/tap/view.js
@@ -0,0 +1,253 @@
+var common = require("../common-tap.js")
+var test = require("tap").test
+var osenv = require("osenv")
+var path = require("path")
+var fs = require("fs")
+var rimraf = require("rimraf")
+var mkdirp = require("mkdirp")
+var tmp = osenv.tmpdir()
+var t1dir = path.resolve(tmp, "view-local-no-pkg")
+var t2dir = path.resolve(tmp, "view-local-notmine")
+var t3dir = path.resolve(tmp, "view-local-mine")
+var mr = require("npm-registry-mock")
+
+test("setup", function (t) {
+ mkdirp.sync(t1dir)
+ mkdirp.sync(t2dir)
+ mkdirp.sync(t3dir)
+
+ fs.writeFileSync(t2dir + "/package.json", JSON.stringify({
+ author: "Evan Lucas"
+ , name: "test-repo-url-https"
+ , version: "0.0.1"
+ }), "utf8")
+
+ fs.writeFileSync(t3dir + "/package.json", JSON.stringify({
+ author: "Evan Lucas"
+ , name: "biscuits"
+ , version: "0.0.1"
+ }), "utf8")
+
+ t.pass("created fixtures")
+ t.end()
+})
+
+test("npm view . in global mode", function (t) {
+ process.chdir(t1dir)
+ common.npm([
+ "view"
+ , "."
+ , "--registry=" + common.registry
+ , "--global"
+ ], { cwd: t1dir }, function (err, code, stdout, stderr) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 1, "exit not ok")
+ t.similar(stderr, /Cannot use view command in global mode./m)
+ t.end()
+ })
+})
+
+test("npm view --global", function(t) {
+ process.chdir(t1dir)
+ common.npm([
+ "view"
+ , "--registry=" + common.registry
+ , "--global"
+ ], { cwd: t1dir }, function(err, code, stdout, stderr) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 1, "exit not ok")
+ t.similar(stderr, /Cannot use view command in global mode./m)
+ t.end()
+ })
+})
+
+test("npm view . with no package.json", function(t) {
+ process.chdir(t1dir)
+ common.npm([
+ "view"
+ , "."
+ , "--registry=" + common.registry
+ ], { cwd: t1dir }, function (err, code, stdout, stderr) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 1, "exit not ok")
+ t.similar(stderr, /Invalid package.json/m)
+ t.end()
+ })
+})
+
+test("npm view . with no published package", function (t) {
+ process.chdir(t3dir)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "."
+ , "--registry=" + common.registry
+ ], { cwd: t3dir }, function (err, code, stdout, stderr) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 1, "exit not ok")
+ t.similar(stderr, /version not found/m)
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view .", function (t) {
+ process.chdir(t2dir)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "."
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ var re = new RegExp("name: 'test-repo-url-https'")
+ t.similar(stdout, re)
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view . select fields", function (t) {
+ process.chdir(t2dir)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "."
+ , "main"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ t.equal(stdout.trim(), "index.js", "should print `index.js`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view .@<version>", function (t) {
+ process.chdir(t2dir)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , ".@0.0.0"
+ , "version"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ t.equal(stdout.trim(), "0.0.0", "should print `0.0.0`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view .@<version> --json", function (t) {
+ process.chdir(t2dir)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , ".@0.0.0"
+ , "version"
+ , "--json"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ t.equal(stdout.trim(), "\"0.0.0\"", "should print `\"0.0.0\"`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view <package name>", function (t) {
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "underscore"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ var re = new RegExp("name: 'underscore'")
+ t.similar(stdout, re, "should have name `underscore`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view <package name> --global", function(t) {
+ mr(common.port, function(s) {
+ common.npm([
+ "view"
+ , "underscore"
+ , "--global"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function(err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ var re = new RegExp("name: 'underscore'")
+ t.similar(stdout, re, "should have name `underscore`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("npm view <package name> --json", function(t) {
+ t.plan(3)
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "underscore"
+ , "--json"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ s.close()
+ try {
+ var out = JSON.parse(stdout.trim())
+ t.similar(out, {
+ maintainers: "jashkenas <jashkenas@gmail.com>"
+ }, "should have the same maintainer")
+ }
+ catch (er) {
+ t.fail("Unable to parse JSON")
+ }
+ })
+ })
+})
+
+test("npm view <package name> <field>", function (t) {
+ mr(common.port, function (s) {
+ common.npm([
+ "view"
+ , "underscore"
+ , "homepage"
+ , "--registry=" + common.registry
+ ], { cwd: t2dir }, function (err, code, stdout) {
+ t.ifError(err, "view command finished successfully")
+ t.equal(code, 0, "exit ok")
+ t.equal(stdout.trim(), "http://underscorejs.org",
+ "homepage should equal `http://underscorejs.org`")
+ s.close()
+ t.end()
+ })
+ })
+})
+
+test("cleanup", function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(t1dir)
+ rimraf.sync(t2dir)
+ rimraf.sync(t3dir)
+ t.pass("cleaned up")
+ t.end()
+})
diff --git a/deps/npm/test/tap/zz-cleanup.js b/deps/npm/test/tap/zz-cleanup.js
new file mode 100644
index 0000000000..7167537e06
--- /dev/null
+++ b/deps/npm/test/tap/zz-cleanup.js
@@ -0,0 +1,15 @@
+var common = require("../common-tap")
+var test = require("tap").test
+var fs = require("fs")
+
+test("cleanup", function (t) {
+ var res = common.deleteNpmCacheRecursivelySync()
+ t.equal(res, 0, "Deleted test npm cache successfully")
+
+ // ensure cache is clean
+ fs.readdir(common.npm_config_cache, function (err) {
+ t.ok(err, "error expected")
+ t.equal(err.code, "ENOENT", "npm cache directory no longer exists")
+ t.end()
+ })
+})