• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3
4var mr = require('npm-registry-mock')
5var test = require('tap').test
6
7var common = require('../common-tap.js')
8var npm = require('../../')
9
10var pkg = common.pkg
11
12var json = {
13  author: 'Anders Janmyr',
14  name: 'dev-dep-duplicate',
15  version: '0.0.0',
16  dependencies: {
17    underscore: '1.5.1'
18  },
19  devDependencies: {
20    underscore: '1.3.1'
21  }
22}
23
24var expected = {
25  name: 'dev-dep-duplicate',
26  version: '0.0.0',
27  dependencies: {
28    underscore: {
29      version: '1.5.1',
30      from: 'underscore@1.5.1',
31      resolved: common.registry + '/underscore/-/underscore-1.5.1.tgz',
32      invalid: true
33    }
34  }
35}
36
37test('prefers version from dependencies over devDependencies', function (t) {
38  t.plan(1)
39
40  mr({ port: common.port }, function (er, s) {
41    setup(function (err) {
42      if (err) {
43        throw err
44      }
45
46      npm.install('.', function (err) {
47        if (err) {
48          throw err
49        }
50
51        npm.commands.ls([], true, function (err, _, results) {
52          if (err) {
53            throw err
54          }
55
56          // these contain full paths so we can't do an exact match
57          // with them
58          delete results.problems
59          delete results.dependencies.underscore.problems
60          t.deepEqual(results, expected)
61          s.close()
62          t.end()
63        })
64      })
65    })
66  })
67})
68
69function setup (cb) {
70  fs.writeFileSync(
71    path.join(pkg, 'package.json'),
72    JSON.stringify(json, null, 2)
73  )
74  process.chdir(pkg)
75
76  var opts = {
77    cache: common.cache,
78    registry: common.registry
79  }
80  npm.load(opts, cb)
81}
82