• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var test = require('tap').test
3var requireInject = require('require-inject')
4var npa = require('npm-package-arg')
5var log = require('npmlog')
6
7// we're just mocking to avoid having to call `npm.load`
8var deps = requireInject('../../lib/install/deps.js', {
9  '../../lib/npm.js': {
10    config: {
11      get: function (val) { return (val === 'global-style' || val === 'legacy-bundling') ? false : 'mock' }
12    },
13    limit: {
14      fetch: 10
15    }
16  }
17})
18
19var earliestInstallable = deps.earliestInstallable
20
21test('earliestInstallable should consider devDependencies', function (t) {
22  var dep1 = {
23    children: [],
24    package: {
25      name: 'dep1',
26      dependencies: { dep2: '2.0.0' }
27    },
28    path: '/dep1',
29    realpath: '/dep1'
30  }
31
32  // a library required by the base package
33  var dep2 = {
34    package: {
35      name: 'dep2',
36      version: '1.0.0'
37    },
38    path: '/dep2',
39    realpath: '/dep2'
40  }
41
42  // an incompatible version of dep2. required by dep1
43  var dep2a = {
44    package: {
45      name: 'dep2',
46      version: '2.0.0',
47      _requested: npa('dep2@2.0.0')
48    },
49    parent: dep1,
50    path: '/dep1/node_modules/dep2a',
51    realpath: '/dep1/node_modules/dep2a'
52  }
53
54  var pkg = {
55    isTop: true,
56    children: [dep1, dep2],
57    package: {
58      name: 'pkg',
59      dependencies: { dep1: '1.0.0' },
60      devDependencies: { dep2: '1.0.0' }
61    },
62    path: '/',
63    realpath: '/'
64  }
65
66  dep1.parent = pkg
67  dep2a.parent = dep1
68  dep2.parent = pkg
69
70  var earliest = earliestInstallable(dep1, dep1, dep2a.package, log)
71  t.isDeeply(earliest, dep1, 'should hoist package when an incompatible devDependency is present')
72  t.end()
73})
74
75test('earliestInstallable should reuse shared prod/dev deps when they are identical', function (t) {
76  var dep1 = {
77    children: [],
78    package: {
79      name: 'dep1',
80      dependencies: { dep2: '1.0.0' }
81    },
82    path: '/dep1',
83    realpath: '/dep1'
84  }
85
86  var dep2 = {
87    package: {
88      name: 'dep2',
89      version: '1.0.0',
90      _requested: npa('dep2@^1.0.0')
91    },
92    path: '/dep2',
93    realpath: '/dep2'
94  }
95
96  var pkg = {
97    isTop: true,
98    children: [dep1],
99    package: {
100      name: 'pkg',
101      dependencies: { dep1: '1.0.0' },
102      devDependencies: { dep2: '^1.0.0' }
103    },
104    path: '/',
105    realpath: '/'
106  }
107
108  dep1.parent = pkg
109  dep2.parent = pkg
110
111  var earliest = earliestInstallable(dep1, dep1, dep2.package, log)
112  t.isDeeply(earliest, pkg, 'should reuse identical shared dev/prod deps when installing both')
113  t.end()
114})
115