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:
authorForrest L Norvell <forrest@npmjs.com>2014-09-13 09:49:32 +0400
committerForrest L Norvell <forrest@npmjs.com>2014-09-13 09:49:32 +0400
commita11c88bdb1488b87d8dcac69df9a55a7a91184b6 (patch)
treea26b29c1179408fead5c8df86a50f7a72d1b4b5f /test
parentf6187eb5454e5f232cfbc5c2a84ab322b87ef3cc (diff)
pack scoped packages correctly (fixes #6175)
Diffstat (limited to 'test')
-rw-r--r--test/tap/pack-scoped.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/test/tap/pack-scoped.js b/test/tap/pack-scoped.js
new file mode 100644
index 000000000..05a77a0f0
--- /dev/null
+++ b/test/tap/pack-scoped.js
@@ -0,0 +1,91 @@
+// verify that prepublish runs on pack and publish
+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, "scoped_package")
+var manifest = join(pkg, "package.json")
+var tmp = join(pkg, "tmp")
+var cache = join(pkg, "cache")
+
+var data = {
+ name : "@scope/generic-package",
+ version : "90000.100001.5"
+}
+
+test("setup", function (t) {
+ var n = 0
+
+ mkdirp(pkg, then())
+ mkdirp(cache, then())
+ mkdirp(tmp, then())
+
+ function then () {
+ n++
+ return function (er) {
+ if (er) throw er
+ if (--n === 0) next()
+ }
+ }
+
+ function next () {
+ fs.writeFile(manifest, JSON.stringify(data), "ascii", done)
+ }
+
+ function done (er) {
+ if (er) throw er
+
+ t.pass("setup done")
+ t.end()
+ }
+})
+
+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,
+ "npm_config_prefix" : pkg,
+ "npm_config_global" : "false"
+ }
+
+ for (var i in process.env) {
+ 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()
+ var regex = new RegExp("scope-generic-package-90000.100001.5.tgz", "ig")
+
+ t.ok(c.match(regex), "found package")
+ t.end()
+ }
+})
+
+test("cleanup", function (t) {
+ rimraf(pkg, function (er) {
+ if (er) throw er
+
+ t.pass("cleaned up")
+ t.end()
+ })
+})