@@ -55,9 +55,9 @@ describe('Webpack replace loader ...', () => {
5555 test : / \. j s $ / ,
5656 loader : '__this-loader' ,
5757 options : {
58- search : ' var VALUE = \'\.*\'' ,
59- replace : ' var a = \'\'' ,
60- flags : 'i '
58+ search : ` var VALUE = '.*'` ,
59+ replace : ` var a = ''` ,
60+ flags : 'ig '
6161 }
6262 } ) ,
6363 ( error , stats ) => {
@@ -67,7 +67,7 @@ describe('Webpack replace loader ...', () => {
6767 expect ( error ) . to . equal ( null )
6868 expect ( contents ) . to . be . a ( 'string' )
6969 expect ( contents ) . to . not . include ( 'var value' )
70- expect ( contents ) . to . include ( ' var a = \'\'' )
70+ expect ( contents ) . to . include ( ` var a = ''` )
7171 done ( )
7272 } )
7373 }
@@ -107,6 +107,30 @@ describe('Webpack replace loader ...', () => {
107107 )
108108 } )
109109
110+ it ( 'should replace with function replace' , done => {
111+ webpack ( getTestWebPackConfig (
112+ {
113+ test : / \. j s $ / ,
114+ loader : '__this-loader' ,
115+ options : {
116+ search : `var value = '(baz)'` ,
117+ replace : ( match , p1 , offset , string ) => `var a = '${ p1 . toUpperCase ( ) } '` ,
118+ flags : 'g'
119+ }
120+ } ) ,
121+ ( error , stats ) => {
122+ expect ( error ) . to . equal ( null )
123+
124+ fs . readFile ( outputFilePath , 'utf8' , ( error , contents ) => {
125+ expect ( error ) . to . equal ( null )
126+ expect ( contents ) . to . be . a ( 'string' )
127+ expect ( contents ) . to . include ( `var a = 'BAZ'` )
128+ done ( )
129+ } )
130+ }
131+ )
132+ } )
133+
110134 it ( 'should replace using multiple queries' , done => {
111135 webpack ( getTestWebPackConfig (
112136 {
0 commit comments