summaryrefslogtreecommitdiff
path: root/deps/npm/test/tap/pack.js
blob: a0c326210ea6ce2dc5d95dd1204d778050689a57 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
'use strict'

const BB = require('bluebird')

const test = require('tap').test
const common = require('../common-tap')
const fs = BB.promisifyAll(require('graceful-fs'))
const path = require('path')
const rimraf = BB.promisify(require('rimraf'))
const Tacks = require('tacks')

const Dir = Tacks.Dir
const File = Tacks.File

const testDir = path.join(__dirname, 'pkg')
const tmp = path.join(testDir, 'tmp')
const cache = path.join(testDir, 'cache')

test('basic pack', (t) => {
  const fixture = new Tacks(new Dir({
    'package.json': new File({
      name: 'generic-package',
      version: '90000.100001.5'
    })
  }))
  return rimraf(testDir)
    .then(() => fixture.create(testDir))
    .then(() => common.npm([
      'pack',
      '--loglevel', 'notice',
      '--cache', cache,
      '--tmp', tmp,
      '--prefix', testDir,
      '--no-global'
    ], {
      cwd: testDir
    }))
    .spread((code, stdout, stderr) => {
      t.equal(code, 0, 'npm pack exited ok')
      t.match(stderr, /notice\s+\d+[a-z]+\s+package\.json/gi, 'mentions package.json')
      t.match(stdout, /generic-package-90000\.100001\.5\.tgz/ig, 'found pkg')
      return fs.statAsync(
        path.join(testDir, 'generic-package-90000.100001.5.tgz')
      )
    })
    .then((stat) => t.ok(stat, 'tarball written to cwd'))
    .then(() => rimraf(testDir))
})

test('pack with bundled', (t) => {
  const fixture = new Tacks(new Dir({
    'package.json': new File({
      name: 'generic-package',
      version: '90000.100001.5',
      dependencies: {
        '@bundle/dep': '^1.0.0',
        'regular-dep': '^1.0.0'
      },
      bundleDependencies: [
        '@bundle/dep',
        'regular-dep'
      ]
    }),
    'node_modules': new Dir({
      'regular-dep': new Dir({
        'package.json': new File({
          name: 'regular-dep',
          version: '1.0.0'
        })
      }),
      '@bundle': new Dir({
        'dep': new Dir({
          'package.json': new File({
            name: '@bundle/dep',
            version: '1.0.0'
          })
        })
      })
    })
  }))
  return rimraf(testDir)
    .then(() => fixture.create(testDir))
    .then(() => common.npm([
      'pack',
      '--loglevel', 'notice',
      '--cache', cache,
      '--tmp', tmp,
      '--prefix', testDir,
      '--no-global'
    ], {
      cwd: testDir
    }))
    .spread((code, stdout, stderr) => {
      t.equal(code, 0, 'npm pack exited ok')
      t.match(stderr, /notice\s+\d+[a-z]+\s+package\.json/gi, 'mentions package.json')
      t.match(stderr, /notice\s+regular-dep/, 'regular dep mentioned')
      t.match(stderr, /notice\s+@bundle\/dep/, 'bundled dep mentioned')
    })
    .then(() => rimraf(testDir))
})

test('pack --dry-run', (t) => {
  const fixture = new Tacks(new Dir({
    'package.json': new File({
      name: 'generic-package',
      version: '90000.100001.5'
    })
  }))
  return rimraf(testDir)
    .then(() => fixture.create(testDir))
    .then(() => common.npm([
      'pack',
      '--dry-run',
      '--loglevel', 'notice',
      '--cache', cache,
      '--tmp', tmp,
      '--prefix', testDir,
      '--no-global'
    ], {
      cwd: testDir
    }))
    .spread((code, stdout, stderr) => {
      t.equal(code, 0, 'npm pack exited ok')
      t.match(stdout, /generic-package-90000\.100001\.5\.tgz/ig, 'found pkg')
      return fs.statAsync(
        path.join(testDir, 'generic-package-90000.100001.5.tgz')
      )
        .then(
          () => { throw new Error('should have failed') },
          (err) => t.equal(err.code, 'ENOENT', 'no tarball written!')
        )
    })
    .then(() => rimraf(testDir))
})

test('pack --json', (t) => {
  const fixture = new Tacks(new Dir({
    'package.json': new File({
      name: 'generic-package',
      version: '90000.100001.5'
    })
  }))
  return rimraf(testDir)
    .then(() => fixture.create(testDir))
    .then(() => common.npm([
      'pack',
      '--dry-run',
      '--json',
      '--loglevel', 'notice',
      '--cache', cache,
      '--tmp', tmp,
      '--prefix', testDir,
      '--no-global'
    ], {
      cwd: testDir
    }))
    .spread((code, stdout, stderr) => {
      t.equal(code, 0, 'npm pack exited ok')
      t.equal(stderr.trim(), '', 'no notice output')
      t.similar(JSON.parse(stdout), [{
        filename: 'generic-package-90000.100001.5.tgz',
        files: [{path: 'package.json'}],
        entryCount: 1
      }], 'pack details output as valid json')
    })
    .then(() => rimraf(testDir))
})