@@ -105,6 +105,87 @@ t.test('dry run', async t => {
105105 t . throws ( ( ) => fs . statSync ( path . resolve ( npm . prefix , filename ) ) )
106106} )
107107
108+ t . test ( 'foreground-scripts defaults to true' , async t => {
109+ const { npm, outputs, logs } = await loadMockNpm ( t , {
110+ prefixDir : {
111+ 'package.json' : JSON . stringify ( {
112+ name : 'test-fg-scripts' ,
113+ version : '0.0.0' ,
114+ scripts : {
115+ prepack : 'echo prepack!' ,
116+ postpack : 'echo postpack!' ,
117+ } ,
118+ }
119+ ) ,
120+ } ,
121+ config : { 'dry-run' : true } ,
122+ } )
123+
124+ /* eslint no-console: 0 */
125+ // TODO: replace this with `const results = t.intercept(console, 'log')`
126+ const log = console . log
127+ t . teardown ( ( ) => {
128+ console . log = log
129+ } )
130+ const caughtLogs = [ ]
131+ console . log = ( ...args ) => {
132+ caughtLogs . push ( args )
133+ }
134+ // end TODO
135+
136+ await npm . exec ( 'pack' , [ ] )
137+ const filename = 'test-fg-scripts-0.0.0.tgz'
138+ t . same (
139+ caughtLogs ,
140+ [
141+ [ '\n> [email protected] prepack\n> echo prepack!\n' ] , 142+ [ '\n> [email protected] postpack\n> echo postpack!\n' ] , 143+ ] ,
144+ 'prepack and postpack log to stdout' )
145+ t . strictSame ( outputs , [ [ filename ] ] )
146+ t . matchSnapshot ( logs . notice . map ( ( [ , m ] ) => m ) , 'logs pack contents' )
147+ t . throws ( ( ) => fs . statSync ( path . resolve ( npm . prefix , filename ) ) )
148+ } )
149+
150+ t . test ( 'foreground-scripts can still be set to false' , async t => {
151+ const { npm, outputs, logs } = await loadMockNpm ( t , {
152+ prefixDir : {
153+ 'package.json' : JSON . stringify ( {
154+ name : 'test-fg-scripts' ,
155+ version : '0.0.0' ,
156+ scripts : {
157+ prepack : 'echo prepack!' ,
158+ postpack : 'echo postpack!' ,
159+ } ,
160+ }
161+ ) ,
162+ } ,
163+ config : { 'dry-run' : true , 'foreground-scripts' : false } ,
164+ } )
165+
166+ /* eslint no-console: 0 */
167+ // TODO: replace this with `const results = t.intercept(console, 'log')`
168+ const log = console . log
169+ t . teardown ( ( ) => {
170+ console . log = log
171+ } )
172+ const caughtLogs = [ ]
173+ console . log = ( ...args ) => {
174+ caughtLogs . push ( args )
175+ }
176+ // end TODO
177+
178+ await npm . exec ( 'pack' , [ ] )
179+ const filename = 'test-fg-scripts-0.0.0.tgz'
180+ t . same (
181+ caughtLogs ,
182+ [ ] ,
183+ 'prepack and postpack do not log to stdout' )
184+ t . strictSame ( outputs , [ [ filename ] ] )
185+ t . matchSnapshot ( logs . notice . map ( ( [ , m ] ) => m ) , 'logs pack contents' )
186+ t . throws ( ( ) => fs . statSync ( path . resolve ( npm . prefix , filename ) ) )
187+ } )
188+
108189t . test ( 'invalid packument' , async t => {
109190 const { npm, outputs } = await loadMockNpm ( t , {
110191 prefixDir : {
0 commit comments