Skip to content

Commit

Permalink
core(lhr): s/audits/auditRefs, s/category.name/category.title/ (#5157)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed May 9, 2018
1 parent 5a92d7c commit 83cb1f7
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 116 deletions.
26 changes: 13 additions & 13 deletions lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function validateCategories(categories, audits, groups) {
}

Object.keys(categories).forEach(categoryId => {
categories[categoryId].audits.forEach((auditRef, index) => {
categories[categoryId].auditRefs.forEach((auditRef, index) => {
if (!auditRef.id) {
throw new Error(`missing an audit id at ${categoryId}[${index}]`);
}
Expand Down Expand Up @@ -460,7 +460,7 @@ class Config {

/**
* Filter out any unrequested categories or audits from the categories object.
* @param {!Object<string, {audits: !Array<{id: string}>}>} categories
* @param {!Object<string, {auditRefs: !Array<{id: string}>}>} categories
* @param {!Array<string>=} categoryIds
* @param {!Array<string>=} auditIds
* @param {!Array<string>=} skipAuditIds
Expand Down Expand Up @@ -489,8 +489,8 @@ class Config {
const auditsToValidate = new Set(auditIds.concat(skipAuditIds));
for (const auditId of auditsToValidate) {
const foundCategory = Object.keys(oldCategories).find(categoryId => {
const audits = oldCategories[categoryId].audits;
return audits.find(candidate => candidate.id === auditId);
const auditRefs = oldCategories[categoryId].auditRefs;
return auditRefs.find(candidate => candidate.id === auditId);
});

if (!foundCategory) {
Expand All @@ -513,37 +513,37 @@ class Config {
if (filterByIncludedCategory && filterByIncludedAudit) {
// If we're filtering to the category and audit whitelist, include the union of the two
if (!categoryIds.includes(categoryId)) {
category.audits = category.audits.filter(audit => auditIds.includes(audit.id));
category.auditRefs = category.auditRefs.filter(audit => auditIds.includes(audit.id));
}
} else if (filterByIncludedCategory) {
// If we're filtering to just the category whitelist and the category is not included, skip it
if (!categoryIds.includes(categoryId)) {
return;
}
} else if (filterByIncludedAudit) {
category.audits = category.audits.filter(audit => auditIds.includes(audit.id));
category.auditRefs = category.auditRefs.filter(audit => auditIds.includes(audit.id));
}

// always filter to the audit blacklist
category.audits = category.audits.filter(audit => !skipAuditIds.includes(audit.id));
category.auditRefs = category.auditRefs.filter(audit => !skipAuditIds.includes(audit.id));

if (category.audits.length) {
if (category.auditRefs.length) {
categories[categoryId] = category;
category.audits.forEach(audit => includedAudits.add(audit.id));
category.auditRefs.forEach(audit => includedAudits.add(audit.id));
}
});

return {categories, audits: includedAudits};
}

/**
* @param {{categories: !Object<string, {name: string}>}} config
* @return {!Array<{id: string, name: string}>}
* @param {{categories: !Object<string, {title: string}>}} config
* @return {!Array<{id: string, title: string}>}
*/
static getCategories(config) {
return Object.keys(config.categories).map(id => {
const name = config.categories[id].name;
return {id, name};
const title = config.categories[id].title;
return {id, title};
});
}

Expand Down
22 changes: 11 additions & 11 deletions lighthouse-core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
passName: 'defaultPass',
recordTrace: true,
useThrottling: true,
pauseAfterLoadMs: 1000,
pauseAfterLoadMs: 10000,
networkQuietThresholdMs: 1000,
cpuQuietThresholdMs: 1000,
gatherers: [
Expand Down Expand Up @@ -246,8 +246,8 @@ module.exports = {
},
categories: {
'performance': {
name: 'Performance',
audits: [
title: 'Performance',
auditRefs: [
{id: 'first-contentful-paint', weight: 3, group: 'metrics'},
{id: 'first-meaningful-paint', weight: 1, group: 'metrics'},
{id: 'speed-index', weight: 4, group: 'metrics'},
Expand Down Expand Up @@ -283,12 +283,12 @@ module.exports = {
],
},
'pwa': {
name: 'Progressive Web App',
title: 'Progressive Web App',
description: 'These checks validate the aspects of a Progressive Web App, as specified by the baseline [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist).',
manualDescription: 'These checks are required by the baseline ' +
'[PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist) but are ' +
'not automatically checked by Lighthouse. They do not affect your score but it\'s important that you verify them manually.',
audits: [
auditRefs: [
{id: 'service-worker', weight: 1},
{id: 'works-offline', weight: 1},
{id: 'without-javascript', weight: 1},
Expand All @@ -307,10 +307,10 @@ module.exports = {
],
},
'accessibility': {
name: 'Accessibility',
title: 'Accessibility',
description: 'These checks highlight opportunities to [improve the accessibility of your web app](https://developers.google.com/web/fundamentals/accessibility). Only a subset of accessibility issues can be automatically detected so manual testing is also encouraged.',
manualDescription: 'These items address areas which an automated testing tool cannot cover. Learn more in our guide on [conducting an accessibility review](https://developers.google.com/web/fundamentals/accessibility/how-to-review).',
audits: [
auditRefs: [
{id: 'accesskeys', weight: 1, group: 'a11y-correct-attributes'},
{id: 'aria-allowed-attr', weight: 3, group: 'a11y-aria'},
{id: 'aria-required-attr', weight: 2, group: 'a11y-aria'},
Expand Down Expand Up @@ -360,8 +360,8 @@ module.exports = {
],
},
'best-practices': {
name: 'Best Practices',
audits: [
title: 'Best Practices',
auditRefs: [
{id: 'appcache-manifest', weight: 1},
{id: 'no-websql', weight: 1},
{id: 'is-on-https', weight: 1},
Expand All @@ -381,12 +381,12 @@ module.exports = {
],
},
'seo': {
name: 'SEO',
title: 'SEO',
description: 'These checks ensure that your page is optimized for search engine results ranking. ' +
'There are additional factors Lighthouse does not check that may affect your search ranking. ' +
'[Learn more](https://support.google.com/webmasters/answer/35769).',
manualDescription: 'Run these additional validators on your site to check additional SEO best practices.',
audits: [
auditRefs: [
{id: 'viewport', weight: 1, group: 'seo-mobile'},
{id: 'document-title', weight: 1, group: 'seo-content'},
{id: 'meta-description', weight: 1, group: 'seo-content'},
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/config/full-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
],
categories: {
'performance': {
audits: [
auditRefs: [
{id: 'unused-javascript', weight: 0, group: 'load-opportunities'},
],
},
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/config/mixed-content-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ module.exports = {

categories: {
mixedContent: {
name: 'Mixed Content',
title: 'Mixed Content',
description: 'These audits check which resources support HTTPS and ' +
'which are potentially blocking the page from switching to HTTPS due ' +
'to mixed-content warnings.',
audits: [
auditRefs: [
{id: 'is-on-https', weight: 1},
{id: 'mixed-content', weight: 1},
],
Expand Down
9 changes: 5 additions & 4 deletions lighthouse-core/report/html/renderer/category-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CategoryRenderer {
gaugeContainerEl.appendChild(gaugeEl);

this.dom.find('.lh-category-header__title', tmpl).appendChild(
this.dom.convertMarkdownCodeSnippets(category.name));
this.dom.convertMarkdownCodeSnippets(category.title));
if (category.description) {
const descEl = this.dom.convertMarkdownLinkSnippets(category.description);
this.dom.find('.lh-category-header__description', tmpl).appendChild(descEl);
Expand Down Expand Up @@ -244,7 +244,7 @@ class CategoryRenderer {
percentageEl.title = 'Errors occurred while auditing';
}

this.dom.find('.lh-gauge__label', tmpl).textContent = category.name;
this.dom.find('.lh-gauge__label', tmpl).textContent = category.title;
return tmpl;
}

Expand All @@ -258,8 +258,9 @@ class CategoryRenderer {
this.createPermalinkSpan(element, category.id);
element.appendChild(this.renderCategoryHeader(category));

const manualAudits = category.audits.filter(item => item.result.scoreDisplayMode === 'manual');
const nonManualAudits = category.audits.filter(audit => !manualAudits.includes(audit));
const auditRefs = category.auditRefs;
const manualAudits = auditRefs.filter(audit => audit.result.scoreDisplayMode === 'manual');
const nonManualAudits = auditRefs.filter(audit => !manualAudits.includes(audit));

const auditsGroupedByGroup = /** @type {!Object<string,
{passed: !Array<!ReportRenderer.AuditJSON>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
element.appendChild(this.renderCategoryHeader(category));

// Metrics
const metricAudits = category.audits.filter(audit => audit.group === 'metrics');
const metricAudits = category.auditRefs.filter(audit => audit.group === 'metrics');
const metricAuditsEl = this.renderAuditGroup(groups['metrics'], {expandable: false});

const keyMetrics = metricAudits.filter(a => a.weight >= 3);
Expand All @@ -141,7 +141,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer {

// Filmstrip
const timelineEl = this.dom.createChildOf(element, 'div', 'lh-filmstrip-container');
const thumbnailAudit = category.audits.find(audit => audit.id === 'screenshot-thumbnails');
const thumbnailAudit = category.auditRefs.find(audit => audit.id === 'screenshot-thumbnails');
const thumbnailResult = thumbnailAudit && thumbnailAudit.result;
if (thumbnailResult && thumbnailResult.details) {
timelineEl.id = thumbnailResult.name;
Expand All @@ -152,7 +152,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
}

// Opportunities
const opportunityAudits = category.audits
const opportunityAudits = category.auditRefs
.filter(audit => audit.group === 'load-opportunities' && !Util.showAsPassed(audit.result))
.sort((auditA, auditB) => this._getWastedMs(auditB) - this._getWastedMs(auditA));

Expand All @@ -172,7 +172,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
}

// Diagnostics
const diagnosticAudits = category.audits
const diagnosticAudits = category.auditRefs
.filter(audit => audit.group === 'diagnostics' && !Util.showAsPassed(audit.result))
.sort((a, b) => {
const scoreA = a.result.scoreDisplayMode === 'informative' ? 100 : Number(a.result.score);
Expand All @@ -189,7 +189,7 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
}

// Passed audits
const passedElements = category.audits
const passedElements = category.auditRefs
.filter(audit => (audit.group === 'load-opportunities' || audit.group === 'diagnostics') &&
Util.showAsPassed(audit.result))
.map((audit, i) => this.renderAudit(audit, i));
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/report/html/renderer/report-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class ReportRenderer {
*/
static smooshAuditResultsIntoCategories(audits, reportCategories) {
for (const category of reportCategories) {
category.audits.forEach(auditMeta => {
category.auditRefs.forEach(auditMeta => {
const result = audits[auditMeta.id];
auditMeta.result = result;
});
Expand Down Expand Up @@ -221,12 +221,12 @@ ReportRenderer.AuditJSON; // eslint-disable-line no-unused-expressions

/**
* @typedef {{
* name: string,
* title: string,
* id: string,
* score: (number|null),
* description: (string|undefined),
* manualDescription: string,
* audits: !Array<!ReportRenderer.AuditJSON>
* auditRefs: !Array<!ReportRenderer.AuditJSON>
* }}
*/
ReportRenderer.CategoryJSON; // eslint-disable-line no-unused-expressions
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/report/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ class ReportGenerator {
// Possible TODO: tightly couple headers and row values
const header = ['category', 'name', 'title', 'type', 'score'];
const table = Object.values(lhr.categories).map(category => {
return category.audits.map(catAudit => {
const audit = lhr.audits[catAudit.id];
return category.auditRefs.map(auditRef => {
const audit = lhr.audits[auditRef.id];
// CSV validator wants all scores to be numeric, use -1 for now
const numericScore = audit.score === null ? -1 : audit.score;
return [category.name, audit.name, audit.description, audit.scoreDisplayMode, numericScore]
return [category.title, audit.name, audit.description, audit.scoreDisplayMode, numericScore]
.map(value => value.toString())
.map(escape);
});
Expand Down
6 changes: 3 additions & 3 deletions lighthouse-core/scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ReportScoring {

for (const [categoryId, configCategory] of Object.entries(configCategories)) {
// Copy category audit members
const audits = configCategory.audits.map(configMember => {
const auditRefs = configCategory.auditRefs.map(configMember => {
const member = {...configMember};

// If a result was not applicable, meaning its checks did not run against anything on
Expand All @@ -71,15 +71,15 @@ class ReportScoring {
return member;
});

const scores = audits.map(auditRef => ({
const scores = auditRefs.map(auditRef => ({
score: resultsByAuditId[auditRef.id].score,
weight: auditRef.weight,
}));
const score = ReportScoring.arithmeticMean(scores);

scoredCategories[categoryId] = {
...configCategory,
audits,
auditRefs,
id: categoryId,
score,
};
Expand Down
Loading

0 comments on commit 83cb1f7

Please sign in to comment.