Skip to content

Commit

Permalink
core(aspect-ratio): skip aspect ratio audit for svg (#3722)
Browse files Browse the repository at this point in the history
* core(aspect-ratio): skip aspect ratio audit for svg, fixes #3716

* core(aspect-ratio): use the correct svg mimeType in the test

* core(aspect-ratio): skip aspect ratio audit for svg

* core(aspect-ratio): use the correct svg mimeType in the test

* core(aspect-ratio): explain why svg is filtered

* core(aspect-ratio): better unit test (fails when it should)
  • Loading branch information
Peter Janes authored and patrickhulce committed Nov 2, 2017
1 parent fbe3fda commit cfc2afe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lighthouse-core/audits/image-aspect-ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ class ImageAspectRatio extends Audit {
let debugString;
const results = [];
images.filter(image => {
// filter out images that don't have following properties
// networkRecord, width, height, images that use `object-fit`: `cover` or `contain`
// - filter out images that don't have following properties:
// networkRecord, width, height, images that use `object-fit`: `cover` or `contain`
// - filter all svgs as they have no natural dimensions to audit
return image.networkRecord &&
image.networkRecord.mimeType !== 'image/svg+xml' &&
image.width &&
image.height &&
!image.usesObjectFit;
Expand Down
22 changes: 22 additions & 0 deletions lighthouse-core/test/audits/image-aspect-ratio-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,26 @@ describe('Images: aspect-ratio audit', () => {
usesObjectFit: false,
},
});

it('skips svg images', () => {
const result = ImageAspectRatioAudit.audit({
ImageUsage: [
generateImage(
{width: 150, height: 150},
{},
{
url: 'https://google.com/logo.png',
mimeType: 'image/svg+xml',
},
{
isCss: false,
usesObjectFit: false,
}
),
],
});

assert.strictEqual(result.rawValue, true, 'rawValue does not match');
assert.strictEqual(result.debugString, undefined, 'debugString does not match');
});
});

0 comments on commit cfc2afe

Please sign in to comment.