File tree Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Expand file tree Collapse file tree 4 files changed +32
-6
lines changed Original file line number Diff line number Diff line change @@ -118,13 +118,25 @@ describe('client-hmr', () => {
118
118
expect ( i18nMock . changeLanguage ) . toHaveBeenCalledWith ( 'en' ) ;
119
119
} ) ;
120
120
121
- it ( 'should trigger reload when lng-country combination file changed' , async ( ) => {
121
+ it ( 'should pass changed filed to the i18next getter' , ( ) => {
122
+ i18nMock . options = { backend : { } , ns : [ 'name-space' ] } ;
123
+ i18nMock . language = 'en' ;
124
+ const getter = jest . fn ( ) . mockImplementation ( ( ) => i18nMock ) ;
125
+ const changedFiles = [ 'en/name-space' ] ;
126
+
127
+ applyClientHMR ( getter ) ;
128
+ whenHotTriggeredWith ( changedFiles ) ;
129
+
130
+ expect ( getter ) . toHaveBeenCalledWith ( { changedFiles } ) ;
131
+ } ) ;
132
+
133
+ it ( 'should trigger reload when lng-country combination file changed' , ( ) => {
122
134
i18nMock . options = { backend : { } , ns : [ 'name-space' ] } ;
123
135
i18nMock . language = 'en-US' ;
124
136
125
137
applyClientHMR ( i18nMock ) ;
126
138
127
- await whenHotTriggeredWith ( [ 'en-US/name-space' ] ) ;
139
+ whenHotTriggeredWith ( [ 'en-US/name-space' ] ) ;
128
140
129
141
expect ( i18nMock . reloadResources ) . toHaveBeenCalledWith (
130
142
[ 'en-US' ] ,
Original file line number Diff line number Diff line change @@ -401,12 +401,12 @@ describe('server-hmr', () => {
401
401
accept : jest . fn ( ) ,
402
402
} ,
403
403
} ;
404
-
405
- applyServerHMR ( ( ) => i18nMock ) ;
406
404
} ) ;
407
405
408
406
it ( 'should reload resources on updated lang, ns' , ( ) => {
409
407
const update = { lang : 'en' , ns : 'name-space' } ;
408
+ applyServerHMR ( ( ) => i18nMock ) ;
409
+
410
410
whenNativeHMRTriggeredWith ( [ `${ update . lang } /${ update . ns } ` ] ) ;
411
411
412
412
expect ( i18nMock . reloadResources ) . toHaveBeenCalledWith (
@@ -415,5 +415,17 @@ describe('server-hmr', () => {
415
415
expect . any ( Function )
416
416
) ;
417
417
} ) ;
418
+
419
+ it ( 'should pass changed filed to the i18next getter' , ( ) => {
420
+ const update = { lang : 'en' , ns : 'name-space' } ;
421
+
422
+ const getter = jest . fn ( ) . mockImplementation ( ( ) => i18nMock ) ;
423
+ const changedFiles = [ `${ update . lang } /${ update . ns } ` ] ;
424
+ applyServerHMR ( getter ) ;
425
+
426
+ whenNativeHMRTriggeredWith ( changedFiles ) ;
427
+
428
+ expect ( getter ) . toHaveBeenCalledWith ( { changedFiles } ) ;
429
+ } ) ;
418
430
} ) ;
419
431
} ) ;
Original file line number Diff line number Diff line change @@ -49,7 +49,8 @@ module.exports = function applyClientHMR(i18nOrGetter) {
49
49
50
50
module . hot . accept ( './trigger.js' , ( ) => {
51
51
const { changedFiles } = require ( './trigger.js' ) ;
52
- const i18nInstance = typeof i18nOrGetter === 'function' ? i18nOrGetter ( ) : i18nOrGetter ;
52
+ const i18nInstance =
53
+ typeof i18nOrGetter === 'function' ? i18nOrGetter ( { changedFiles } ) : i18nOrGetter ;
53
54
54
55
const list = extractList ( changedFiles , i18nInstance ) ;
55
56
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ module.exports = function applyServerHMR(i18nOrGetter) {
9
9
const logOnce = createLoggerOnce ( log ) ;
10
10
11
11
function reloadServerTranslation ( { changedFiles } ) {
12
- const i18nInstance = typeof i18nOrGetter === 'function' ? i18nOrGetter ( ) : i18nOrGetter ;
12
+ const i18nInstance =
13
+ typeof i18nOrGetter === 'function' ? i18nOrGetter ( { changedFiles } ) : i18nOrGetter ;
13
14
14
15
const list = extractList ( changedFiles , i18nInstance ) ;
15
16
You can’t perform that action at this time.
0 commit comments