Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(aspect-ratio): skip aspect ratio audit for svg #3722

Merged
merged 7 commits into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});
});