diff --git a/lighthouse-core/test/config/config-helpers-test.js b/lighthouse-core/test/config/config-helpers-test.js index dd42fa7f9f11..7400e3582ad7 100644 --- a/lighthouse-core/test/config/config-helpers-test.js +++ b/lighthouse-core/test/config/config-helpers-test.js @@ -149,6 +149,11 @@ describe('.deepCloneConfigJson', () => { describe('.resolveSettings', () => { it('resolves the locale', () => { const settings = resolveSettings({locale: 'zh-CN'}); + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) { + expect(settings.locale).toEqual('en'); + return; + } expect(settings.locale).toEqual('zh'); }); diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index a0f381ee5982..9f01267fa987 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -828,6 +828,8 @@ describe('Config', () => { it('uses config setting for locale if set', () => { const locale = 'ar-XB'; const config = new Config({settings: {locale}}); + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) return; assert.strictEqual(config.settings.locale, locale); }); @@ -835,6 +837,8 @@ describe('Config', () => { const settingsLocale = 'en-XA'; const flagsLocale = 'ar-XB'; const config = new Config({settings: {locale: settingsLocale}}, {locale: flagsLocale}); + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) return; assert.strictEqual(config.settings.locale, flagsLocale); }); }); diff --git a/lighthouse-core/test/lib/i18n/i18n-test.js b/lighthouse-core/test/lib/i18n/i18n-test.js index dae823444c8f..cbb17f8a5b02 100644 --- a/lighthouse-core/test/lib/i18n/i18n-test.js +++ b/lighthouse-core/test/lib/i18n/i18n-test.js @@ -153,16 +153,34 @@ describe('i18n', () => { it('logs a warning if locale is not available and the default is used', () => { const logListener = jest.fn(); - log.events.once('warning', logListener); + log.events.on('warning', logListener); expect(i18n.lookupLocale(invalidLocale)).toEqual('en'); + // COMPAT: Node 12 logs an extra warning that full-icu is not available. + if (process.versions.node.startsWith('12')) { + expect(logListener).toBeCalledTimes(2); + expect(logListener).toHaveBeenNthCalledWith(1, ['i18n', + expect.stringMatching(/Requested locale not available in this version of node/)]); + expect(logListener).toHaveBeenNthCalledWith(2, ['i18n', + `locale(s) '${invalidLocale}' not available. Falling back to default 'en'`]); + return; + } + expect(logListener).toBeCalledTimes(1); expect(logListener).toBeCalledWith(['i18n', `locale(s) '${invalidLocale}' not available. Falling back to default 'en'`]); + + log.events.off('warning', logListener); }); it('falls back to root tag prefix if specific locale not available', () => { + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) { + expect(i18n.lookupLocale('es-JKJK')).toEqual('en'); + return; + } + expect(i18n.lookupLocale('es-JKJK')).toEqual('es'); }); diff --git a/lighthouse-core/test/lib/i18n/swap-locale-test.js b/lighthouse-core/test/lib/i18n/swap-locale-test.js index 6b6c2b0abc94..3c3b87dcf0e8 100644 --- a/lighthouse-core/test/lib/i18n/swap-locale-test.js +++ b/lighthouse-core/test/lib/i18n/swap-locale-test.js @@ -11,6 +11,25 @@ const lhr = require('../../results/sample_v2.json'); /* eslint-env jest */ describe('swap-locale', () => { + // COMPAT: Node 12 only has 'en' by default. Skip these tests since they're all about swapping locales. + if (process.versions.node.startsWith('12')) { + // Jest requires at least one test per suite. + it('runs even if other locales are not supported', () => { + /** @type {LH.Result} */ + const lhrClone = JSON.parse(JSON.stringify(lhr)); + + // Even though 'pt' is requested, 'en' is all that's available. + const lhrEn = swapLocale(lhr, 'pt').lhr; + expect(lhrEn.configSettings.locale).toBe('en'); + + // Set locale back to full 'en-US' do do the comparison. + lhrEn.configSettings.locale = 'en-US'; + expect(lhrEn).toStrictEqual(lhrClone); + }); + + return; + } + it('does not mutate the original lhr', () => { /** @type {LH.Result} */ const lhrClone = JSON.parse(JSON.stringify(lhr)); diff --git a/lighthouse-core/test/report/html/renderer/i18n-test.js b/lighthouse-core/test/report/html/renderer/i18n-test.js index a204edbc267a..3921ca9cc767 100644 --- a/lighthouse-core/test/report/html/renderer/i18n-test.js +++ b/lighthouse-core/test/report/html/renderer/i18n-test.js @@ -106,6 +106,9 @@ describe('util helpers', () => { }); it('formats numbers based on locale', () => { + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) return; + // Requires full-icu or Intl polyfill. const number = 12346.858558; @@ -117,6 +120,9 @@ describe('util helpers', () => { }); it('uses decimal comma with en-XA test locale', () => { + // COMPAT: Node 12 only has 'en' by default. + if (process.versions.node.startsWith('12')) return; + // Requires full-icu or Intl polyfill. const number = 12346.858558;