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:
authorKarolis Narkevicius <karolis.n@gmail.com>2015-03-03 17:28:59 +0300
committerForrest L Norvell <forrest@npmjs.com>2015-03-05 12:14:11 +0300
commitc56cfcd79cd8ab4ccd06d2c03d7e04030d576683 (patch)
tree97b8c4270c640e49ece6669d5b0bb7d59fe0de68 /test
parent6823807bba6c00228a724e1205ae90d67df0adad (diff)
dedupe: Handle scoped packages
Diffstat (limited to 'test')
-rw-r--r--test/tap/dedupe-scoped.js71
-rw-r--r--test/tap/dedupe-scoped/package.json9
2 files changed, 80 insertions, 0 deletions
diff --git a/test/tap/dedupe-scoped.js b/test/tap/dedupe-scoped.js
new file mode 100644
index 000000000..a5962d8ea
--- /dev/null
+++ b/test/tap/dedupe-scoped.js
@@ -0,0 +1,71 @@
+var test = require("tap").test
+ , fs = require("fs")
+ , path = require("path")
+ , existsSync = fs.existsSync || path.existsSync
+ , rimraf = require("rimraf")
+ , mr = require("npm-registry-mock")
+ , common = require("../common-tap.js")
+
+var EXEC_OPTS = {}
+
+test("dedupe finds the common scoped modules and moves it up one level", function (t) {
+ setup(function (s) {
+ common.npm(
+ [
+ "install", ".",
+ "--registry", common.registry
+ ],
+ EXEC_OPTS,
+ function (err, code) {
+ scopePackages(function () {
+ 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-scoped", "node_modules", "minimist")))
+ t.ok(!existsSync(path.join(__dirname, "dedupe-scoped", "node_modules", "checker")))
+ s.close() // shutdown mock registry.
+ t.end()
+ })
+ })
+ })
+ })
+})
+
+function setup (cb) {
+ process.chdir(path.join(__dirname, "dedupe-scoped"))
+ mr({port : common.port}, function (er, s) { // create mock registry.
+ rimraf.sync(path.join(__dirname, "dedupe-scoped", "node_modules"))
+ fs.mkdirSync(path.join(__dirname, "dedupe-scoped", "node_modules"))
+ cb(s)
+ })
+}
+
+function scopePackages (cb) {
+ scopeAt("minimist", path.join(__dirname, "dedupe-scoped", "node_modules", "optimist"));
+ scopeAt("minimist", path.join(__dirname, "dedupe-scoped", "node_modules", "clean"));
+ cb();
+}
+
+function scopeAt(pkgName, targetPath) {
+ var pkg, p, p2;
+
+ p = path.join(targetPath, "package.json")
+ pkg = JSON.parse(fs.readFileSync(p).toString())
+ pkg.dependencies["@scoped/" + pkgName] = pkg.dependencies[pkgName]
+ delete pkg.dependencies[pkgName]
+ fs.writeFileSync(p, JSON.stringify(pkg, null, 2))
+
+ p = path.join(targetPath, "node_modules", pkgName, "package.json")
+ pkg = JSON.parse(fs.readFileSync(p).toString())
+ pkg.name = "@scoped/" + pkgName
+ fs.writeFileSync(p, JSON.stringify(pkg, null, 2))
+
+ p = path.join(targetPath, "node_modules", "@scoped")
+ fs.mkdirSync(p)
+
+ p = path.join(targetPath, "node_modules", pkgName)
+ p2 = path.join(targetPath, "node_modules", "@scoped", pkgName)
+ fs.renameSync(p, p2)
+} \ No newline at end of file
diff --git a/test/tap/dedupe-scoped/package.json b/test/tap/dedupe-scoped/package.json
new file mode 100644
index 000000000..842d4b2b2
--- /dev/null
+++ b/test/tap/dedupe-scoped/package.json
@@ -0,0 +1,9 @@
+{
+ "author": "Dedupe tester",
+ "name": "dedupe",
+ "version": "0.0.0",
+ "dependencies": {
+ "optimist": "0.6.0",
+ "clean": "2.1.6"
+ }
+}