@@ -9,6 +9,7 @@ const pluginMock = {
99 plugin : {
1010 addFileToAssets : filename => Promise . resolve ( path . basename ( filename ) ) ,
1111 } ,
12+ outputName : 'index.html' ,
1213} ;
1314
1415test ( 'assets should always be an array' , ( ) => {
@@ -76,7 +77,7 @@ test.concurrent('should used passed in publicPath', async () => {
7677 expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
7778} ) ;
7879
79- // No idea what this does, actually... Coverage currently hits it, but the logic is untested.
80+ // TODO: No idea what this does, actually... Coverage currently hits it, but the logic is untested.
8081test ( 'should handle missing `publicPath`' ) ;
8182
8283test . concurrent ( 'should add file missing "/" to public path' , async ( ) => {
@@ -200,3 +201,41 @@ test.concurrent('should replace compilation assets key if `outputPath` is set',
200201 expect ( compilation . assets [ 'my-file.js.map' ] ) . toBeUndefined ( ) ;
201202 expect ( compilation . assets [ 'assets/my-file.js.map' ] ) . toEqual ( source ) ;
202203} ) ;
204+
205+ test . concurrent ( 'filter option should exclude some files' , async ( ) => {
206+ const callback = jest . fn ( ) ;
207+ const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
208+ const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
209+
210+ await addAllAssetsToCompilation (
211+ [ { filepath : path . join ( __dirname , 'my-file.js' ) , files : [ 'something-weird' ] } ] ,
212+ compilation ,
213+ pluginData ,
214+ callback
215+ ) ;
216+
217+ expect ( pluginData . assets . css ) . toEqual ( [ ] ) ;
218+ expect ( pluginData . assets . js ) . toEqual ( [ ] ) ;
219+
220+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
221+ expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
222+ } ) ;
223+
224+ test . concurrent ( 'filter option should include some files' , async ( ) => {
225+ const callback = jest . fn ( ) ;
226+ const compilation = { options : { output : { publicPath : 'vendor/' } } } ;
227+ const pluginData = Object . assign ( { assets : { js : [ ] , css : [ ] } } , pluginMock ) ;
228+
229+ await addAllAssetsToCompilation (
230+ [ { filepath : path . join ( __dirname , 'my-file.js' ) , files : [ 'index.*' ] } ] ,
231+ compilation ,
232+ pluginData ,
233+ callback
234+ ) ;
235+
236+ expect ( pluginData . assets . css ) . toEqual ( [ ] ) ;
237+ expect ( pluginData . assets . js ) . toEqual ( [ 'vendor/my-file.js' ] ) ;
238+
239+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
240+ expect ( callback ) . toHaveBeenCalledWith ( null , pluginData ) ;
241+ } ) ;
0 commit comments