pack: output generated tarball filename · npm/cli@2c305e8 (original) (raw)
1
``
`-
const { test } = require('tap')
`
``
1
`+
const t = require('tap')
`
2
2
`const requireInject = require('require-inject')
`
3
3
``
4
``
`-
test('should pack current directory with no arguments', (t) => {
`
``
4
`+
const OUTPUT = []
`
``
5
`+
const output = (...msg) => OUTPUT.push(msg)
`
``
6
+
``
7
`+
const libnpmpackActual = require('libnpmpack')
`
``
8
`+
const libnpmpack = async (spec, opts) => {
`
``
9
`+
if (!opts) {
`
``
10
`+
throw new Error('expected options object')
`
``
11
`+
}
`
``
12
`+
return ''
`
``
13
`+
}
`
``
14
+
``
15
`+
t.afterEach(cb => {
`
``
16
`+
OUTPUT.length = 0
`
``
17
`+
cb()
`
``
18
`+
})
`
``
19
+
``
20
`+
t.test('should pack current directory with no arguments', (t) => {
`
5
21
`const pack = requireInject('../../lib/pack.js', {
`
``
22
`+
'../../lib/utils/output.js': output,
`
6
23
`'../../lib/npm.js': {
`
7
24
`flatOptions: {
`
8
25
`unicode: false,
`
9
26
`json: false,
`
10
27
`dryRun: false
`
11
28
`}
`
12
29
`},
`
13
``
`-
'libnpmpack': () => {
`
14
``
`-
t.ok(true, 'libnpmpack is called')
`
15
``
`-
return ''
`
16
``
`-
},
`
17
``
`-
'npmlog': {
`
18
``
`-
'showProgress': () => {},
`
19
``
`-
'clearProgress': () => {}
`
``
30
`+
libnpmpack,
`
``
31
`+
npmlog: {
`
``
32
`+
notice: () => {},
`
``
33
`+
showProgress: () => {},
`
``
34
`+
clearProgress: () => {}
`
20
35
`}
`
21
36
`})
`
22
37
``
23
``
`-
pack([], () => {
`
24
``
`-
t.end()
`
``
38
`+
return pack([], er => {
`
``
39
`+
if (er) {
`
``
40
`+
throw er
`
``
41
`+
}
`
``
42
`` +
const filename = npm-${require('../../package.json').version}.tgz
``
``
43
`+
t.strictSame(OUTPUT, [[filename]])
`
25
44
`})
`
26
45
`})
`
27
46
``
28
``
`-
test('should pack given directory', (t) => {
`
``
47
`+
t.test('should pack given directory', (t) => {
`
29
48
`const testDir = t.testdir({
`
30
49
`'package.json': JSON.stringify({
`
31
50
`name: 'my-cool-pkg',
`
`@@ -34,31 +53,37 @@ test('should pack given directory', (t) => {
`
34
53
`})
`
35
54
``
36
55
`const pack = requireInject('../../lib/pack.js', {
`
37
``
`-
'../../lib/utils/output.js': () => {},
`
``
56
`+
'../../lib/utils/output.js': output,
`
38
57
`'../../lib/npm.js': {
`
39
58
`flatOptions: {
`
40
59
`unicode: true,
`
41
60
`json: true,
`
42
61
`dryRun: true
`
43
62
`}
`
44
63
`},
`
45
``
`-
'libnpmpack': () => '',
`
46
``
`-
'npmlog': {
`
``
64
`+
libnpmpack,
`
``
65
`+
npmlog: {
`
``
66
`+
notice: () => {},
`
47
67
`'showProgress': () => {},
`
48
68
`'clearProgress': () => {}
`
49
69
`}
`
50
70
`})
`
51
71
``
52
``
`-
pack([testDir], () => {
`
53
``
`-
t.end()
`
``
72
`+
return pack([testDir], er => {
`
``
73
`+
if (er) {
`
``
74
`+
throw er
`
``
75
`+
}
`
``
76
`+
const filename = 'my-cool-pkg-1.0.0.tgz'
`
``
77
`+
t.strictSame(OUTPUT, [[filename]])
`
54
78
`})
`
55
79
`})
`
56
80
``
57
``
`-
test('should log pack contents', (t) => {
`
``
81
`+
t.test('should log pack contents', (t) => {
`
58
82
`const pack = requireInject('../../lib/pack.js', {
`
``
83
`+
'../../lib/utils/output.js': output,
`
59
84
`'../../lib/utils/tar.js': {
`
60
``
`-
'getContents': () => {},
`
61
``
`-
'logTar': () => {
`
``
85
`+
...require('../../lib/utils/tar.js'),
`
``
86
`+
logTar: () => {
`
62
87
`t.ok(true, 'logTar is called')
`
63
88
`}
`
64
89
`},
`
`@@ -69,14 +94,19 @@ test('should log pack contents', (t) => {
`
69
94
`dryRun: false
`
70
95
`}
`
71
96
`},
`
72
``
`-
'libnpmpack': () => '',
`
73
``
`-
'npmlog': {
`
``
97
`+
libnpmpack,
`
``
98
`+
npmlog: {
`
``
99
`+
notice: () => {},
`
74
100
`'showProgress': () => {},
`
75
101
`'clearProgress': () => {}
`
76
102
`}
`
77
103
`})
`
78
104
``
79
``
`-
pack([], () => {
`
80
``
`-
t.end()
`
``
105
`+
return pack([], er => {
`
``
106
`+
if (er) {
`
``
107
`+
throw er
`
``
108
`+
}
`
``
109
`` +
const filename = npm-${require('../../package.json').version}.tgz
``
``
110
`+
t.strictSame(OUTPUT, [[filename]])
`
81
111
`})
`
82
112
`})
`