Repository: GoogleChrome/lighthouse (js)

Issue:
x-ms-bmp should be flagged under "serve images under next gen formats"
Discovered this while testing the `legacy-image-formats" feature policy, which warns developers about using legacy image formats like BMP. 

#### Provide the steps to reproduce
1. Run LH on https://feature-policy-demos.appspot.com/test

#### What is the current behavior?

LH does not recommend that a BMP image be served in another format.

#### What is the expected behavior?

There's a bmp image on that page (https://homepages.cae.wisc.edu/~ece533/images/sails.bmp) that should be flagged under the "serve images under next gen formats" audit:

<img width="774" alt="screen shot 2018-07-18 at 4 27 29 pm" src="https://user-images.githubusercontent.com/238208/42913040-82e056d4-8aa7-11e8-8a1c-f68f861101c1.png">

#### Environment Information
* Affected Channels: DevTools / all
* Lighthouse version: 3
* Node.js version: n/a
* Operating System: Mac os, canary 69.0.3495.0



Pull request description:
core(optimized-images): support non-standard mime types
**Related Issues/PRs**
fixes #5687


Patch:
diff --git a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
index b593ae9c1..80ee69be4 100644
--- a/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
+++ b/lighthouse-core/gather/gatherers/dobetterweb/optimized-images.js
@@ -21,6 +21,8 @@ const WEBP_QUALITY = 0.85;
 
 const MINIMUM_IMAGE_SIZE = 4096; // savings of <4 KB will be ignored in the audit anyway
 
+const IMAGE_REGEX = /^image\/((x|ms|x-ms)-)?(png|bmp|jpeg)$/;
+
 /** @typedef {{isSameOrigin: boolean, isBase64DataUri: boolean, requestId: string, url: string, mimeType: string, resourceSize: number}} SimplifiedNetworkRecord */
 
 /* global document, Image, atob */
@@ -87,7 +89,7 @@ class OptimizedImages extends Gatherer {
 
       seenUrls.add(record.url);
       const isOptimizableImage = record.resourceType === NetworkRequest.TYPES.Image &&
-        /image\/(png|bmp|jpeg)/.test(record.mimeType);
+        IMAGE_REGEX.test(record.mimeType);
       const isSameOrigin = URL.originsMatch(pageUrl, record.url);
       const isBase64DataUri = /^data:.{2,40}base64\s*,/.test(record.url);
 


Test patch:
diff --git a/lighthouse-core/test/audits/dobetterweb/doctype-test.js b/lighthouse-core/test/audits/dobetterweb/doctype-test.js
index 937aa568a..b77e49bf1 100644
--- a/lighthouse-core/test/audits/dobetterweb/doctype-test.js
+++ b/lighthouse-core/test/audits/dobetterweb/doctype-test.js
@@ -8,7 +8,7 @@
 const Audit = require('../../../audits/dobetterweb/doctype.js');
 const assert = require('assert');
 
-/* eslint-env mocha */
+/* eslint-env jest */
 
 describe('DOBETTERWEB: doctype audit', () => {
   it('fails when document does not contain a doctype', () => {
diff --git a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js
index 68dfe839c..d017f0387 100644
--- a/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js
+++ b/lighthouse-core/test/gather/gatherers/dobetterweb/optimized-images-test.js
@@ -5,7 +5,7 @@
  */
 'use strict';
 
-/* eslint-env mocha */
+/* eslint-env jest */
 
 const OptimizedImages =
     require('../../../../gather/gatherers/dobetterweb/optimized-images');
@@ -185,4 +185,23 @@ describe('Optimized images', () => {
       assert.ok(/gmail.*image.jpg/.test(artifact[3].url));
     });
   });
+
+  it('handles non-standard mime types too', async () => {
+    const traceData = {
+      networkRecords: [
+        {
+          requestId: '1',
+          url: 'http://google.com/image.bmp?x-ms',
+          mimeType: 'image/x-ms-bmp',
+          resourceSize: 12000,
+          transferSize: 20000,
+          resourceType: 'Image',
+          finished: true,
+        },
+      ],
+    };
+
+    const artifact = await optimizedImages.afterPass(options, traceData);
+    expect(artifact).toHaveLength(1);
+  });
 });