• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1var fs = require('graceful-fs')
2var path = require('path')
3var existsSync = fs.existsSync || path.existsSync
4
5var mkdirp = require('mkdirp')
6var rimraf = require('rimraf')
7var test = require('tap').test
8
9var common = require('../common-tap.js')
10
11var testdir = common.pkg
12var pkg = path.join(testdir, 'pkg')
13var dep = path.join(testdir, 'dep')
14var work = path.join(testdir, 'uninstall-link-clean-TEST')
15var modules = path.join(work, 'node_modules')
16
17var EXEC_OPTS = { cwd: work, stdio: [0, 'ignore', 2] }
18
19var world = 'console.log("hello blrbld")\n'
20
21var json = {
22  name: 'package',
23  version: '0.0.0',
24  bin: {
25    hello: './world.js'
26  },
27  dependencies: {
28    'dep': 'file:../dep'
29  }
30}
31
32var pjDep = {
33  name: 'dep',
34  version: '0.0.0',
35  bin: {
36    hello: './world.js'
37  }
38}
39
40test('setup', function (t) {
41  cleanup()
42  mkdirp.sync(pkg)
43  fs.writeFileSync(
44    path.join(pkg, 'package.json'),
45    JSON.stringify(json, null, 2)
46  )
47  fs.writeFileSync(path.join(pkg, 'world.js'), world)
48
49  mkdirp.sync(dep)
50  fs.writeFileSync(
51    path.join(dep, 'package.json'),
52    JSON.stringify(pjDep, null, 2)
53  )
54  fs.writeFileSync(path.join(dep, 'world.js'), world)
55
56  mkdirp.sync(modules)
57
58  t.end()
59})
60
61test('installing package with links', function (t) {
62  common.npm(
63    [
64      '--loglevel', 'error',
65      'install', pkg
66    ],
67    EXEC_OPTS,
68    function (err, code) {
69      t.ifError(err, 'install ran to completion without error')
70      t.notOk(code, 'npm install exited with code 0')
71
72      t.ok(
73        existsSync(path.join(modules, 'package', 'package.json')),
74        'package installed'
75      )
76      t.ok(existsSync(path.join(modules, '.bin')), 'binary link directory exists')
77      t.ok(existsSync(path.join(modules, 'package', 'node_modules', '.bin')),
78        'nested binary link directory exists')
79
80      t.end()
81    }
82  )
83})
84
85test('uninstalling package with links', function (t) {
86  common.npm(
87    [
88      '--loglevel', 'error',
89      'uninstall', 'package'
90    ],
91    EXEC_OPTS,
92    function (err, code) {
93      t.ifError(err, 'uninstall ran to completion without error')
94      t.notOk(code, 'npm uninstall exited with code 0')
95
96      t.notOk(existsSync(path.join(modules, 'package')),
97        'package directory no longer exists')
98      t.notOk(existsSync(path.join(modules, 'package', 'node_modules', '.bin')),
99        'nested binary link directory no longer exists')
100
101      t.end()
102    }
103  )
104})
105
106test('cleanup', function (t) {
107  cleanup()
108  t.end()
109})
110
111function cleanup () {
112  rimraf.sync(testdir)
113}
114