@@ -137,3 +137,46 @@ tape('use custom browserslist config', function (assert) {
137137 assert . ok ( / y i e l d / . test ( content ) , 'did not transpile yield keyword' )
138138 } )
139139} )
140+
141+ tape ( 'envify in watch mode' , function ( assert ) {
142+ assert . plan ( 5 )
143+
144+ var file = `
145+ console.log(process.env.BANKAI_TEST_VALUE)
146+ `
147+ var file2 = `
148+ var a = process.env.BANKAI_TEST_VALUE
149+ console.log({ a: a })
150+ `
151+
152+ var tmpDirname = path . join ( __dirname , '../tmp' , 'js-pipeline-' + ( Math . random ( ) * 1e4 ) . toFixed ( ) )
153+ mkdirp . sync ( tmpDirname )
154+ fs . writeFileSync ( path . join ( tmpDirname , 'app.js' ) , file )
155+
156+ process . env . BANKAI_TEST_VALUE = 'replacement'
157+ var compiler = bankai ( path . join ( tmpDirname , 'app.js' ) , { watch : true , reload : false } )
158+ compiler . on ( 'error' , assert . error )
159+ compiler . scripts ( 'bundle.js' , function ( err , res ) {
160+ assert . error ( err , 'no error writing script' )
161+ assert . notEqual ( res . buffer . toString ( 'utf8' ) . indexOf ( 'replacement' ) , - 1 , 'contains replacement value' )
162+
163+ compiler . graph . on ( 'change' , next )
164+
165+ // Wait for a bit before changing the source file, because the watcher setup isn't instant.
166+ setTimeout ( function ( ) {
167+ fs . writeFileSync ( path . join ( tmpDirname , 'app.js' ) , file2 )
168+ } , 500 )
169+ } )
170+
171+ function next ( stepName , nodeName ) {
172+ if ( stepName !== 'scripts' || nodeName !== 'bundle' ) return
173+ compiler . scripts ( 'bundle.js' , function ( err , res ) {
174+ assert . error ( err , 'no error writing script' )
175+ assert . notEqual ( res . buffer . toString ( 'utf8' ) . indexOf ( 'replacement' ) , - 1 , 'contains replacement value' )
176+ assert . notEqual ( res . buffer . toString ( 'utf8' ) . indexOf ( 'a: a' ) , - 1 , 'is the updated file' )
177+
178+ compiler . close ( )
179+ } )
180+ compiler . graph . removeListener ( 'change' , next )
181+ }
182+ } )
0 commit comments