• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2var Bluebird = require('bluebird')
3var fs = require('graceful-fs')
4var path = require('path')
5
6var mkdirp = require('mkdirp')
7var rimraf = require('rimraf')
8var test = require('tap').test
9
10var common = require('../common-tap.js')
11
12var dir = common.pkg
13var pkg = path.resolve(dir, 'pkg-with-bundled')
14var dep = path.resolve(dir, 'a-bundled-dep')
15
16var pj = JSON.stringify({
17  name: 'pkg-with-bundled',
18  version: '1.0.0',
19  dependencies: {
20    'a-bundled-dep': 'file:../a-bundled-dep-2.0.0.tgz'
21  },
22  bundledDependencies: {
23    'a-bundled-dep': 'file:../a-bundled-dep-2.0.0.tgz'
24  }
25}, null, 2) + '\n'
26
27var pjDep = JSON.stringify({
28  name: 'a-bundled-dep',
29  version: '2.0.0'
30}, null, 2) + '\n'
31
32test('setup', function (t) {
33  bootstrap()
34  t.end()
35})
36
37test('handles non-array bundleddependencies', function (t) {
38  return Bluebird.try(() => {
39    return common.npm(['pack', 'a-bundled-dep/'], {cwd: dir, stdio: [0, 1, 2]})
40  }).spread((code) => {
41    t.is(code, 0, 'built a-bundled-dep')
42    return common.npm(['install'], {cwd: pkg, stdio: [0, 1, 2]})
43  }).spread((code) => {
44    t.is(code, 0, 'prepared pkg-with-bundled')
45    return common.npm(['pack', 'pkg-with-bundled/'], {cwd: dir, stdio: [0, 1, 'pipe']})
46  }).spread((code, _, stderr) => {
47    t.equal(code, 0, 'exited with a error code')
48    t.equal(stderr, '')
49  })
50})
51
52test('cleanup', function (t) {
53  cleanup()
54  t.end()
55})
56
57function bootstrap () {
58  cleanup()
59  mkdirp.sync(dir)
60  mkdirp.sync(path.join(dir, 'node_modules'))
61
62  mkdirp.sync(pkg)
63  fs.writeFileSync(path.resolve(pkg, 'package.json'), pj)
64
65  mkdirp.sync(dep)
66  fs.writeFileSync(path.resolve(dep, 'package.json'), pjDep)
67}
68
69function cleanup () {
70  rimraf.sync(dir)
71}
72