Repository: GoogleChrome/lighthouse
Pull request #9388 (2019-07-17 12:11:43)

core: fix serverResponseTime typo in network-server-latency
<!-- Thank you for submitting a pull request! -->

**Summary**
<!-- What kind of change does this PR introduce? -->
This fixes a typo for `network-server-latency`, which has currently `serverReponseTime` instead of `serverResponseTime` (and maybe cause bugs when trying to get some values out of the JSON).
<!-- Is this a bugfix, feature, refactoring, build related change, etc? -->


Patch:
diff --git a/lighthouse-core/audits/network-server-latency.js b/lighthouse-core/audits/network-server-latency.js
index 03c153970..bd65c5037 100644
--- a/lighthouse-core/audits/network-server-latency.js
+++ b/lighthouse-core/audits/network-server-latency.js
@@ -45,22 +45,22 @@ class NetworkServerLatency extends Audit {
 
     /** @type {number} */
     let maxLatency = 0;
-    /** @type {Array<{origin: string, serverReponseTime: number}>} */
+    /** @type {Array<{origin: string, serverResponseTime: number}>} */
     const results = [];
-    for (const [origin, serverReponseTime] of analysis.serverResponseTimeByOrigin.entries()) {
+    for (const [origin, serverResponseTime] of analysis.serverResponseTimeByOrigin.entries()) {
       // Ignore entries that don't look like real origins, like the __SUMMARY__ entry.
       if (!origin.startsWith('http')) continue;
 
-      maxLatency = Math.max(serverReponseTime, maxLatency);
-      results.push({origin, serverReponseTime});
+      maxLatency = Math.max(serverResponseTime, maxLatency);
+      results.push({origin, serverResponseTime});
     }
 
-    results.sort((a, b) => b.serverReponseTime - a.serverReponseTime);
+    results.sort((a, b) => b.serverResponseTime - a.serverResponseTime);
 
     /** @type {LH.Audit.Details.Table['headings']} */
     const headings = [
       {key: 'origin', itemType: 'text', text: str_(i18n.UIStrings.columnURL)},
-      {key: 'serverReponseTime', itemType: 'ms', granularity: 1,
+      {key: 'serverResponseTime', itemType: 'ms', granularity: 1,
         text: str_(i18n.UIStrings.columnTimeSpent)},
     ];
 
diff --git a/lighthouse-core/lib/i18n/i18n.js b/lighthouse-core/lib/i18n/i18n.js
index d3da92e48..a6c302101 100644
--- a/lighthouse-core/lib/i18n/i18n.js
+++ b/lighthouse-core/lib/i18n/i18n.js
@@ -127,9 +127,7 @@ function lookupLocale(locale) {
  * @param {string} icuMessage
  * @param {Record<string, *>} [values]
  */
-function _preprocessMessageValues(icuMessage, values) {
-  if (!values) return;
-
+function _preprocessMessageValues(icuMessage, values = {}) {
   const clonedValues = JSON.parse(JSON.stringify(values));
   const parsed = MessageParser.parse(icuMessage);
   // Throw an error if a message's value isn't provided
@@ -137,7 +135,7 @@ function _preprocessMessageValues(icuMessage, values) {
     .filter(el => el.type === 'argumentElement')
     .forEach(el => {
       if (el.id && (el.id in values) === false) {
-        throw new Error('ICU Message contains a value reference that wasn\'t provided');
+        throw new Error(`ICU Message contains a value reference ("${el.id}") that wasn't provided`);
       }
     });
 
diff --git a/proto/sample_v2_round_trip.json b/proto/sample_v2_round_trip.json
index 0c03c90c9..7a1d26952 100644
--- a/proto/sample_v2_round_trip.json
+++ b/proto/sample_v2_round_trip.json
@@ -1824,18 +1824,18 @@
                     {
                         "granularity": 1.0,
                         "itemType": "ms",
-                        "key": "serverReponseTime",
+                        "key": "serverResponseTime",
                         "text": "Time Spent"
                     }
                 ],
                 "items": [
                     {
                         "origin": "http://localhost:10200",
-                        "serverReponseTime": 572.829
+                        "serverResponseTime": 572.829
                     },
                     {
                         "origin": "http://ajax.googleapis.com",
-                        "serverReponseTime": 562.398
+                        "serverResponseTime": 562.398
                     }
                 ],
                 "type": "table"
@@ -4991,4 +4991,4 @@
         "total": 12345.6789
     },
     "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36"
-}
\ No newline at end of file
+}


Test patch:
diff --git a/lighthouse-core/test/audits/network-server-latency-test.js b/lighthouse-core/test/audits/network-server-latency-test.js
index 37535f00d..ec5de79d3 100644
--- a/lighthouse-core/test/audits/network-server-latency-test.js
+++ b/lighthouse-core/test/audits/network-server-latency-test.js
@@ -16,7 +16,7 @@ describe('Network Server Latency audit', () => {
     const artifacts = {devtoolsLogs: {defaultPass: acceptableDevToolsLog}};
     const result = await ServerLatency.audit(artifacts, {computedCache: new Map()});
     result.details.items.forEach(
-      item => (item.serverReponseTime = Math.round(item.serverReponseTime * 100) / 100)
+      item => (item.serverResponseTime = Math.round(item.serverResponseTime * 100) / 100)
     );
 
     // These were all from a trace that used our ancient 150ms devtools throttling which appears as
@@ -24,15 +24,15 @@ describe('Network Server Latency audit', () => {
     expect(result.details.items).toEqual([
       {
         origin: 'https://www.google-analytics.com',
-        serverReponseTime: 159.55,
+        serverResponseTime: 159.55,
       },
       {
         origin: 'https://pwa.rocks',
-        serverReponseTime: 159.42,
+        serverResponseTime: 159.42,
       },
       {
         origin: 'https://www.googletagmanager.com',
-        serverReponseTime: 153.03,
+        serverResponseTime: 153.03,
       },
     ]);
   });
diff --git a/lighthouse-core/test/lib/i18n/i18n-test.js b/lighthouse-core/test/lib/i18n/i18n-test.js
index 185c1df5e..2782a2bb1 100644
--- a/lighthouse-core/test/lib/i18n/i18n-test.js
+++ b/lighthouse-core/test/lib/i18n/i18n-test.js
@@ -102,6 +102,7 @@ describe('i18n', () => {
       helloSecWorld: 'Hello {in, number, seconds} World',
       helloTimeInMsWorld: 'Hello {timeInMs, number, seconds} World',
       helloPercentWorld: 'Hello {in, number, extendedPercent} World',
+      helloWorldMultiReplace: '{hello} {world}',
     };
     const str_ = i18n.createMessageInstanceIdFn(__filename, UIStrings);
 
@@ -134,5 +135,16 @@ describe('i18n', () => {
       const helloPercentStr = str_(UIStrings.helloPercentWorld, {in: 0.43078});
       expect(helloPercentStr).toBeDisplayString('Hello 43.08% World');
     });
+
+    it('throws an error when values are needed but not provided', () => {
+      expect(_ => i18n.getFormatted(str_(UIStrings.helloBytesWorld), 'en-US'))
+      .toThrow(`ICU Message contains a value reference ("in") that wasn't provided`);
+    });
+
+    it('throws an error when a value is missing', () => {
+      expect(_ => i18n.getFormatted(str_(UIStrings.helloWorldMultiReplace,
+        {hello: 'hello'}), 'en-US'))
+      .toThrow(`ICU Message contains a value reference ("world") that wasn't provided`);
+    });
   });
 });
diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json
index ea1424095..fdb70f610 100644
--- a/lighthouse-core/test/results/sample_v2.json
+++ b/lighthouse-core/test/results/sample_v2.json
@@ -1127,7 +1127,7 @@
             "text": "URL"
           },
           {
-            "key": "serverReponseTime",
+            "key": "serverResponseTime",
             "itemType": "ms",
             "granularity": 1,
             "text": "Time Spent"
@@ -1136,11 +1136,11 @@
         "items": [
           {
             "origin": "http://localhost:10200",
-            "serverReponseTime": 572.829
+            "serverResponseTime": 572.829
           },
           {
             "origin": "http://ajax.googleapis.com",
-            "serverReponseTime": 562.398
+            "serverResponseTime": 562.398
           }
         ]
       }
@@ -6336,4 +6336,4 @@
       }
     }
   ]
-}
\ No newline at end of file
+}