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:
authorRebecca Turner <me@re-becca.org>2015-07-09 11:30:10 +0300
committerRebecca Turner <me@re-becca.org>2015-07-10 12:04:44 +0300
commit9babfd63f19f2d80b2d2624e0963b0bdb0d76ef4 (patch)
treecb024d5a14666c7344b1fd8a77c7035803c60871 /test
parent148a8c5b21ea6e8df793a8aa500bdedffde09d6e (diff)
install: uninstall: Limit global tree manipulation to named pkgs
PR-URL: https://github.com/npm/npm/pull/8876 Fixes: https://github.com/npm/npm/issues/8608
Diffstat (limited to 'test')
-rw-r--r--test/tap/no-scan-full-global-dir.js77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/tap/no-scan-full-global-dir.js b/test/tap/no-scan-full-global-dir.js
new file mode 100644
index 000000000..b03f4fa59
--- /dev/null
+++ b/test/tap/no-scan-full-global-dir.js
@@ -0,0 +1,77 @@
+'use strict'
+var test = require('tap').test
+var requireInject = require('require-inject')
+var path = require('path')
+var log = require('npmlog')
+var inherits = require('inherits')
+
+var packages = {
+ abc: {package: {name: 'abc'}, path: path.join(__dirname, 'node_modules', 'abc')},
+ def: {package: {name: 'def'}, path: path.join(__dirname, 'node_modules', 'def')},
+ ghi: {package: {name: 'ghi'}, path: path.join(__dirname, 'node_modules', 'ghi')},
+ jkl: {package: {name: 'jkl'}, path: path.join(__dirname, 'node_modules', 'jkl')}
+}
+var dir = {}
+dir[__dirname] ={ children: [ packages.abc, packages.def, packages.ghi, packages.jkl ] }
+dir[packages.abc.path] = packages.abc
+dir[packages.def.path] = packages.def
+dir[packages.ghi.path] = packages.ghi
+dir[packages.jkl.path] = packages.jkl
+
+var rpt = function (root, cb) {
+ cb(null, dir[root])
+}
+rpt.Node = function () {
+ this.children = []
+}
+
+var npm = requireInject.installGlobally('../../lib/npm.js', {
+ 'read-package-tree': rpt
+})
+
+test('setup', function (t) {
+ npm.load(function () {
+ t.pass('npm loaded')
+ t.end()
+ })
+})
+
+function loadArgMetadata (cb) {
+ this.args = this.args.map(function (arg) { return {name: arg} })
+ cb()
+}
+
+test('installer', function (t) {
+ t.plan(1)
+ var Installer = require('../../lib/install.js').Installer
+ var TestInstaller = function () {
+ Installer.apply(this, arguments)
+ this.global = true
+ }
+ inherits(TestInstaller, Installer)
+ TestInstaller.prototype.loadArgMetadata = loadArgMetadata
+
+ var inst = new TestInstaller(__dirname, false, ['def', 'abc'])
+ inst.loadCurrentTree(function () {
+ var kids = inst.currentTree.children.map(function (child) { return child.package.name })
+ t.isDeeply(kids, ['def', 'abc'])
+ t.end()
+ })
+})
+
+test('uninstaller', function (t) {
+ t.plan(1)
+ var Uninstaller = require('../../lib/uninstall.js').Uninstaller
+ var TestUninstaller = function () {
+ Uninstaller.apply(this, arguments)
+ this.global = true
+ }
+ inherits(TestUninstaller, Uninstaller)
+
+ var uninst = new TestUninstaller(__dirname, false, ['ghi', 'jkl'])
+ uninst.loadCurrentTree(function () {
+ var kids = uninst.currentTree.children.map(function (child) { return child.package.name })
+ t.isDeeply(kids, ['ghi', 'jkl'])
+ t.end()
+ })
+})