• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var fs = require('fs')
3var path = require('path')
4
5var mkdirp = require('mkdirp')
6var test = require('tap').test
7
8var common = require('../common-tap')
9
10var base = common.pkg
11var installPath = path.resolve(base, 'install')
12var installBin = path.resolve(installPath, 'node_modules', '.bin')
13var packageApath = path.resolve(base, 'packageA')
14var packageBpath = path.resolve(base, 'packageB')
15
16var packageA = {
17  name: 'a',
18  version: '1.0.0',
19  description: 'x',
20  repository: 'x',
21  license: 'MIT',
22  bin: {
23    testbin: './testbin.js'
24  }
25}
26var packageB = {
27  name: 'b',
28  version: '1.0.0',
29  description: 'x',
30  repository: 'x',
31  license: 'MIT',
32  bin: {
33    testbin: './testbin.js'
34  }
35}
36
37var EXEC_OPTS = {
38  cwd: installPath
39}
40
41test('setup', function (t) {
42  mkdirp.sync(path.join(installPath, 'node_modules'))
43  mkdirp.sync(packageApath)
44  fs.writeFileSync(
45    path.join(packageApath, 'package.json'),
46    JSON.stringify(packageA, null, 2)
47  )
48  fs.writeFileSync(
49    path.join(packageApath, packageA.bin.testbin),
50    ''
51  )
52  mkdirp.sync(packageBpath)
53  fs.writeFileSync(
54    path.join(packageBpath, 'package.json'),
55    JSON.stringify(packageB, null, 2)
56  )
57  fs.writeFileSync(
58    path.join(packageBpath, packageB.bin.testbin),
59    ''
60  )
61  t.end()
62})
63
64test('npm install A', function (t) {
65  process.chdir(installPath)
66  common.npm([
67    'install', packageApath
68  ], EXEC_OPTS, function (err, code, stdout, stderr) {
69    console.log(stdout, stderr)
70    t.ifErr(err, 'install finished successfully')
71    t.notOk(code, 'exit ok')
72    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
73    t.end()
74  })
75})
76
77test('npm install B', function (t) {
78  process.chdir(installPath)
79  common.npm([
80    'install', packageBpath
81  ], EXEC_OPTS, function (err, code, stdout, stderr) {
82    t.ifErr(err, 'install finished successfully')
83    t.notOk(code, 'exit ok')
84    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
85    t.end()
86  })
87})
88
89test('verify bins', function (t) {
90  var bin = path.dirname(
91    path.resolve(
92      installBin,
93      common.readBinLink(path.join(installBin, 'testbin'))))
94  t.is(bin, path.join(installPath, 'node_modules', 'b'))
95  t.end()
96})
97
98test('rm install A', function (t) {
99  process.chdir(installPath)
100  common.npm([
101    'rm', packageApath
102  ], EXEC_OPTS, function (err, code, stdout, stderr) {
103    t.ifErr(err, 'install finished successfully')
104    t.notOk(code, 'exit ok')
105    t.notOk(stderr, 'Should not get data on stderr: ' + stderr)
106    t.end()
107  })
108})
109
110test('verify postremoval bins', function (t) {
111  var bin = path.dirname(
112    path.resolve(
113      installBin,
114      common.readBinLink(path.join(installBin, 'testbin'))))
115  t.is(bin, path.join(installPath, 'node_modules', 'b'))
116  t.end()
117})
118