summaryrefslogtreecommitdiff
path: root/deps/npm/test
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/test')
-rw-r--r--deps/npm/test/tap/bundled-transitive-deps.js83
-rw-r--r--deps/npm/test/tap/check-install-self.js13
-rw-r--r--deps/npm/test/tap/ignore-scripts.js8
-rw-r--r--deps/npm/test/tap/install-actions.js25
-rw-r--r--deps/npm/test/tap/install-order.js35
-rw-r--r--deps/npm/test/tap/outdated-bad-read-tree.js21
-rw-r--r--deps/npm/test/tap/progress-config.js45
-rw-r--r--deps/npm/test/tap/shared-linked.js152
-rw-r--r--deps/npm/test/tap/shrinkwrap-lifecycle.js55
-rw-r--r--deps/npm/test/tap/unit-deps-childDependencySpecifier.js56
-rw-r--r--deps/npm/test/tap/unit-deps-removeObsoleteDep.js2
-rw-r--r--deps/npm/test/tap/unit-deps-replaceModule.js41
12 files changed, 480 insertions, 56 deletions
diff --git a/deps/npm/test/tap/bundled-transitive-deps.js b/deps/npm/test/tap/bundled-transitive-deps.js
new file mode 100644
index 0000000000..4aefe5b9cc
--- /dev/null
+++ b/deps/npm/test/tap/bundled-transitive-deps.js
@@ -0,0 +1,83 @@
+'use strict'
+var fs = require('fs')
+var path = require('path')
+var test = require('tap').test
+var Tacks = require('tacks')
+var File = Tacks.File
+var Dir = Tacks.Dir
+var common = require('../common-tap.js')
+var npm = require('../../lib/npm.js')
+var tar = require('../../lib/utils/tar.js')
+
+var testdir = path.join(__dirname, path.basename(__filename, '.js'))
+var packed = path.join(testdir, 'packed')
+
+var fixture = new Tacks(
+ Dir({
+ 'package.json': File({
+ name: 'bundled-transitive-deps',
+ version: '1.0.0',
+ dependencies: {
+ 'a': '1.0.0'
+ },
+ bundleDependencies: [
+ 'a'
+ ]
+ }),
+ node_modules: Dir({
+ 'a': Dir({
+ 'package.json': File({
+ name: 'a',
+ version: '1.0.0',
+ dependencies: {
+ 'b': '1.0.0'
+ }
+ })
+ }),
+ 'b': Dir({
+ 'package.json': File({
+ name: 'b',
+ version: '1.0.0'
+ })
+ })
+ })
+ })
+)
+
+function setup () {
+ cleanup()
+ fixture.create(testdir)
+}
+
+function cleanup () {
+ fixture.remove(testdir)
+}
+
+test('setup', function (t) {
+ setup()
+ npm.load({}, t.end)
+})
+
+test('bundled-transitive-deps', function (t) {
+ common.npm(['pack'], {cwd: testdir}, thenCheckPack)
+ function thenCheckPack (err, code, stdout, stderr) {
+ if (err) throw err
+ var tarball = stdout.trim()
+ t.comment(stderr.trim())
+ t.is(code, 0, 'pack successful')
+ tar.unpack(path.join(testdir, tarball), packed, thenCheckContents)
+ }
+ function thenCheckContents (err) {
+ t.ifError(err, 'unpack successful')
+ var transitivePackedDep = path.join(packed, 'node_modules', 'b')
+ t.doesNotThrow(transitivePackedDep + ' exists', function () {
+ fs.statSync(transitivePackedDep)
+ })
+ t.end()
+ }
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
diff --git a/deps/npm/test/tap/check-install-self.js b/deps/npm/test/tap/check-install-self.js
index 821d8eb4d4..2cde1606a9 100644
--- a/deps/npm/test/tap/check-install-self.js
+++ b/deps/npm/test/tap/check-install-self.js
@@ -22,19 +22,22 @@ test('setup', function (t) {
t.end()
})
-var INSTALL_OPTS = ['--loglevel', 'silent']
var EXEC_OPTS = {cwd: installIn}
test('install self', function (t) {
- common.npm(['install', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
- t.ifError(err, 'npm ran without issue')
+ common.npm(['install', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.comment(stdout.trim())
+ t.comment(stderr.trim())
t.is(code, 1, 'npm install refused to install a package in itself')
t.end()
})
})
test('force install self', function (t) {
- common.npm(['install', '--force', installFrom].concat(INSTALL_OPTS), EXEC_OPTS, function (err, code) {
- t.ifError(err, 'npm ran without issue')
+ common.npm(['install', '--force', installFrom], EXEC_OPTS, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.comment(stdout.trim())
+ t.comment(stderr.trim())
t.is(code, 0, 'npm install happily installed a package in itself with --force')
t.end()
})
diff --git a/deps/npm/test/tap/ignore-scripts.js b/deps/npm/test/tap/ignore-scripts.js
index 8c0d350198..785921d7eb 100644
--- a/deps/npm/test/tap/ignore-scripts.js
+++ b/deps/npm/test/tap/ignore-scripts.js
@@ -40,7 +40,10 @@ var json = {
postrestart: 'exit 123',
preversion: 'exit 123',
version: 'exit 123',
- postversion: 'exit 123'
+ postversion: 'exit 123',
+ preshrinkwrap: 'exit 123',
+ shrinkwrap: 'exit 123',
+ postshrinkwrap: 'exit 123'
}
}
@@ -73,7 +76,8 @@ var scripts = [
'prestop', 'stop', 'poststop',
'prestart', 'start', 'poststart',
'prerestart', 'restart', 'postrestart',
- 'preversion', 'version', 'postversion'
+ 'preversion', 'version', 'postversion',
+ 'preshrinkwrap', 'shrinkwrap', 'postshrinkwrap'
]
scripts.forEach(function (script) {
diff --git a/deps/npm/test/tap/install-actions.js b/deps/npm/test/tap/install-actions.js
index c71b0044e1..ad75cacb5e 100644
--- a/deps/npm/test/tap/install-actions.js
+++ b/deps/npm/test/tap/install-actions.js
@@ -20,7 +20,7 @@ test('setup', function (t) {
test('->optdep:a->dep:b', function (t) {
var moduleA = {
name: 'a',
- path: '/',
+ path: '/a',
package: {
scripts: {
postinstall: 'false'
@@ -28,11 +28,12 @@ test('->optdep:a->dep:b', function (t) {
dependencies: {
b: '*'
}
- }
+ },
+ isTop: true
}
var moduleB = {
name: 'b',
- path: '/',
+ path: '/b',
package: {},
requires: [],
requiredBy: [moduleA]
@@ -47,13 +48,16 @@ test('->optdep:a->dep:b', function (t) {
}
},
children: [moduleA, moduleB],
- requires: [moduleA]
+ requires: [moduleA],
+ isTop: true
}
moduleA.requiredBy = [tree]
+ moduleA.parent = tree
+ moduleB.parent = tree
t.plan(3)
actions.postinstall('/', '/', moduleA, mockLog, function (er) {
- t.ok(er && er.code === 'ELIFECYCLE', 'Lifecycle failed')
+ t.is(er && er.code, 'ELIFECYCLE', 'Lifecycle failed')
t.ok(moduleA.failed, 'moduleA (optional dep) is marked failed')
t.ok(moduleB.failed, 'moduleB (direct dep of moduleA) is marked as failed')
t.end()
@@ -71,14 +75,16 @@ test('->dep:b,->optdep:a->dep:b', function (t) {
dependencies: {
b: '*'
}
- }
+ },
+ isTop: false
}
var moduleB = {
name: 'b',
path: '/',
package: {},
requires: [],
- requiredBy: [moduleA]
+ requiredBy: [moduleA],
+ isTop: false
}
moduleA.requires = [moduleB]
@@ -93,10 +99,13 @@ test('->dep:b,->optdep:a->dep:b', function (t) {
}
},
children: [moduleA, moduleB],
- requires: [moduleA, moduleB]
+ requires: [moduleA, moduleB],
+ isTop: true
}
moduleA.requiredBy = [tree]
moduleB.requiredBy.push(tree)
+ moduleA.parent = tree
+ moduleB.parent = tree
t.plan(3)
actions.postinstall('/', '/', moduleA, mockLog, function (er) {
diff --git a/deps/npm/test/tap/install-order.js b/deps/npm/test/tap/install-order.js
index c1c4e9dca6..80b3f6f45e 100644
--- a/deps/npm/test/tap/install-order.js
+++ b/deps/npm/test/tap/install-order.js
@@ -1,15 +1,42 @@
'use strict'
var test = require('tap').test
var sortActions = require('../../lib/install/diff-trees.js').sortActions
-
+var top = {
+ location: '/',
+ package: {},
+ requiredBy: [],
+ requires: [a, b],
+ isTop: true
+}
var a = {
- package: {_location: '/a', _requiredBy: []}
+ location: '/a',
+ package: {},
+ requiredBy: [],
+ requires: [c],
+ isTop: false,
+ userRequired: false,
+ existing: false,
+ parent: top
}
var b = {
- package: {_location: '/b', _requiredBy: []}
+ location: '/b',
+ package: {},
+ requiredBy: [],
+ requires: [c],
+ isTop: false,
+ userRequired: false,
+ existing: false,
+ parent: top
}
var c = {
- package: {_location: '/c', _requiredBy: ['/a', '/b']}
+ location: '/c',
+ package: {},
+ requiredBy: [a, b],
+ requires: [],
+ isTop: false,
+ userRequired: false,
+ existing: false,
+ parent: top
}
test('install-order when installing deps', function (t) {
diff --git a/deps/npm/test/tap/outdated-bad-read-tree.js b/deps/npm/test/tap/outdated-bad-read-tree.js
new file mode 100644
index 0000000000..eb4bac36ef
--- /dev/null
+++ b/deps/npm/test/tap/outdated-bad-read-tree.js
@@ -0,0 +1,21 @@
+'use strict'
+var test = require('tap').test
+var requireInject = require('require-inject')
+var npm = require('../../lib/npm.js')
+
+test('setup', function (t) {
+ npm.load({progress: false}, t.end)
+})
+
+test('outdated', function (t) {
+ var rptError = new Error('read-package-tree')
+ var outdated = requireInject('../../lib/outdated.js', {
+ 'read-package-tree': function (dir, cb) {
+ cb(rptError)
+ }
+ })
+ outdated([], function (err) {
+ t.is(err, rptError)
+ t.end()
+ })
+})
diff --git a/deps/npm/test/tap/progress-config.js b/deps/npm/test/tap/progress-config.js
index 634c9e8596..94d9b15f1b 100644
--- a/deps/npm/test/tap/progress-config.js
+++ b/deps/npm/test/tap/progress-config.js
@@ -13,19 +13,22 @@ var requireInject = require('require-inject')
// Make sure existing environment vars don't muck up the test
process.env = {}
-
-function hasOnlyAscii (s) {
- return /^[\000-\177]*$/.test(s)
-}
+// Pretend that stderr is a tty regardless, so we can get consistent
+// results.
+process.stderr.isTTY = true
test('setup', function (t) {
fs.writeFileSync(configName, '')
t.done()
})
+function getFreshNpm () {
+ return requireInject.withEmptyCache('../../lib/npm.js', {npmlog: log})
+}
+
test('disabled', function (t) {
t.plan(1)
- var npm = requireInject('../../lib/npm.js', {})
+ var npm = getFreshNpm()
npm.load({userconfig: configName, progress: false}, function () {
t.is(log.progressEnabled, false, 'should be disabled')
})
@@ -33,7 +36,7 @@ test('disabled', function (t) {
test('enabled', function (t) {
t.plan(1)
- var npm = requireInject('../../lib/npm.js', {})
+ var npm = getFreshNpm()
npm.load({userconfig: configName, progress: true}, function () {
t.is(log.progressEnabled, true, 'should be enabled')
})
@@ -41,7 +44,7 @@ test('enabled', function (t) {
test('default', function (t) {
t.plan(1)
- var npm = requireInject('../../lib/npm.js', {})
+ var npm = getFreshNpm()
npm.load({userconfig: configName}, function () {
t.is(log.progressEnabled, true, 'should be enabled')
})
@@ -49,41 +52,37 @@ test('default', function (t) {
test('default-travis', function (t) {
t.plan(1)
- global.process.env.TRAVIS = 'true'
- var npm = requireInject('../../lib/npm.js', {})
+ process.env.TRAVIS = 'true'
+ var npm = getFreshNpm()
npm.load({userconfig: configName}, function () {
t.is(log.progressEnabled, false, 'should be disabled')
- delete global.process.env.TRAVIS
+ delete process.env.TRAVIS
})
})
test('default-ci', function (t) {
t.plan(1)
- global.process.env.CI = 'true'
- var npm = requireInject('../../lib/npm.js', {})
+ process.env.CI = 'true'
+ var npm = getFreshNpm()
npm.load({userconfig: configName}, function () {
t.is(log.progressEnabled, false, 'should be disabled')
- delete global.process.env.CI
+ delete process.env.CI
})
})
test('unicode-true', function (t) {
- t.plan(6)
- var npm = requireInject('../../lib/npm.js', {})
+ var npm = getFreshNpm()
npm.load({userconfig: configName, unicode: true}, function () {
- Object.keys(log.gauge.theme).forEach(function (key) {
- t.notOk(hasOnlyAscii(log.gauge.theme[key]), 'only unicode')
- })
+ t.is(log.gauge._theme.hasUnicode, true, 'unicode will be selected')
+ t.done()
})
})
test('unicode-false', function (t) {
- t.plan(6)
- var npm = requireInject('../../lib/npm.js', {})
+ var npm = getFreshNpm()
npm.load({userconfig: configName, unicode: false}, function () {
- Object.keys(log.gauge.theme).forEach(function (key) {
- t.ok(hasOnlyAscii(log.gauge.theme[key]), 'only ASCII')
- })
+ t.is(log.gauge._theme.hasUnicode, false, 'unicode will NOT be selected')
+ t.done()
})
})
diff --git a/deps/npm/test/tap/shared-linked.js b/deps/npm/test/tap/shared-linked.js
new file mode 100644
index 0000000000..63c2538da1
--- /dev/null
+++ b/deps/npm/test/tap/shared-linked.js
@@ -0,0 +1,152 @@
+'use strict'
+var path = require('path')
+var test = require('tap').test
+var Tacks = require('tacks')
+var File = Tacks.File
+var Symlink = Tacks.Symlink
+var Dir = Tacks.Dir
+var common = require('../common-tap.js')
+var mr = require('npm-registry-mock')
+var extend = Object.assign || require('util')._extend
+
+var testdir = path.join(__dirname, path.basename(__filename, '.js'))
+var bugdir = path.join(testdir, 'modules', 'bug')
+
+// This is an absolutely minimal version of the optimist included with
+// npm-registry-mock.
+var optimist = Dir({
+ 'package.json': File({
+ dependencies: {
+ minimist: '~0.0.1',
+ wordwrap: '~0.0.2'
+ },
+ name: 'optimist',
+ version: '0.6.0'
+ }),
+ node_modules: Dir({
+ minimist: Dir({
+ 'package.json': File({
+ _shasum: 'd7aa327bcecf518f9106ac6b8f003fa3bcea8566',
+ name: 'minimist',
+ version: '0.0.5'
+ })
+ }),
+ wordwrap: Dir({
+ 'package.json': File({
+ _shasum: 'b79669bb42ecb409f83d583cad52ca17eaa1643f',
+ name: 'wordwrap',
+ version: '0.0.2'
+ })
+ })
+ })
+})
+
+var fixture = new Tacks(
+ Dir({
+ cache: Dir({}),
+ global: Dir({
+ lib: Dir({
+ node_modules: Dir({
+ linked1: Symlink('../../../modules/linked1/'),
+ linked2: Symlink('../../../modules/linked2/')
+ })
+ })
+ }),
+ modules: Dir({
+ bug: Dir({
+ node_modules: Dir({
+ linked1: Symlink('../../../global/lib/node_modules/linked1'),
+ linked2: Symlink('../../../global/lib/node_modules/linked2')
+ }),
+ 'package.json': File({
+ name: 'bug',
+ version: '10800.0.0',
+ devDependencies: {
+ optimist: '0.6.0',
+ linked1: '^1.0.0',
+ linked2: '^1.0.0'
+ }
+ })
+ }),
+ linked1: Dir({
+ 'package.json': File({
+ name: 'linked1',
+ version: '1.0.0',
+ devDependencies: {
+ optimist: '0.6.0'
+ }
+ }),
+ node_modules: Dir({
+ optimist: optimist
+ })
+ }),
+ linked2: Dir({
+ 'package.json': File({
+ name: 'linked2',
+ version: '1.0.0',
+ devDependencies: {
+ optimist: '0.6.0',
+ linked1: '^1.0.0'
+ }
+ }),
+ node_modules: Dir({
+ linked1: Symlink('../../../global/lib/node_modules/linked1'),
+ optimist: optimist
+ })
+ })
+ })
+ })
+)
+
+function setup () {
+ cleanup()
+ fixture.create(testdir)
+}
+
+function cleanup () {
+ fixture.remove(testdir)
+}
+
+var server
+test('setup', function (t) {
+ setup()
+ mr({port: common.port}, function (er, s) {
+ t.ifError(er)
+ server = s
+ t.end()
+ })
+})
+
+test('shared-linked', function (t) {
+ var options = {
+ cwd: bugdir,
+ env: extend(extend({}, process.env), {
+ npm_config_prefix: path.join(testdir, 'global')
+ })
+ }
+ var config = [
+ '--cache', path.join(testdir, 'cache'),
+ '--registry', common.registry,
+ '--unicode', 'false'
+ ]
+
+ common.npm(config.concat(['install', '--dry-run']), options, function (err, code, stdout, stderr) {
+ if (err) throw err
+ t.is(code, 0)
+ var got = stdout.trim().replace(/\s+\n/g, '\n')
+ var expected =
+ 'bug@10800.0.0 ' + bugdir + '\n' +
+ '`-- optimist@0.6.0\n' +
+ ' +-- minimist@0.0.5\n' +
+ ' `-- wordwrap@0.0.2'
+ t.is(got, expected, 'just an optimist install please')
+ server.done()
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ if (server) server.close()
+ cleanup()
+ t.end()
+})
diff --git a/deps/npm/test/tap/shrinkwrap-lifecycle.js b/deps/npm/test/tap/shrinkwrap-lifecycle.js
new file mode 100644
index 0000000000..0e84259667
--- /dev/null
+++ b/deps/npm/test/tap/shrinkwrap-lifecycle.js
@@ -0,0 +1,55 @@
+var fs = require('graceful-fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+var pkg = path.resolve(__dirname, 'shrinkwrap-lifecycle')
+
+test('npm shrinkwrap execution order', function (t) {
+ setup()
+ fs.writeFileSync(path.resolve(pkg, 'package.json'), JSON.stringify({
+ author: 'Simen Bekkhus',
+ name: 'shrinkwrap-lifecycle',
+ shrinkwrap: '0.0.0',
+ description: 'Test for npm shrinkwrap execution order',
+ scripts: {
+ preshrinkwrap: 'echo this happens first',
+ shrinkwrap: 'echo this happens second',
+ postshrinkwrap: 'echo this happens third'
+ }
+ }), 'utf8')
+ common.npm(['shrinkwrap'], [], function (err, code, stdout) {
+ if (err) throw err
+
+ var indexOfFirst = stdout.indexOf('echo this happens first')
+ var indexOfSecond = stdout.indexOf('echo this happens second')
+ var indexOfThird = stdout.indexOf('wrote npm-shrinkwrap.json')
+ var indexOfFourth = stdout.indexOf('echo this happens third')
+
+ t.ok(indexOfFirst >= 0)
+ t.ok(indexOfSecond >= 0)
+ t.ok(indexOfThird >= 0)
+ t.ok(indexOfFourth >= 0)
+
+ t.ok(indexOfFirst < indexOfSecond)
+ t.ok(indexOfSecond < indexOfThird)
+ t.ok(indexOfThird < indexOfFourth)
+
+ t.end()
+ })
+})
+
+test('cleanup', function (t) {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+ t.end()
+})
+
+function setup () {
+ mkdirp.sync(pkg)
+ process.chdir(pkg)
+}
diff --git a/deps/npm/test/tap/unit-deps-childDependencySpecifier.js b/deps/npm/test/tap/unit-deps-childDependencySpecifier.js
new file mode 100644
index 0000000000..600b719fb2
--- /dev/null
+++ b/deps/npm/test/tap/unit-deps-childDependencySpecifier.js
@@ -0,0 +1,56 @@
+'use strict'
+var test = require('tap').test
+var requireInject = require('require-inject')
+var asap = require('asap')
+
+// we're just mocking to avoid having to call `npm.load`
+var deps = requireInject('../../lib/install/deps.js', {
+ '../../lib/npm.js': {
+ config: {
+ get: function () { return 'mock' }
+ }
+ }
+})
+
+var childDependencySpecifier = deps._childDependencySpecifier
+
+test('childDependencySpecifier', function (t) {
+ var tree = {
+ resolved: {},
+ package: {
+ name: 'bar',
+ _requested: ''
+ }
+ }
+
+ childDependencySpecifier(tree, 'foo', '^1.0.0', function () {
+ t.deepEqual(tree.resolved, {
+ foo: {
+ '^1.0.0': {
+ raw: 'foo@^1.0.0',
+ escapedName: 'foo',
+ scope: null,
+ name: 'foo',
+ rawSpec: '^1.0.0',
+ spec: '>=1.0.0 <2.0.0',
+ type: 'range'
+ }
+ }
+ }, 'should populate resolved')
+
+ var order = []
+
+ childDependencySpecifier(tree, 'foo', '^1.0.0', function () {
+ order.push(1)
+ childDependencySpecifier(tree, 'foo', '^1.0.0', function () {
+ order.push(3)
+ t.deepEqual(order, [1, 2, 3], 'should yield nested callbacks')
+ t.end()
+ })
+ })
+
+ asap(function () {
+ order.push(2)
+ })
+ })
+})
diff --git a/deps/npm/test/tap/unit-deps-removeObsoleteDep.js b/deps/npm/test/tap/unit-deps-removeObsoleteDep.js
index 2e34fd730f..8bba0d0da1 100644
--- a/deps/npm/test/tap/unit-deps-removeObsoleteDep.js
+++ b/deps/npm/test/tap/unit-deps-removeObsoleteDep.js
@@ -11,7 +11,7 @@ var deps = requireInject('../../lib/install/deps.js', {
}
})
-var removeObsoleteDep = deps._removeObsoleteDep
+var removeObsoleteDep = deps.removeObsoleteDep
test('removeObsoleteDep', function (t) {
var child1 = {requiredBy: []}
diff --git a/deps/npm/test/tap/unit-deps-replaceModule.js b/deps/npm/test/tap/unit-deps-replaceModule.js
index d38aa9985d..d5f0fdbf89 100644
--- a/deps/npm/test/tap/unit-deps-replaceModule.js
+++ b/deps/npm/test/tap/unit-deps-replaceModule.js
@@ -6,45 +6,60 @@ test('setup', function (t) {
npm.load({}, t.done)
})
-test('replaceModule', function (t) {
- var replaceModule = require('../../lib/install/deps')._replaceModule
+test('replaceModuleByName', function (t) {
+ var replaceModuleByName = require('../../lib/install/deps')._replaceModuleByName
var mods = []
for (var ii = 0; ii < 10; ++ii) {
- mods.push({package: {name: ii}})
+ mods.push({package: {name: ii}, path: '/path/to/' + ii})
}
var test = {}
test.A = mods.slice(0, 4)
- replaceModule(test, 'A', mods[2])
+ replaceModuleByName(test, 'A', mods[2])
t.isDeeply(test.A, mods.slice(0, 4), 'replacing an existing module leaves the order alone')
- replaceModule(test, 'A', mods[7])
+ replaceModuleByName(test, 'A', mods[7])
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends')
test.B = mods.slice(0, 4)
var replacement = {package: {name: 1}, isReplacement: true}
- replaceModule(test, 'B', replacement)
+ replaceModuleByName(test, 'B', replacement)
t.isDeeply(test.B, [mods[0], replacement, mods[2], mods[3]], 'replacing existing module swaps out for the new version')
- replaceModule(test, 'C', mods[7])
+ replaceModuleByName(test, 'C', mods[7])
t.isDeeply(test.C, [mods[7]], 'replacing when the key does not exist yet, causes its creation')
+
+ test.D = mods.slice(0, 4)
+ var duplicateByPath = {package: {name: 'dup'}, path: test.D[0].path}
+ replaceModuleByName(test, 'D', duplicateByPath)
+ t.isDeeply(test.D, mods.slice(0, 4).concat(duplicateByPath), 'replacing with a duplicate path but diff names appends')
t.end()
})
-test('replaceModuleName', function (t) {
- var replaceModuleName = require('../../lib/install/deps')._replaceModuleName
+test('replaceModuleByPath', function (t) {
+ var replaceModuleByPath = require('../../lib/install/deps')._replaceModuleByPath
var mods = []
for (var ii = 0; ii < 10; ++ii) {
- mods.push('pkg' + ii)
+ mods.push({package: {name: ii}, path: '/path/to/' + ii})
}
var test = {}
test.A = mods.slice(0, 4)
- replaceModuleName(test, 'A', mods[2])
+ replaceModuleByPath(test, 'A', mods[2])
t.isDeeply(test.A, mods.slice(0, 4), 'replacing an existing module leaves the order alone')
- replaceModuleName(test, 'A', mods[7])
+ replaceModuleByPath(test, 'A', mods[7])
t.isDeeply(test.A, mods.slice(0, 4).concat(mods[7]), 'replacing a new module appends')
- replaceModuleName(test, 'C', mods[7])
+ test.B = mods.slice(0, 4)
+ var replacement = {package: {name: 1}, isReplacement: true, path: '/path/to/1'}
+ replaceModuleByPath(test, 'B', replacement)
+ t.isDeeply(test.B, [mods[0], replacement, mods[2], mods[3]], 'replacing existing module swaps out for the new version')
+
+ replaceModuleByPath(test, 'C', mods[7])
t.isDeeply(test.C, [mods[7]], 'replacing when the key does not exist yet, causes its creation')
+
+ test.D = mods.slice(0, 4)
+ var duplicateByPath = {package: {name: 'dup'}, path: test.D[0].path}
+ replaceModuleByPath(test, 'D', duplicateByPath)
+ t.isDeeply(test.D, [duplicateByPath].concat(mods.slice(1, 4)), 'replacing with a duplicate path but diff names replaces')
t.end()
})