summaryrefslogtreecommitdiff
path: root/deps/node/deps/npm/test/tap/bundled-dependencies-nonarray.js
blob: 924e1b27b60a3a272596f9e348cbff5bb4f1dec6 (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
'use strict'
var Bluebird = require('bluebird')
var fs = require('graceful-fs')
var path = require('path')

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

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

var dir = path.resolve(__dirname, path.basename(__filename, '.js'))
var pkg = path.resolve(dir, 'pkg-with-bundled')
var dep = path.resolve(dir, 'a-bundled-dep')

var pj = JSON.stringify({
  name: 'pkg-with-bundled',
  version: '1.0.0',
  dependencies: {
    'a-bundled-dep': 'file:../a-bundled-dep-2.0.0.tgz'
  },
  bundledDependencies: {
    'a-bundled-dep': 'file:../a-bundled-dep-2.0.0.tgz'
  }
}, null, 2) + '\n'

var pjDep = JSON.stringify({
  name: 'a-bundled-dep',
  version: '2.0.0'
}, null, 2) + '\n'

test('setup', function (t) {
  bootstrap()
  t.end()
})

test('handles non-array bundleddependencies', function (t) {
  return Bluebird.try(() => {
    return common.npm(['pack', 'a-bundled-dep/'], {cwd: dir, stdio: [0, 1, 2]})
  }).spread((code) => {
    t.is(code, 0, 'built a-bundled-dep')
    return common.npm(['install'], {cwd: pkg, stdio: [0, 1, 2]})
  }).spread((code) => {
    t.is(code, 0, 'prepared pkg-with-bundled')
    return common.npm(['pack', 'pkg-with-bundled/'], {cwd: dir, stdio: [0, 1, 'pipe']})
  }).spread((code, _, stderr) => {
    t.equal(code, 0, 'exited with a error code')
    t.equal(stderr, '')
  })
})

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

function bootstrap () {
  cleanup()
  mkdirp.sync(dir)
  mkdirp.sync(path.join(dir, 'node_modules'))

  mkdirp.sync(pkg)
  fs.writeFileSync(path.resolve(pkg, 'package.json'), pj)

  mkdirp.sync(dep)
  fs.writeFileSync(path.resolve(dep, 'package.json'), pjDep)
}

function cleanup () {
  rimraf.sync(dir)
}