@@ -11,6 +11,7 @@ import * as constants from '../../../core/config/constants.js';
11
11
import * as format from '../../localization/format.js' ;
12
12
import { locales } from '../../localization/locales.js' ;
13
13
import { getModuleDirectory , getModulePath } from '../../../esm-utils.js' ;
14
+ import { LH_ROOT } from '../../../root.js' ;
14
15
15
16
const moduleDir = getModuleDirectory ( import . meta) ;
16
17
const modulePath = getModulePath ( import . meta) ;
@@ -185,37 +186,41 @@ describe('format', () => {
185
186
expect ( formattedStr ) . toEqual ( 'en-XZ cuerda!' ) ;
186
187
} ) ;
187
188
188
- it ( 'overwrites existing locale strings' , async ( ) => {
189
- const filename = 'core/audits/is-on-https.js' ;
190
- const { UIStrings} = await import ( '../../../core/audits/is-on-https.js' ) ;
191
- const str_ = i18n . createIcuMessageFn ( filename , UIStrings ) ;
192
-
193
- // To start with, we get back the intended string..
194
- const origTitle = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
195
- expect ( origTitle ) . toEqual ( 'Usa HTTPS' ) ;
196
- const origFailureTitle = format . getFormatted ( str_ ( UIStrings . failureTitle ) , 'es-419' ) ;
197
- expect ( origFailureTitle ) . toEqual ( 'No usa HTTPS' ) ;
198
-
199
- // Now we declare and register the new string...
200
- const localeData = {
201
- 'core/audits/is-on-https.js | title' : {
202
- 'message' : 'new string for es-419 uses https!' ,
203
- } ,
204
- } ;
205
- format . registerLocaleData ( 'es-419' , localeData ) ;
206
-
207
- // And confirm that's what is returned
208
- const newTitle = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
209
- expect ( newTitle ) . toEqual ( 'new string for es-419 uses https!' ) ;
210
-
211
- // Meanwhile another string that wasn't set in registerLocaleData just falls back to english
212
- const newFailureTitle = format . getFormatted ( str_ ( UIStrings . failureTitle ) , 'es-419' ) ;
213
- expect ( newFailureTitle ) . toEqual ( 'Does not use HTTPS' ) ;
214
-
215
- // Restore overwritten strings to avoid messing with other tests
216
- locales [ 'es-419' ] = clonedLocales [ 'es-419' ] ;
217
- const title = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
218
- expect ( title ) . toEqual ( 'Usa HTTPS' ) ;
189
+ [
190
+ { label : 'relative path' , filename : 'core/audits/is-on-https.js' } ,
191
+ { label : 'absolute path' , filename : `${ LH_ROOT } /core/audits/is-on-https.js` } ,
192
+ ] . forEach ( ( { label, filename} ) => {
193
+ it ( `overwrites existing locale strings: ${ label } ` , async ( ) => {
194
+ const { UIStrings} = await import ( '../../../core/audits/is-on-https.js' ) ;
195
+ const str_ = i18n . createIcuMessageFn ( filename , UIStrings ) ;
196
+
197
+ // To start with, we get back the intended string..
198
+ const origTitle = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
199
+ expect ( origTitle ) . toEqual ( 'Usa HTTPS' ) ;
200
+ const origFailureTitle = format . getFormatted ( str_ ( UIStrings . failureTitle ) , 'es-419' ) ;
201
+ expect ( origFailureTitle ) . toEqual ( 'No usa HTTPS' ) ;
202
+
203
+ // Now we declare and register the new string...
204
+ const localeData = {
205
+ 'core/audits/is-on-https.js | title' : {
206
+ 'message' : 'new string for es-419 uses https!' ,
207
+ } ,
208
+ } ;
209
+ format . registerLocaleData ( 'es-419' , localeData ) ;
210
+
211
+ // And confirm that's what is returned
212
+ const newTitle = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
213
+ expect ( newTitle ) . toEqual ( 'new string for es-419 uses https!' ) ;
214
+
215
+ // Meanwhile another string that wasn't set in registerLocaleData just falls back to english
216
+ const newFailureTitle = format . getFormatted ( str_ ( UIStrings . failureTitle ) , 'es-419' ) ;
217
+ expect ( newFailureTitle ) . toEqual ( 'Does not use HTTPS' ) ;
218
+
219
+ // Restore overwritten strings to avoid messing with other tests
220
+ locales [ 'es-419' ] = clonedLocales [ 'es-419' ] ;
221
+ const title = format . getFormatted ( str_ ( UIStrings . title ) , 'es-419' ) ;
222
+ expect ( title ) . toEqual ( 'Usa HTTPS' ) ;
223
+ } ) ;
219
224
} ) ;
220
225
} ) ;
221
226
0 commit comments