Repository: GoogleChrome/lighthouse
Pull request #6360 (2018-10-22 19:34:20)

i18n: update test for new canonical locale codes
Some recent ICU update (maybe in [Node 10.7](https://nodejs.org/en/blog/release/v10.7.0/)?) now acts upon the [recommended deprecation of some locale codes](https://www.unicode.org/cldr/charts/latest/supplemental/aliases.html) (namely, `in` -> `id` and `iw` -> `he`), and so we have a failure on a test checking that all our supported locales use canonical codes in more recent versions of Node.

For now we still support the deprecated codes with explicit aliases in `locales.js` because existing versions of Node won't do that extra canonicalization step, so this PR updates the test to recognize both the old and new behavior.


Patch:
diff --git a/.travis.yml b/.travis.yml
index 210f03e6e..362465fae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,7 @@ branches:
 matrix:
   include:
     - node_js: "8"
-    - node_js: "9"
+    - node_js: "10"
       if: head_branch IS blank AND branch = master
 dist: trusty
 cache:
@@ -42,7 +42,7 @@ script:
   - yarn test-viewer
   - yarn test-lantern
   - yarn i18n:checks
-  # _JAVA_OPTIONS is breaking parsing of compiler output. See #3338.
+  # _JAVA_OPTIONS is breaking parsing of `compile-devtools` output. See #3338.
   - unset _JAVA_OPTIONS
   # FIXME(paulirish): re-enable after a roll of LH->CDT
   # - yarn compile-devtools
diff --git a/lighthouse-core/audits/image-aspect-ratio.js b/lighthouse-core/audits/image-aspect-ratio.js
index ed70e01f6..750acafff 100644
--- a/lighthouse-core/audits/image-aspect-ratio.js
+++ b/lighthouse-core/audits/image-aspect-ratio.js
@@ -77,6 +77,8 @@ class ImageAspectRatio extends Audit {
       // - filter all svgs as they have no natural dimensions to audit
       return image.networkRecord &&
         image.networkRecord.mimeType !== 'image/svg+xml' &&
+        image.naturalHeight > 5 &&
+        image.naturalWidth > 5 &&
         image.width &&
         image.height &&
         !image.usesObjectFit;


Test patch:
diff --git a/lighthouse-core/test/audits/image-aspect-ratio-test.js b/lighthouse-core/test/audits/image-aspect-ratio-test.js
index b7ae1dc1d..ac438abe9 100644
--- a/lighthouse-core/test/audits/image-aspect-ratio-test.js
+++ b/lighthouse-core/test/audits/image-aspect-ratio-test.js
@@ -137,11 +137,10 @@ describe('Images: aspect-ratio audit', () => {
     },
   });
 
-  testImage('has invalid natural sizing information', {
+  testImage('is placeholder image', {
     rawValue: true,
-    warning: 'Invalid image sizing information https://google.com/logo.png',
-    clientSize: [100, 100],
-    naturalSize: [0, 0],
+    clientSize: [300, 220],
+    naturalSize: [1, 1],
     props: {
       isCss: false,
       usesObjectFit: false,
diff --git a/lighthouse-core/test/lib/i18n/locales-test.js b/lighthouse-core/test/lib/i18n/locales-test.js
index cf66ca390..eba944fa3 100644
--- a/lighthouse-core/test/lib/i18n/locales-test.js
+++ b/lighthouse-core/test/lib/i18n/locales-test.js
@@ -11,10 +11,25 @@ const assert = require('assert');
 /* eslint-env jest */
 
 describe('locales', () => {
-  it('has only canonical language tags', () => {
+  it('has only canonical (or expected-deprecated) language tags', () => {
+    // Map of deprecated codes to their canonical version. Depending on the ICU
+    // version used to run Lighthouse/this test, these *may* come back as their
+    // substitute, not themselves.
+    const deprecatedCodes = {
+      in: 'id',
+      iw: 'he',
+    };
+
     for (const locale of Object.keys(locales)) {
       const canonicalLocale = Intl.getCanonicalLocales(locale)[0];
-      assert.strictEqual(locale, canonicalLocale);
+      const substitute = deprecatedCodes[locale];
+      assert.ok(locale === canonicalLocale || substitute === canonicalLocale,
+          `locale code '${locale}' not canonical`);
+    }
+
+    // Deprecation subsitutes should be removed from the test if no longer used.
+    for (const locale of Object.keys(deprecatedCodes)) {
+      assert.ok(locales[locale], `${locale} substitute should be removed from test`);
     }
   });