1- const { test } = require ( 'tap' )
1+ const t = require ( 'tap' )
22const requireInject = require ( 'require-inject' )
33
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 ) => {
521 const pack = requireInject ( '../../lib/pack.js' , {
22+ '../../lib/utils/output.js' : output ,
623 '../../lib/npm.js' : {
724 flatOptions : {
825 unicode : false ,
926 json : false ,
1027 dryRun : false
1128 }
1229 } ,
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 : ( ) => { }
2035 }
2136 } )
2237
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 ] ] )
2544 } )
2645} )
2746
28- test ( 'should pack given directory' , ( t ) => {
47+ t . test ( 'should pack given directory' , ( t ) => {
2948 const testDir = t . testdir ( {
3049 'package.json' : JSON . stringify ( {
3150 name : 'my-cool-pkg' ,
@@ -34,31 +53,37 @@ test('should pack given directory', (t) => {
3453 } )
3554
3655 const pack = requireInject ( '../../lib/pack.js' , {
37- '../../lib/utils/output.js' : ( ) => { } ,
56+ '../../lib/utils/output.js' : output ,
3857 '../../lib/npm.js' : {
3958 flatOptions : {
4059 unicode : true ,
4160 json : true ,
4261 dryRun : true
4362 }
4463 } ,
45- 'libnpmpack' : ( ) => '' ,
46- 'npmlog' : {
64+ libnpmpack,
65+ npmlog : {
66+ notice : ( ) => { } ,
4767 'showProgress' : ( ) => { } ,
4868 'clearProgress' : ( ) => { }
4969 }
5070 } )
5171
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 ] ] )
5478 } )
5579} )
5680
57- test ( 'should log pack contents' , ( t ) => {
81+ t . test ( 'should log pack contents' , ( t ) => {
5882 const pack = requireInject ( '../../lib/pack.js' , {
83+ '../../lib/utils/output.js' : output ,
5984 '../../lib/utils/tar.js' : {
60- 'getContents' : ( ) => { } ,
61- ' logTar' : ( ) => {
85+ ... require ( '../../lib/utils/tar.js' ) ,
86+ logTar : ( ) => {
6287 t . ok ( true , 'logTar is called' )
6388 }
6489 } ,
@@ -69,14 +94,19 @@ test('should log pack contents', (t) => {
6994 dryRun : false
7095 }
7196 } ,
72- 'libnpmpack' : ( ) => '' ,
73- 'npmlog' : {
97+ libnpmpack,
98+ npmlog : {
99+ notice : ( ) => { } ,
74100 'showProgress' : ( ) => { } ,
75101 'clearProgress' : ( ) => { }
76102 }
77103 } )
78104
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 ] ] )
81111 } )
82112} )
0 commit comments