summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/uninstall-link-clean.js
blob: eccdac8b26badf4634aa65a6e4750dd5c575d1b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var fs = require('graceful-fs')
var path = require('path')
var existsSync = fs.existsSync || path.existsSync

var mkdirp = require('mkdirp')
var osenv = require('osenv')
var rimraf = require('rimraf')
var test = require('tap').test

var common = require('../common-tap.js')

var pkg = path.join(__dirname, 'uninstall-link-clean')
var dep = path.join(__dirname, 'dep')
var work = path.join(__dirname, 'uninstall-link-clean-TEST')
var modules = path.join(work, 'node_modules')

var EXEC_OPTS = { cwd: work }

var world = 'console.log("hello blrbld")\n'

var json = {
  name: 'package',
  version: '0.0.0',
  bin: {
    hello: './world.js'
  },
  dependencies: {
    'dep': 'file:../dep'
  }
}

var pjDep = {
  name: 'dep',
  version: '0.0.0',
  bin: {
    hello: './world.js'
  }
}

test('setup', function (t) {
  cleanup()
  mkdirp.sync(pkg)
  fs.writeFileSync(
    path.join(pkg, 'package.json'),
    JSON.stringify(json, null, 2)
  )
  fs.writeFileSync(path.join(pkg, 'world.js'), world)

  mkdirp.sync(dep)
  fs.writeFileSync(
    path.join(dep, 'package.json'),
    JSON.stringify(pjDep, null, 2)
  )
  fs.writeFileSync(path.join(dep, 'world.js'), world)

  mkdirp.sync(modules)
  process.chdir(work)

  t.end()
})

test('installing package with links', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      'install', pkg
    ],
    EXEC_OPTS,
    function (err, code) {
      t.ifError(err, 'install ran to completion without error')
      t.notOk(code, 'npm install exited with code 0')

      t.ok(
        existsSync(path.join(modules, 'package', 'package.json')),
        'package installed'
      )
      t.ok(existsSync(path.join(modules, '.bin')), 'binary link directory exists')
      t.ok(existsSync(path.join(modules, 'package', 'node_modules', '.bin')),
        'nested binary link directory exists')

      t.end()
    }
  )
})

test('uninstalling package with links', function (t) {
  common.npm(
    [
      '--loglevel', 'silent',
      'uninstall', 'package'
    ],
    EXEC_OPTS,
    function (err, code) {
      t.ifError(err, 'uninstall ran to completion without error')
      t.notOk(code, 'npm uninstall exited with code 0')

      t.notOk(existsSync(path.join(modules, 'package')),
        'package directory no longer exists')
      t.notOk(existsSync(path.join(modules, 'package', 'node_modules', '.bin')),
        'nested binary link directory no longer exists')

      t.end()
    }
  )
})

test('cleanup', function (t) {
  cleanup()
  t.end()
})

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(dep)
  rimraf.sync(work)
  rimraf.sync(pkg)
}