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:
authorMaximilian Antoni <mail@maxantoni.de>2015-10-07 16:17:23 +0300
committerRebecca Turner <me@re-becca.org>2015-10-09 02:24:37 +0300
commit87336c30a848f93d9503f00d9c4147a76e74cb3b (patch)
tree208eb628a7b3ee6bf6b2f1728474686807107593 /test
parent3c44763b40f3e93978c10f6d2e6c60dd2feca51d (diff)
shrinkwrap: do not fail on optional dependencies
If an optional dependency was not installed, shrinkwrap fails with a message saying that a required dependency is missing. This patch checks whether a missing dependency was listed in the optionalDependencies. PR-URL: https://github.com/npm/npm/pull/9879
Diffstat (limited to 'test')
-rw-r--r--test/tap/shrinkwrap-optional-dependency.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/test/tap/shrinkwrap-optional-dependency.js b/test/tap/shrinkwrap-optional-dependency.js
new file mode 100644
index 000000000..c083e9fe4
--- /dev/null
+++ b/test/tap/shrinkwrap-optional-dependency.js
@@ -0,0 +1,102 @@
+var fs = require('fs')
+var path = require('path')
+
+var mkdirp = require('mkdirp')
+var mr = require('npm-registry-mock')
+var osenv = require('osenv')
+var rimraf = require('rimraf')
+var test = require('tap').test
+
+var common = require('../common-tap.js')
+var npm = npm = require('../../')
+
+var pkg = path.resolve(__dirname, 'shrinkwrap-optional-dependency')
+
+test('shrinkwrap does not fail on missing optional dependency', function (t) {
+ t.plan(1)
+
+ var mocks = {
+ get: {
+ '/random-package': [404, {}]
+ }
+ }
+
+ mr({port: common.port, mocks: mocks}, function (er, s) {
+
+ function fail (err) {
+ s.close() // Close on failure to allow node to exit
+ t.fail(err)
+ }
+
+ setup(function (err) {
+ if (err) return fail(err)
+
+ // Install without the optional dependency
+ npm.install('.', function (err) {
+ if (err) return fail(err)
+
+ // Pretend the optional dependency was specified, but somehow failed to load:
+ json.optionalDependencies = {
+ 'random-package': '0.0.0'
+ }
+ writePackage()
+
+ npm.commands.shrinkwrap([], true, function (err, results) {
+ if (err) return fail(err)
+
+ t.deepEqual(results, desired)
+ s.close()
+ t.end()
+ })
+ })
+ })
+ })
+})
+
+test('cleanup', function (t) {
+ cleanup()
+ t.end()
+})
+
+var desired = {
+ name: 'npm-test-shrinkwrap-optional-dependency',
+ version: '0.0.0',
+ dependencies: {
+ 'test-package': {
+ version: '0.0.0',
+ from: 'test-package@0.0.0',
+ resolved: common.registry + '/test-package/-/test-package-0.0.0.tgz'
+ }
+ }
+}
+
+var json = {
+ author: 'Maximilian Antoni',
+ name: 'npm-test-shrinkwrap-optional-dependency',
+ version: '0.0.0',
+ dependencies: {
+ 'test-package': '0.0.0'
+ }
+}
+
+function writePackage () {
+ fs.writeFileSync(path.join(pkg, 'package.json'), JSON.stringify(json, null, 2))
+}
+
+function setup (cb) {
+ cleanup()
+ mkdirp.sync(pkg)
+ writePackage()
+ process.chdir(pkg)
+
+ var opts = {
+ cache: path.resolve(pkg, 'cache'),
+ registry: common.registry
+ }
+ npm.load(opts, cb)
+}
+
+function cleanup () {
+ process.chdir(osenv.tmpdir())
+ rimraf.sync(pkg)
+}