summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/tap/do-not-remove-other-bins.js
blob: 6fec728d43bcc32f013c2f317c34f88cf2a51ae3 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
'use strict'
var fs = require('fs')
var path = require('path')

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

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

var base = path.resolve(__dirname, path.basename(__filename, '.js'))
var installPath = path.resolve(base, 'install')
var installBin = path.resolve(installPath, 'node_modules', '.bin')
var packageApath = path.resolve(base, 'packageA')
var packageBpath = path.resolve(base, 'packageB')

var packageA = {
  name: 'a',
  version: '1.0.0',
  description: 'x',
  repository: 'x',
  license: 'MIT',
  bin: {
    testbin: './testbin.js'
  }
}
var packageB = {
  name: 'b',
  version: '1.0.0',
  description: 'x',
  repository: 'x',
  license: 'MIT',
  bin: {
    testbin: './testbin.js'
  }
}

var EXEC_OPTS = {
  cwd: installPath
}

test('setup', function (t) {
  cleanup()
  mkdirp.sync(path.join(installPath, 'node_modules'))
  mkdirp.sync(packageApath)
  fs.writeFileSync(
    path.join(packageApath, 'package.json'),
    JSON.stringify(packageA, null, 2)
  )
  fs.writeFileSync(
    path.join(packageApath, packageA.bin.testbin),
    ''
  )
  mkdirp.sync(packageBpath)
  fs.writeFileSync(
    path.join(packageBpath, 'package.json'),
    JSON.stringify(packageB, null, 2)
  )
  fs.writeFileSync(
    path.join(packageBpath, packageB.bin.testbin),
    ''
  )
  t.end()
})

test('npm install A', function (t) {
  process.chdir(installPath)
  common.npm([
    'install', packageApath
  ], EXEC_OPTS, function (err, code, stdout, stderr) {
    console.log(stdout, stderr)
    t.ifErr(err, 'install finished successfully')
    t.notOk(code, 'exit ok')
    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
    t.end()
  })
})

test('npm install B', function (t) {
  process.chdir(installPath)
  common.npm([
    'install', packageBpath
  ], EXEC_OPTS, function (err, code, stdout, stderr) {
    t.ifErr(err, 'install finished successfully')
    t.notOk(code, 'exit ok')
    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
    t.end()
  })
})

test('verify bins', function (t) {
  var bin = path.dirname(
    path.resolve(
      installBin,
      common.readBinLink(path.join(installBin, 'testbin'))))
  t.is(bin, path.join(installPath, 'node_modules', 'b'))
  t.end()
})

test('rm install A', function (t) {
  process.chdir(installPath)
  common.npm([
    'rm', packageApath
  ], EXEC_OPTS, function (err, code, stdout, stderr) {
    t.ifErr(err, 'install finished successfully')
    t.notOk(code, 'exit ok')
    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
    t.end()
  })
})

test('verify postremoval bins', function (t) {
  var bin = path.dirname(
    path.resolve(
      installBin,
      common.readBinLink(path.join(installBin, 'testbin'))))
  t.is(bin, path.join(installPath, 'node_modules', 'b'))
  t.end()
})

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

function cleanup () {
  process.chdir(osenv.tmpdir())
  rimraf.sync(base)
}