• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3
4var mkdirp = require('mkdirp')
5var test = require('tap').test
6
7var common = require('../common-tap')
8
9var root = common.pkg
10// Allow running this test on older commits (useful for bisecting)
11if (!root) {
12  var main = require.main.filename
13  root = path.resolve(path.dirname(main), path.basename(main, '.js'))
14}
15var pkg = path.join(root, 'parent')
16
17var EXEC_OPTS = { cwd: pkg }
18
19var parent = {
20  name: 'parent',
21  version: '0.0.0',
22  dependencies: {
23    'child-1-1': 'file:../children/child-1-1',
24    'child-1-2': 'file:../children/child-1-2',
25    'child-2': 'file:../children/child-2'
26  }
27}
28
29var parentLock = {
30  'name': 'parent',
31  'version': '1.0.0',
32  'lockfileVersion': 1,
33  'requires': true,
34  'dependencies': {
35    'child-1-1': {
36      'version': 'file:../children/child-1-1',
37      'requires': {
38        'child-2': 'file:../children/child-2'
39      }
40    },
41    'child-1-2': {
42      'version': 'file:../children/child-1-2',
43      'requires': {
44        'child-1-1': 'file:../children/child-1-1',
45        'child-2': 'file:../children/child-2'
46      }
47    },
48    'child-2': {
49      'version': 'file:../children/child-2'
50    }
51  }
52}
53
54var child11 = {
55  name: 'parent',
56  version: '0.0.0',
57  'dependencies': {
58    'child-2': 'file:../child-2'
59  }
60}
61
62var child11Lock = {
63  'name': 'child-1-1',
64  'version': '1.0.0',
65  'lockfileVersion': 1,
66  'requires': true,
67  'dependencies': {
68    'child-2': {
69      'version': 'file:../child-2'
70    }
71  }
72}
73
74var child12 = {
75  'name': 'child-1-2',
76  'version': '1.0.0',
77  'dependencies': {
78    'child-1-1': 'file:../child-1-1',
79    'child-2': 'file:../child-2'
80  }
81}
82
83var child12Lock = {
84  'name': 'child-1-2',
85  'version': '1.0.0',
86  'lockfileVersion': 1,
87  'requires': true,
88  'dependencies': {
89    'child-1-1': {
90      'version': 'file:../child-1-1',
91      'requires': {
92        'child-2': 'file:../child-2'
93      }
94    },
95    'child-2': {
96      'version': 'file:../child-2'
97    }
98  }
99}
100
101var child2 = {
102  'name': 'child-2',
103  'version': '1.0.0',
104  'dependencies': {}
105}
106
107var child2Lock = {
108  'name': 'child-2',
109  'version': '1.0.0',
110  'lockfileVersion': 1,
111  'requires': true,
112  'dependencies': {}
113}
114
115test('setup', function (t) {
116  mkdirp.sync(pkg)
117  fs.writeFileSync(
118    path.join(pkg, 'package.json'),
119    JSON.stringify(parent, null, 2)
120  )
121
122  fs.writeFileSync(
123    path.join(pkg, 'package-lock.json'),
124    JSON.stringify(parentLock, null, 2)
125  )
126
127  mkdirp.sync(path.join(root, 'children', 'child-1-1'))
128  fs.writeFileSync(
129    path.join(root, 'children', 'child-1-1', 'package.json'),
130    JSON.stringify(child11, null, 2)
131  )
132  fs.writeFileSync(
133    path.join(root, 'children', 'child-1-1', 'package-lock.json'),
134    JSON.stringify(child11Lock, null, 2)
135  )
136
137  mkdirp.sync(path.join(root, 'children', 'child-1-2'))
138  fs.writeFileSync(
139    path.join(root, 'children', 'child-1-2', 'package.json'),
140    JSON.stringify(child12, null, 2)
141  )
142  fs.writeFileSync(
143    path.join(root, 'children', 'child-1-2', 'package-lock.json'),
144    JSON.stringify(child12Lock, null, 2)
145  )
146
147  mkdirp.sync(path.join(root, 'children', 'child-2'))
148  fs.writeFileSync(
149    path.join(root, 'children', 'child-2', 'package.json'),
150    JSON.stringify(child2, null, 2)
151  )
152  fs.writeFileSync(
153    path.join(root, 'children', 'child-2', 'package-lock.json'),
154    JSON.stringify(child2Lock, null, 2)
155  )
156
157  process.chdir(pkg)
158  t.end()
159})
160
161test('\'npm install\' should install local packages', function (t) {
162  common.npm(
163    [
164      'install', '.'
165    ],
166    EXEC_OPTS,
167    function (err, code) {
168      t.ifError(err, 'error should not exist')
169      t.notOk(code, 'npm install exited with code 0')
170      t.end()
171    }
172  )
173})
174