• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var test = require('tap').test
2var path = require('path')
3var fs = require('fs')
4var mkdirp = require('mkdirp')
5var rimraf = require('rimraf')
6var readInstalled = require('../')
7
8var root = path.resolve(__dirname, 'root')
9var pkg = path.resolve(root, 'pkg')
10var pkgnm = path.resolve(pkg, 'node_modules')
11var linkdepSrc = path.resolve(root, 'linkdep')
12var linkdepLink = path.resolve(pkgnm, 'linkdep')
13var devdep = path.resolve(linkdepSrc, 'node_modules', 'devdep')
14
15function pjson (dir, data) {
16  mkdirp.sync(dir)
17  var d = path.resolve(dir, 'package.json')
18  fs.writeFileSync(d, JSON.stringify(data))
19}
20
21test('setup', function (t) {
22  rimraf.sync(root)
23  pjson(pkg, {
24    name: 'root',
25    version: '1.2.3',
26    dependencies: {
27      linkdep: ''
28    }
29  })
30  pjson(linkdepSrc, {
31    name: 'linkdep',
32    version: '1.2.3',
33    devDependencies: {
34      devdep: ''
35    }
36  })
37  pjson(devdep, {
38    name: 'devdep',
39    version: '1.2.3'
40  })
41
42  mkdirp.sync(pkgnm)
43  fs.symlinkSync(linkdepSrc, linkdepLink, 'dir')
44
45  t.end()
46})
47
48test('basic', function (t) {
49  readInstalled(pkg, { dev: true }, function (er, data) {
50    var dd = data.dependencies.linkdep.dependencies.devdep
51    t.notOk(dd.extraneous, 'linked dev dep should not be extraneous')
52    t.end()
53  })
54})
55
56test('cleanup', function (t) {
57  rimraf.sync(root)
58  t.end()
59})
60