@@ -359,6 +359,55 @@ describe('parser', () => {
359359 i18nextParser . end ( fakeFile )
360360 } )
361361
362+ it ( 'ignores empty keys by default' , ( done ) => {
363+ let resultContent
364+ const i18nextParser = new i18nTransform ( {
365+ locales : [ 'en' ] ,
366+ defaultNamespace : 'test_empty_keys' ,
367+ } )
368+ const fakeFile = new Vinyl ( {
369+ contents : Buffer . from ( "t('key'); t('');" ) ,
370+ path : 'file.js' ,
371+ } )
372+
373+ i18nextParser . on ( 'data' , ( file ) => {
374+ if ( file . relative . endsWith ( path . normalize ( 'en/test_empty_keys.json' ) ) ) {
375+ resultContent = JSON . parse ( file . contents )
376+ }
377+ } )
378+ i18nextParser . on ( 'end' , ( ) => {
379+ assert . deepEqual ( resultContent , { key : '' } )
380+ done ( )
381+ } )
382+
383+ i18nextParser . end ( fakeFile )
384+ } )
385+
386+ it ( 'includes empty keys when ignoreEmptyKeys is false' , ( done ) => {
387+ let resultContent
388+ const i18nextParser = new i18nTransform ( {
389+ locales : [ 'en' ] ,
390+ defaultNamespace : 'test_ignore_empty' ,
391+ ignoreEmptyKeys : false ,
392+ } )
393+ const fakeFile = new Vinyl ( {
394+ contents : Buffer . from ( "t('key'); t('');" ) ,
395+ path : 'file.js' ,
396+ } )
397+
398+ i18nextParser . on ( 'data' , ( file ) => {
399+ if ( file . relative . endsWith ( path . normalize ( 'en/test_ignore_empty.json' ) ) ) {
400+ resultContent = JSON . parse ( file . contents )
401+ }
402+ } )
403+ i18nextParser . on ( 'end' , ( ) => {
404+ assert . deepEqual ( resultContent , { key : '' , '' : '' } )
405+ done ( )
406+ } )
407+
408+ i18nextParser . end ( fakeFile )
409+ } )
410+
362411 it ( 'applies withTranslation namespace globally' , ( done ) => {
363412 let result
364413 const i18nextParser = new i18nTransform ( )
0 commit comments