@@ -89,6 +89,14 @@ rollers.forEach(({rollup, version, opts, noTreeshake}) => {
8989 assert . is ( ( await analyze ( bundle , { filter : 'import-b' } ) ) . modules . length , 1 )
9090 } )
9191
92+ test ( `${ version } : filter with callback works` , async ( assert ) => {
93+ let bundle = await rollup ( opts )
94+ let noMatch = ( m ) => m . id . indexOf ( 'jimmy' ) !== - 1
95+ let hasMatch = ( m ) => m . id . indexOf ( 'import-b' ) !== - 1
96+ assert . is ( ( await analyze ( bundle , { filter : noMatch } ) ) . modules . length , 0 )
97+ assert . is ( ( await analyze ( bundle , { filter : hasMatch } ) ) . modules . length , 1 )
98+ } )
99+
92100 test ( `${ version } : root works as expected` , async ( assert ) => {
93101 let bundle = await rollup ( opts )
94102 assert . not (
@@ -114,7 +122,6 @@ rollers.forEach(({rollup, version, opts, noTreeshake}) => {
114122 let rollOpts = Object . assign ( { plugins : [ plugin ( { writeTo} ) ] } , opts )
115123 let bundle = await rollup ( rollOpts )
116124 await bundle . generate ( { format : 'cjs' } )
117- if ( version === 'latest' ) console . log ( results )
118125 assert . is ( results . substr ( 0 , expectHeader . length ) , expectHeader )
119126 } )
120127
@@ -130,5 +137,17 @@ rollers.forEach(({rollup, version, opts, noTreeshake}) => {
130137 let imported = results . find ( ( r ) => r . id . indexOf ( 'import-a' ) !== - 1 )
131138 assert . is ( imported . size , 27 )
132139 } )
140+
141+ test ( `${ version } : treeshaken bundle filters with callback` , async ( assert ) => {
142+ let results
143+ let filter = ( m ) => m . size > 2000
144+ let onAnalysis = ( r ) => { results = r . modules }
145+ let plugins = [ plugin ( { onAnalysis, filter} ) ]
146+ let rollOpts = Object . assign ( { } , opts , { plugins} )
147+ let bundle = await rollup ( rollOpts )
148+ let output = { file : join ( fixtures , 'output.js' ) , format : 'cjs' }
149+ await bundle . write ( output )
150+ assert . is ( results . length , 1 )
151+ } )
133152 }
134153} )
0 commit comments