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

Resolve audit result #487

Merged
merged 3 commits into from
Jul 8, 2016
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: 3 additions & 3 deletions lighthouse-cli/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ function createOutput(results, outputMode) {
}

item.subItems.forEach(subitem => {
let lineItem = ` -- ${subitem.description}: ${subitem.value}`;
if (typeof subitem.rawValue !== 'undefined') {
lineItem += ` (${subitem.rawValue})`;
let lineItem = ` -- ${subitem.description}: ${subitem.score}`;
if (subitem.displayValue) {
lineItem += ` (${subitem.displayValue})`;
}
output += `${lineItem}\n`;
if (subitem.debugString) {
Expand Down
7 changes: 5 additions & 2 deletions lighthouse-cli/test/fixtures/sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@
"description": "Users notice if sites and apps don't perform well. These top-level metrics capture the most important perceived performance concerns.",
"subItems": [
{
"value": 100,
"rawValue": "920.5ms",
"score": 100,
"displayValue": "920.5ms",
"rawValue": "920.5",
"optimalValue": "1,600ms",
"extendedInfo": {
"timings": {
Expand All @@ -57,6 +58,7 @@
},
{
"value": 99,
"displayValue": "1068",
"rawValue": 1068,
"optimalValue": "1,250",
"extendedInfo": {
Expand Down Expand Up @@ -301,6 +303,7 @@
},
{
"value": true,
"displayValue": "#4527A0",
"rawValue": "#4527A0",
"name": "theme-color-meta",
"category": "HTML",
Expand Down
15 changes: 8 additions & 7 deletions lighthouse-core/aggregator/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,28 @@ class Aggregate {
let weight = 0;

if (typeof expected === 'undefined' ||
typeof expected.value === 'undefined' ||
typeof expected.rawValue === 'undefined' ||
typeof expected.weight === 'undefined') {
return weight;
}

if (typeof result === 'undefined' ||
typeof result.value === 'undefined') {
typeof result.rawValue === 'undefined' ||
typeof result.score === 'undefined') {
return weight;
}

if (typeof result.value !== typeof expected.value) {
if (typeof result.rawValue !== typeof expected.rawValue) {
return weight;
}

switch (typeof expected.value) {
switch (typeof expected.rawValue) {
case 'boolean':
weight = this._convertBooleanToWeight(result.value, expected.value, expected.weight);
weight = this._convertBooleanToWeight(result.score, expected.rawValue, expected.weight);
break;

case 'number':
weight = this._convertNumberToWeight(result.value, expected.value, expected.weight);
weight = this._convertNumberToWeight(result.score, expected.rawValue, expected.weight);
break;

default:
Expand Down Expand Up @@ -154,7 +155,7 @@ class Aggregate {
// TODO(paullewis): Remove once coming soon audits have landed.
if (item.criteria[e].comingSoon) {
subItems.push({
value: '¯\\_(ツ)_/¯', // TODO(samthor): Patch going to Closure, String.raw is badly typed
score: '¯\\_(ツ)_/¯', // TODO(samthor): Patch going to Closure, String.raw is badly typed
name: 'coming-soon',
category: item.criteria[e].category,
description: item.criteria[e].description,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/aria-allowed-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ARIAAllowedAttr extends Audit {
artifacts.Accessibility.violations.find(result => result.id === 'aria-allowed-attr');

return ARIAAllowedAttr.generateAuditResult({
value: typeof rule === 'undefined',
rawValue: typeof rule === 'undefined',
debugString: this.createDebugString(rule),
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.ACCESSIBILITY,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/aria-valid-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ARIAValidAttr extends Audit {
artifacts.Accessibility.violations.find(result => result.id === 'aria-valid-attr');

return ARIAValidAttr.generateAuditResult({
value: typeof rule === 'undefined',
rawValue: typeof rule === 'undefined',
debugString: this.createDebugString(rule),
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.ACCESSIBILITY,
Expand Down
18 changes: 15 additions & 3 deletions lighthouse-core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,24 @@ class Audit {
* @return {!AuditResult}
*/
static generateAuditResult(result) {
if (typeof result.value === 'undefined') {
throw new Error('generateAuditResult requires a value');
if (typeof result.rawValue === 'undefined') {
throw new Error('generateAuditResult requires a rawValue');
}

let score = typeof result.score === 'undefined' ? result.rawValue : result.score;
let displayValue = result.displayValue;
if (typeof displayValue === 'undefined') {
displayValue = result.rawValue ? result.rawValue : '';
}

// The same value or true should be '' it doesn't add value to the report
if (displayValue === score) {
displayValue = '';
}

return {
value: result.value,
score,
displayValue: `${displayValue}`,
rawValue: result.rawValue,
debugString: result.debugString,
optimalValue: result.optimalValue,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/color-contrast.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ColorContrast extends Audit {
artifacts.Accessibility.violations.find(result => result.id === 'color-contrast');

return ColorContrast.generateAuditResult({
value: typeof rule === 'undefined',
rawValue: typeof rule === 'undefined',
debugString: this.createDebugString(rule),
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.ACCESSIBILITY,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/critical-request-chains.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CriticalRequestChains extends Audit {
walk(artifacts.CriticalRequestChains, 0);

return CriticalRequestChains.generateAuditResult({
value: chainCount,
rawValue: chainCount,
optimalValue: this.meta.optimalValue,
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.CRITICAL_REQUEST_CHAINS,
Expand Down
7 changes: 4 additions & 3 deletions lighthouse-core/audits/estimated-input-latency.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class EstimatedInputLatency extends Audit {
const latencyPercentiles = TracingProcessor.getRiskToResponsiveness(model, trace, startTime);

const ninetieth = latencyPercentiles.find(result => result.percentile === 0.9);
const rawValue = ninetieth.time.toFixed(1) + 'ms';
const rawValue = ninetieth.time.toFixed(1);

// Use the CDF of a log-normal distribution for scoring.
// 10th Percentile ≈ 58ms
Expand All @@ -69,17 +69,18 @@ class EstimatedInputLatency extends Audit {
let score = 100 * distribution.computeComplementaryPercentile(ninetieth.time);

return EstimatedInputLatency.generateAuditResult({
value: Math.round(score),
score: Math.round(score),
optimalValue: this.meta.optimalValue,
rawValue,
displayValue: `${rawValue}ms`,
extendedInfo: {
value: latencyPercentiles,
formatter: Formatter.SUPPORTED_FORMATS.ESTIMATED_INPUT_LATENCY
}
});
} catch (err) {
return EstimatedInputLatency.generateAuditResult({
value: -1,
rawValue: -1,
debugString: 'Unable to parse trace contents: ' + err.message
});
}
Expand Down
8 changes: 5 additions & 3 deletions lighthouse-core/audits/first-meaningful-paint.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ class FirstMeaningfulPaint extends Audit {
const result = this.calculateScore(data);

resolve(FirstMeaningfulPaint.generateAuditResult({
value: result.score,
score: result.score,
rawValue: result.duration,
displayValue: `${result.duration}ms`,
debugString: result.debugString,
optimalValue: this.meta.optimalValue,
extendedInfo: result.extendedInfo
}));
}).catch(err => {
// Recover from trace parsing failures.
return FirstMeaningfulPaint.generateAuditResult({
value: -1,
rawValue: -1,
debugString: err.message
});
});
Expand Down Expand Up @@ -127,8 +128,9 @@ class FirstMeaningfulPaint extends Audit {
score = Math.max(0, score);

return {
duration: `${firstMeaningfulPaint.toFixed(1)}ms`,
duration: `${firstMeaningfulPaint.toFixed(1)}`,
score: Math.round(score),
rawValue: firstMeaningfulPaint.toFixed(1),
extendedInfo: {timings}
};
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/image-alt.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ImageAlt extends Audit {
artifacts.Accessibility.violations.find(result => result.id === 'image-alt');

return ImageAlt.generateAuditResult({
value: typeof rule === 'undefined',
rawValue: typeof rule === 'undefined',
debugString: this.createDebugString(rule),
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.ACCESSIBILITY,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/is-on-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class HTTPS extends Audit {
*/
static audit(artifacts) {
return HTTPS.generateAuditResult({
value: artifacts.HTTPS.value,
rawValue: artifacts.HTTPS.value,
debugString: artifacts.HTTPS.debugString
});
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Label extends Audit {
artifacts.Accessibility.violations.find(result => result.id === 'label');

return Label.generateAuditResult({
value: typeof rule === 'undefined',
rawValue: typeof rule === 'undefined',
debugString: this.createDebugString(rule),
extendedInfo: {
formatter: Formatter.SUPPORTED_FORMATS.ACCESSIBILITY,
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-background-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ManifestBackgroundColor extends Audit {
.hasBackgroundColorValue(artifacts.Manifest.value);

return ManifestBackgroundColor.generateAuditResult({
value: hasBackgroundColor
rawValue: hasBackgroundColor
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/manifest-display.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class ManifestDisplay extends Audit {
const hasRecommendedValue = ManifestDisplay.hasRecommendedValue(displayValue);

return ManifestDisplay.generateAuditResult({
value: hasRecommendedValue,
rawValue: displayValue,
rawValue: hasRecommendedValue,
displayValue,
debugString: 'Manifest display property should be standalone or fullscreen.'
});
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-exists.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ManifestExists extends Audit {
*/
static audit(artifacts) {
return ManifestExists.generateAuditResult({
value: typeof artifacts.Manifest.value !== 'undefined',
rawValue: typeof artifacts.Manifest.value !== 'undefined',
debugString: artifacts.Manifest.debugString
});
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/manifest-icons-min-144.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ManifestIconsMin144 extends Audit {

if (icons.doExist(manifest) === false) {
return ManifestIconsMin144.generateAuditResult({
value: false,
rawValue: false,
debugString: 'WARNING: No icons found in the manifest'
});
}
Expand All @@ -51,7 +51,7 @@ class ManifestIconsMin144 extends Audit {
const foundSizesDebug = matchingIcons.length ?
`Found icons of sizes: ${matchingIcons}` : undefined;
return ManifestIconsMin144.generateAuditResult({
value: !!matchingIcons.length,
rawValue: !!matchingIcons.length,
debugString: foundSizesDebug
});
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/manifest-icons-min-192.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ManifestIconsMin192 extends Audit {

if (icons.doExist(manifest) === false) {
return ManifestIconsMin192.generateAuditResult({
value: false,
rawValue: false,
debugString: 'WARNING: No icons found in the manifest'
});
}
Expand All @@ -52,7 +52,7 @@ class ManifestIconsMin192 extends Audit {
const foundSizesDebug = matchingIcons.length ?
`Found icons of sizes: ${matchingIcons}` : undefined;
return ManifestIconsMin192.generateAuditResult({
value: !!matchingIcons.length,
rawValue: !!matchingIcons.length,
debugString: foundSizesDebug
});
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ManifestName extends Audit {
}

return ManifestName.generateAuditResult({
value: hasName
rawValue: hasName
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-short-name-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ManifestShortNameLength extends Audit {
}

return ManifestShortNameLength.generateAuditResult({
value: isShortNameShortEnough,
rawValue: isShortNameShortEnough,
debugString
});
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-short-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ManifestShortName extends Audit {
}

return ManifestShortName.generateAuditResult({
value: hasShortName
rawValue: hasShortName
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-start-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ManifestStartUrl extends Audit {
}

return ManifestStartUrl.generateAuditResult({
value: hasStartUrl
rawValue: hasStartUrl
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/audits/manifest-theme-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ManifestThemeColor extends Audit {
}

return ManifestThemeColor.generateAuditResult({
value: hasThemeColor
rawValue: hasThemeColor
});
}
}
Expand Down
10 changes: 5 additions & 5 deletions lighthouse-core/audits/meta-theme-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ class ThemeColor extends Audit {
const themeColorMeta = artifacts.ThemeColor;
if (!themeColorMeta) {
return ThemeColor.generateAuditResult({
value: false,
rawValue: false,
debugString: 'No valid theme-color meta tag found.'
});
}

if (!validColor(themeColorMeta)) {
return ThemeColor.generateAuditResult({
value: false,
rawValue: themeColorMeta,
displayValue: themeColorMeta,
rawValue: false,
debugString: 'The theme-color meta tag did not contain a valid CSS color.'
});
}

return ThemeColor.generateAuditResult({
value: true,
rawValue: themeColorMeta
displayValue: themeColorMeta,
rawValue: true
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/audits/redirects-http.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ class RedirectsHTTP extends Audit {
if (!artifacts.HTTPRedirect ||
!artifacts.HTTPRedirect.value) {
return RedirectsHTTP.generateAuditResult({
value: false
rawValue: false
});
}

return RedirectsHTTP.generateAuditResult({
value: artifacts.HTTPRedirect.value,
rawValue: artifacts.HTTPRedirect.value,
debugString: artifacts.HTTPRedirect.debugString
});
}
Expand Down
Loading