diff options
author | Daniel Lupu <lupu.daniel.f@gmail.com> | 2016-04-26 02:11:38 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2016-05-13 04:37:21 +0300 |
commit | d0c6d194471be8ce3e7b41b744b24f63dd1a3f6f (patch) | |
tree | a2215729859e6a621b13c5d4976a04aa7bf299c1 /test | |
parent | 8a81ff1ef3c2a8aae45368b3b75f2359f4dacd4b (diff) |
extract: Propagate read-package-tree errors for bundled dependencies
This protects against a crasher when a bundled dep is missing a package.json
(or index.js with embedded package.json data).
PR-URL: https://github.com/npm/npm/pull/12476
Credit: @dflupu
Diffstat (limited to 'test')
-rw-r--r-- | test/tap/bundled-dependencies-no-pkgjson.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/tap/bundled-dependencies-no-pkgjson.js b/test/tap/bundled-dependencies-no-pkgjson.js new file mode 100644 index 000000000..44eb47a03 --- /dev/null +++ b/test/tap/bundled-dependencies-no-pkgjson.js @@ -0,0 +1,47 @@ +var test = require('tap').test +var path = require('path') +var fs = require('graceful-fs') + +var mkdirp = require('mkdirp') +var rimraf = require('rimraf') +var common = require('../common-tap.js') + +var dir = path.resolve(__dirname, 'bundled-dependencies-no-pkgjson') +var pkg = path.resolve(dir, 'pkg-with-bundled-dep') +var dep = path.resolve(pkg, 'node_modules', 'a-bundled-dep') + +var pkgJson = JSON.stringify({ + name: 'pkg-with-bundled-dep', + version: '1.0.0', + dependencies: { + }, + bundledDependencies: [ + 'a-bundled-dep' + ] +}, null, 2) + '\n' + +test('setup', function (t) { + mkdirp.sync(path.join(dir, 'node_modules')) + mkdirp.sync(dep) + + fs.writeFileSync(path.resolve(pkg, 'package.json'), pkgJson) + fs.writeFileSync(path.resolve(dep, 'index.js'), '') + t.end() +}) + +test('proper error on bundled dep with no package.json', function (t) { + t.plan(3) + var npmArgs = ['install', './' + path.basename(pkg)] + + common.npm(npmArgs, { cwd: dir }, function (err, code, stdout, stderr) { + t.ifError(err, 'npm ran without issue') + t.notEqual(code, 0) + t.like(stderr, /ENOENT/, 'ENOENT should be in stderr') + t.end() + }) +}) + +test('cleanup', function (t) { + rimraf.sync(dir) + t.end() +}) |