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(image-aspect-ratio): pass audit when no images are missized #3552

Merged
merged 2 commits into from
Oct 13, 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: 6 additions & 0 deletions lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ <h2>Do better web tester page</h2>

</template>

<!-- FAIL(image-aspect-ratio): image is naturally 480x318 -->
<img src="lighthouse-480x318.jpg" width="480" height="57">
<!-- PASS(image-aspect-ratio) -->
<img src="lighthouse-480x318.jpg" width="480" height="318">


<!-- Some websites overwrite the original Error object. The captureJSCallUsage function
relies on the native Error object and prepareStackTrace from V8. When overwriting the stack
property the e.stack inside the gatherer won't be in the correct format
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 15 additions & 2 deletions lighthouse-cli/test/smokehouse/dobetterweb/dbw-expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ module.exports = [
extendedInfo: {
value: {
results: {
length: 14,
length: 15,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additional request for image in page

},
},
},
details: {
items: {
length: 14,
length: 15,
},
},
},
Expand Down Expand Up @@ -185,6 +185,19 @@ module.exports = [
},
},
},
'image-aspect-ratio': {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbw seemed like the best place for this since it's already running all of Best Practices, but happy to move

score: false,
details: {
items: {
0: {
2: {
text: /^480 x 57/,
},
},
length: 1,
},
},
},
},
}, {
initialUrl: 'http://localhost:10200/dobetterweb/domtester.html?smallDOM',
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/image-aspect-ratio.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class ImageAspectRatio extends Audit {
];

return {
rawValue: results.length,
rawValue: results.length === 0,
debugString,
details: Audit.makeTableDetails(headings, results),
};
Expand Down
36 changes: 24 additions & 12 deletions lighthouse-core/test/audits/image-aspect-ratio-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
'use strict';

const Audit = require('../../audits/image-aspect-ratio.js');
const ImageAspectRatioAudit = require('../../audits/image-aspect-ratio.js');
const assert = require('assert');

/* eslint-env mocha */
Expand All @@ -27,7 +27,7 @@ describe('Images: aspect-ratio audit', () => {
function testImage(condition, data) {
const description = `identifies when an image ${condition}`;
it(description, () => {
const result = Audit.audit({
const result = ImageAspectRatioAudit.audit({
ImageUsage: [
generateImage(
{width: data.clientSize[0], height: data.clientSize[1]},
Expand All @@ -38,12 +38,13 @@ describe('Images: aspect-ratio audit', () => {
],
});

assert.equal(result.rawValue, data.listed ? 1 : 0);
assert.strictEqual(result.rawValue, data.rawValue, 'rawValue does not match');
assert.strictEqual(result.debugString, data.debugString, 'debugString does not match');
});
}

testImage('is much larger than natural aspect ratio', {
listed: true,
rawValue: false,
clientSize: [800, 500],
naturalSize: [200, 200],
props: {
Expand All @@ -53,7 +54,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('is a css image and much larger than natural aspect ratio', {
listed: false,
rawValue: true,
clientSize: [],
naturalSize: [200, 200],
props: {
Expand All @@ -63,7 +64,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('is larger than natural aspect ratio', {
listed: true,
rawValue: false,
clientSize: [400, 300],
naturalSize: [200, 200],
props: {
Expand All @@ -73,7 +74,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('uses object-fit and is much smaller than natural aspect ratio', {
listed: false,
rawValue: true,
clientSize: [200, 200],
naturalSize: [800, 500],
props: {
Expand All @@ -83,7 +84,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('is much smaller than natural aspect ratio', {
listed: true,
rawValue: false,
clientSize: [200, 200],
naturalSize: [800, 500],
props: {
Expand All @@ -93,7 +94,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('is smaller than natural aspect ratio', {
listed: true,
rawValue: false,
clientSize: [200, 200],
naturalSize: [400, 300],
props: {
Expand All @@ -103,7 +104,7 @@ describe('Images: aspect-ratio audit', () => {
});

testImage('aspect ratios match', {
listed: false,
rawValue: true,
clientSize: [100, 100],
naturalSize: [300, 300],
props: {
Expand All @@ -112,13 +113,24 @@ describe('Images: aspect-ratio audit', () => {
},
});

testImage('has invalid sizing information', {
listed: false,
testImage('has no display sizing information', {
rawValue: true,
clientSize: [0, 0],
naturalSize: [100, 100],
props: {
isCss: false,
usesObjectFit: false,
},
});

testImage('has invalid natural sizing information', {
rawValue: true,
debugString: 'Invalid image sizing information https://google.com/logo.png',
clientSize: [100, 100],
naturalSize: [0, 0],
props: {
isCss: false,
usesObjectFit: false,
},
});
});