• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var mr = require('npm-registry-mock')
6var osenv = require('osenv')
7var rimraf = require('rimraf')
8var test = require('tap').test
9
10var npm = require('../../')
11var common = require('../common-tap')
12
13var pkg = path.resolve(__dirname, 'peer-deps-invalid')
14var cache = path.resolve(pkg, 'cache')
15
16var json = {
17  author: 'Domenic Denicola <domenic@domenicdenicola.com> (http://domenicdenicola.com/)',
18  name: 'peer-deps-invalid',
19  version: '0.0.0',
20  dependencies: {
21    'npm-test-peer-deps-file': 'http://localhost:' + common.port + '/ok.js',
22    'npm-test-peer-deps-file-invalid': 'http://localhost:' + common.port + '/invalid.js'
23  }
24}
25
26var fileFail = function () {
27/**package
28* { "name": "npm-test-peer-deps-file-invalid"
29* , "main": "index.js"
30* , "version": "1.2.3"
31* , "description":"This one should conflict with the other one"
32* , "peerDependencies": { "underscore": "1.3.3" }
33* }
34**/
35  module.exports = 'I\'m just a lonely index, naked as the day I was born.'
36}.toString().split('\n').slice(1, -1).join('\n')
37
38var fileOK = function () {
39/**package
40* { "name": "npm-test-peer-deps-file"
41* , "main": "index.js"
42* , "version": "1.2.3"
43* , "description":"No package.json in sight!"
44* , "peerDependencies": { "underscore": "1.3.1" }
45* , "dependencies": { "mkdirp": "0.3.5" }
46* }
47**/
48  module.exports = 'I\'m just a lonely index, naked as the day I was born.'
49}.toString().split('\n').slice(1, -1).join('\n')
50
51test('setup', function (t) {
52  cleanup()
53  mkdirp.sync(cache)
54  fs.writeFileSync(
55    path.join(pkg, 'package.json'),
56    JSON.stringify(json, null, 2)
57  )
58  fs.writeFileSync(path.join(pkg, 'file-ok.js'), fileOK)
59  fs.writeFileSync(path.join(pkg, 'file-fail.js'), fileFail)
60
61  process.chdir(pkg)
62  t.end()
63})
64
65test('installing dependencies that have conflicting peerDependencies', function (t) {
66  var customMocks = {
67    'get': {
68      '/ok.js': [200, path.join(pkg, 'file-ok.js')],
69      '/invalid.js': [200, path.join(pkg, 'file-fail.js')]
70    }
71  }
72  mr({port: common.port, mocks: customMocks}, function (err, s) {
73    t.ifError(err, 'mock registry started')
74    npm.load(
75      {
76        cache: cache,
77        registry: common.registry
78      },
79      function () {
80        npm.commands.install([], function (err, additions, tree) {
81          t.error(err)
82          var invalid = tree.warnings.filter(function (warning) { return warning.code === 'EPEERINVALID' })
83          t.is(invalid.length, 2)
84          s.close()
85          t.end()
86        })
87      }
88    )
89  })
90})
91
92test('cleanup', function (t) {
93  cleanup()
94  t.end()
95})
96
97function cleanup () {
98  process.chdir(osenv.tmpdir())
99  rimraf.sync(pkg)
100}
101