@@ -472,20 +472,45 @@ describe('SvgChunkWebpackPlugin', () => {
472472
473473 describe ( 'SvgChunkWebpackPlugin getFilename' , ( ) => {
474474 it ( 'Should call the getFilename function with default name' , ( ) => {
475- svgChunkWebpackPlugin . options . filename = 'sprite/[name].svg' ;
476- compilationWebpack . getPath . mockReturnValue ( 'sprite/home.svg' ) ;
475+ svgChunkWebpackPlugin . options . filename = 'sprites/[name].svg' ;
477476
478477 const result = svgChunkWebpackPlugin . getFilename ( {
479478 compilation : compilationWebpack ,
480479 entryName : 'home' ,
481480 output : spritesFixture . home
482481 } ) ;
483482
484- expect ( compilationWebpack . getPath ) . toHaveBeenCalledWith ( 'sprite/[name].svg' , {
485- filename : 'home'
483+ expect ( compilationWebpack . compiler . webpack . util . createHash ) . not . toHaveBeenCalled ( ) ;
484+ expect ( result ) . toBe ( 'sprites/home.svg' ) ;
485+ } ) ;
486+
487+ it ( 'Should call the getFilename function with default name with slashes' , ( ) => {
488+ svgChunkWebpackPlugin . options . filename = 'sprites/[name].svg' ;
489+
490+ const result = svgChunkWebpackPlugin . getFilename ( {
491+ compilation : compilationWebpack ,
492+ entryName : 'home/components/footer' ,
493+ output : spritesFixture . home
486494 } ) ;
495+
487496 expect ( compilationWebpack . compiler . webpack . util . createHash ) . not . toHaveBeenCalled ( ) ;
488- expect ( result ) . toBe ( 'sprite/home.svg' ) ;
497+ expect ( result ) . toBe ( 'sprites/home/components/footer.svg' ) ;
498+ } ) ;
499+
500+ it ( 'Should call the getFilename function with [fullhash]' , ( ) => {
501+ svgChunkWebpackPlugin . options . filename = 'sprites/[name].[fullhash].svg' ;
502+ compilationWebpack . outputOptions = {
503+ hashDigestLength : 20
504+ } ;
505+ compilationWebpack . fullHash = '117b8f68975f36a8c463a1b2c3d4e5f6' ;
506+
507+ const result = svgChunkWebpackPlugin . getFilename ( {
508+ compilation : compilationWebpack ,
509+ entryName : 'home' ,
510+ sprite : spritesFixture . home
511+ } ) ;
512+
513+ expect ( result ) . toStrictEqual ( 'sprites/home.117b8f68975f36a8c463.svg' ) ;
489514 } ) ;
490515
491516 it ( 'Should call the getFilename function with [contenthash]' , ( ) => {
@@ -495,19 +520,20 @@ describe('SvgChunkWebpackPlugin', () => {
495520 hashDigest : 'hex' ,
496521 hashDigestLength : 20
497522 } ;
498- compilationWebpack . getPath . mockReturnValue ( 'sprites/home.[contenthash].svg' ) ;
499523 compilationWebpack . compiler . webpack . util . createHash . mockReturnValue ( {
500524 update : jest . fn ( ) . mockReturnValue ( {
501525 digest : jest . fn ( ) . mockReturnValue ( {
502526 substring : jest . fn ( ) . mockReturnValue ( 'a1b2c3d4e5f6' )
503527 } )
504528 } )
505529 } ) ;
530+
506531 const result = svgChunkWebpackPlugin . getFilename ( {
507532 compilation : compilationWebpack ,
508533 entryName : 'home' ,
509534 sprite : spritesFixture . home
510535 } ) ;
536+
511537 expect ( compilationWebpack . compiler . webpack . util . createHash ) . toHaveBeenCalledWith ( 'md4' ) ;
512538 expect (
513539 compilationWebpack . compiler . webpack . util . createHash ( ) . update
0 commit comments