11const t = require ( 'tap' )
22const mockNpm = require ( '../fixtures/mock-npm' )
33const pacote = require ( 'pacote' )
4+ const path = require ( 'path' )
45
56const OUTPUT = [ ]
67const output = ( ...msg ) => OUTPUT . push ( msg )
@@ -27,6 +28,7 @@ const mockPacote = {
2728t . afterEach ( ( ) => OUTPUT . length = 0 )
2829
2930t . test ( 'should pack current directory with no arguments' , ( t ) => {
31+ let tarballFileName
3032 const Pack = t . mock ( '../../lib/pack.js' , {
3133 libnpmpack,
3234 npmlog : {
@@ -35,14 +37,46 @@ t.test('should pack current directory with no arguments', (t) => {
3537 clearProgress : ( ) => { } ,
3638 } ,
3739 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 , 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+ } ,
3975 } ,
4076 } )
4177 const npm = mockNpm ( {
4278 config : {
43- unicode : false ,
44- json : false ,
45- 'dry-run' : false ,
79+ 'pack-destination' : '/tmp/test' ,
4680 } ,
4781 output,
4882 } )
@@ -53,10 +87,10 @@ t.test('should pack current directory with no arguments', (t) => {
5387
5488 const filename = `npm-${ require ( '../../package.json' ) . version } .tgz`
5589 t . strictSame ( OUTPUT , [ [ filename ] ] )
90+ t . strictSame ( tarballFileName , path . join ( '/tmp/test' , filename ) )
5691 t . end ( )
5792 } )
5893} )
59-
6094t . test ( 'should pack given directory' , ( t ) => {
6195 const testDir = t . testdir ( {
6296 'package.json' : JSON . stringify ( {
0 commit comments