Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2014-08-30 03:21:34 +0400
committerForrest L Norvell <forrest@npmjs.com>2014-08-30 04:28:47 +0400
commit0dc6a07c778071c94c2251429c7d107e88a45095 (patch)
treec79fbd1e80450befc8e3a580a72bfda8328ff774 /test
parent65d2179af96737eb9038eaa24a293a62184aaa13 (diff)
Run commands in prefix, not cwd
In general, we should never be relying on {cwd}/package.json. The current working directory should be used for printing out relative paths for human consumption, but npm should always walk up the directory tree to find its working dir for *doing* stuff. Fix #6059
Diffstat (limited to 'test')
-rw-r--r--test/run.js5
-rw-r--r--test/tap/pwd-prefix.js35
2 files changed, 39 insertions, 1 deletions
diff --git a/test/run.js b/test/run.js
index a213afe7a..904df5b8e 100644
--- a/test/run.js
+++ b/test/run.js
@@ -81,7 +81,10 @@ function exec (cmd, cwd, shouldFail, cb) {
cmd = cmd.replace(/^npm /, npmReplace + " ")
cmd = cmd.replace(/^node /, nodeReplace + " ")
+ console.error("$$$$$$ cd %s; PATH=%s %s", cwd, env.PATH, cmd)
+
child_process.exec(cmd, {cwd: cwd, env: env}, function (er, stdout, stderr) {
+ console.error("$$$$$$ after command", cmd, cwd)
if (stdout) {
console.error(prefix(stdout, " 1> "))
}
@@ -155,7 +158,7 @@ function main (cb) {
return [ "npm install packages/"+p, testdir ]
}) ]
, [ execChain, packages.map(function (p) {
- return [ "npm test", path.resolve(base, p) ]
+ return [ "npm test -ddd", path.resolve(base, p) ]
}) ]
, [ execChain, packagesToRm.map(function (p) {
return [ "npm rm "+p, root ]
diff --git a/test/tap/pwd-prefix.js b/test/tap/pwd-prefix.js
new file mode 100644
index 000000000..e041552e7
--- /dev/null
+++ b/test/tap/pwd-prefix.js
@@ -0,0 +1,35 @@
+// This test ensures that a few commands do the same
+// thing when the cwd is where package.json is, and when
+// the package.json is one level up.
+
+var test = require("tap").test
+var common = require("../common-tap.js")
+var path = require("path")
+var root = path.resolve(__dirname, "../..")
+var lib = path.resolve(root, "lib")
+var commands = ["run", "version"]
+
+commands.forEach(function (cmd) {
+ // Should get the same stdout and stderr each time
+ var stdout, stderr
+
+ test(cmd + " in root", function (t) {
+ common.npm([cmd], {cwd: root}, function(er, code, so, se) {
+ if (er) throw er
+ t.equal(code, 0)
+ stdout = so
+ stderr = se
+ t.end()
+ })
+ })
+
+ test(cmd + " in lib", function (t) {
+ common.npm([cmd], {cwd: lib}, function(er, code, so, se) {
+ if (er) throw er
+ t.equal(code, 0)
+ t.equal(so, stdout)
+ t.equal(se, stderr)
+ t.end()
+ })
+ })
+})