1
1
const t = require ( 'tap' )
2
2
const mockNpm = require ( '../fixtures/mock-npm' )
3
3
const pacote = require ( 'pacote' )
4
+ const path = require ( 'path' )
4
5
5
6
const OUTPUT = [ ]
6
7
const output = ( ...msg ) => OUTPUT . push ( msg )
@@ -27,6 +28,7 @@ const mockPacote = {
27
28
t . afterEach ( ( ) => OUTPUT . length = 0 )
28
29
29
30
t . test ( 'should pack current directory with no arguments' , ( t ) => {
31
+ let tarballFileName
30
32
const Pack = t . mock ( '../../lib/pack.js' , {
31
33
libnpmpack,
32
34
npmlog : {
@@ -35,14 +37,46 @@ t.test('should pack current directory with no arguments', (t) => {
35
37
clearProgress : ( ) => { } ,
36
38
} ,
37
39
fs : {
38
- writeFile : ( file , data , cb ) => cb ( ) ,
40
+ writeFile : ( file , data , cb ) => {
41
+ tarballFileName = file
42
+ cb ( )
43
+ } ,
44
+ } ,
45
+ } )
46
+ const npm = mockNpm ( {
47
+ output,
48
+ } )
49
+ const pack = new Pack ( npm )
50
+
51
+ pack . exec ( [ ] , err => {
52
+ t . error ( err , { bail : true } )
53
+
54
+ const filename = `npm-${ require ( '../../package.json' ) . version } .tgz`
55
+ t . strictSame ( OUTPUT , [ [ filename ] ] )
56
+ t . strictSame ( tarballFileName , path . resolve ( filename ) )
57
+ t . end ( )
58
+ } )
59
+ } )
60
+
61
+ t . test ( 'follows pack-destination config' , ( t ) => {
62
+ let tarballFileName
63
+ const Pack = t . mock ( '../../lib/pack.js' , {
64
+ libnpmpack,
65
+ npmlog : {
66
+ notice : ( ) => { } ,
67
+ showProgress : ( ) => { } ,
68
+ clearProgress : ( ) => { } ,
69
+ } ,
70
+ fs : {
71
+ writeFile : ( file , data , cb ) => {
72
+ tarballFileName = file
73
+ cb ( )
74
+ } ,
39
75
} ,
40
76
} )
41
77
const npm = mockNpm ( {
42
78
config : {
43
- unicode : false ,
44
- json : false ,
45
- 'dry-run' : false ,
79
+ 'pack-destination' : '/tmp/test' ,
46
80
} ,
47
81
output,
48
82
} )
@@ -53,10 +87,10 @@ t.test('should pack current directory with no arguments', (t) => {
53
87
54
88
const filename = `npm-${ require ( '../../package.json' ) . version } .tgz`
55
89
t . strictSame ( OUTPUT , [ [ filename ] ] )
90
+ t . strictSame ( tarballFileName , path . resolve ( '/tmp/test' , filename ) )
56
91
t . end ( )
57
92
} )
58
93
} )
59
-
60
94
t . test ( 'should pack given directory' , ( t ) => {
61
95
const testDir = t . testdir ( {
62
96
'package.json' : JSON . stringify ( {
0 commit comments