From eabc17b0a17c05930551c894143e273a9561c221 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Mon, 7 May 2018 17:33:34 -0700 Subject: [PATCH 1/2] core(lhr): s/audits/auditRefs, s/category.name/category.title/ --- lighthouse-core/config/config.js | 26 +++++----- lighthouse-core/config/default-config.js | 22 ++++----- lighthouse-core/config/full-config.js | 2 +- .../config/mixed-content-config.js | 4 +- .../report/html/renderer/category-renderer.js | 9 ++-- .../renderer/performance-category-renderer.js | 10 ++-- .../report/html/renderer/report-renderer.js | 8 ++-- lighthouse-core/report/report-generator.js | 6 +-- lighthouse-core/scoring.js | 6 +-- lighthouse-core/test/config/config-test.js | 48 +++++++++---------- .../html/renderer/category-renderer-test.js | 26 +++++----- .../performance-category-renderer-test.js | 12 ++--- .../html/renderer/report-renderer-test.js | 2 +- lighthouse-core/test/results/sample_v2.json | 20 ++++---- lighthouse-core/test/runner-test.js | 6 +-- lighthouse-core/test/scoring-test.js | 6 +-- .../app/src/lighthouse-background.js | 2 +- lighthouse-extension/app/src/popup.js | 2 +- lighthouse-extension/test/extension-test.js | 2 +- lighthouse-viewer/test/viewer-test-pptr.js | 2 +- typings/config.d.ts | 6 +-- typings/lhr.d.ts | 4 +- 22 files changed, 116 insertions(+), 115 deletions(-) diff --git a/lighthouse-core/config/config.js b/lighthouse-core/config/config.js index 9de9ab95309e..42f05a90999d 100644 --- a/lighthouse-core/config/config.js +++ b/lighthouse-core/config/config.js @@ -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}]`); } @@ -456,7 +456,7 @@ class Config { /** * Filter out any unrequested categories or audits from the categories object. - * @param {!Object}>} categories + * @param {!Object}>} categories * @param {!Array=} categoryIds * @param {!Array=} auditIds * @param {!Array=} skipAuditIds @@ -485,8 +485,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) { @@ -509,7 +509,7 @@ 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 @@ -517,15 +517,15 @@ class Config { 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)); } }); @@ -533,13 +533,13 @@ class Config { } /** - * @param {{categories: !Object}} config - * @return {!Array<{id: string, name: string}>} + * @param {{categories: !Object}} 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}; }); } diff --git a/lighthouse-core/config/default-config.js b/lighthouse-core/config/default-config.js index f3b2605b715b..c388ffe2484a 100644 --- a/lighthouse-core/config/default-config.js +++ b/lighthouse-core/config/default-config.js @@ -15,7 +15,7 @@ module.exports = { passName: 'defaultPass', recordTrace: true, useThrottling: true, - pauseAfterLoadMs: 1000, + pauseAfterLoadMs: 10000, networkQuietThresholdMs: 1000, cpuQuietThresholdMs: 1000, gatherers: [ @@ -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'}, @@ -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}, @@ -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'}, @@ -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}, @@ -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'}, diff --git a/lighthouse-core/config/full-config.js b/lighthouse-core/config/full-config.js index c37f134a6db1..5d430473df70 100644 --- a/lighthouse-core/config/full-config.js +++ b/lighthouse-core/config/full-config.js @@ -21,7 +21,7 @@ module.exports = { ], categories: { 'performance': { - audits: [ + auditRefs: [ {id: 'unused-javascript', weight: 0, group: 'load-opportunities'}, ], }, diff --git a/lighthouse-core/config/mixed-content-config.js b/lighthouse-core/config/mixed-content-config.js index 29ba715239e1..7e21f8faa912 100644 --- a/lighthouse-core/config/mixed-content-config.js +++ b/lighthouse-core/config/mixed-content-config.js @@ -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}, ], diff --git a/lighthouse-core/report/html/renderer/category-renderer.js b/lighthouse-core/report/html/renderer/category-renderer.js index 66427c07a813..0796b7c12460 100644 --- a/lighthouse-core/report/html/renderer/category-renderer.js +++ b/lighthouse-core/report/html/renderer/category-renderer.js @@ -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); @@ -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; } @@ -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, diff --git a/lighthouse-core/report/html/renderer/performance-category-renderer.js b/lighthouse-core/report/html/renderer/performance-category-renderer.js index 478a0128c107..db9ef6e41751 100644 --- a/lighthouse-core/report/html/renderer/performance-category-renderer.js +++ b/lighthouse-core/report/html/renderer/performance-category-renderer.js @@ -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); @@ -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; @@ -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)); @@ -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); @@ -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)); diff --git a/lighthouse-core/report/html/renderer/report-renderer.js b/lighthouse-core/report/html/renderer/report-renderer.js index 7fcc1b46761d..0e3b13dd5982 100644 --- a/lighthouse-core/report/html/renderer/report-renderer.js +++ b/lighthouse-core/report/html/renderer/report-renderer.js @@ -105,7 +105,7 @@ class ReportRenderer { const navItem = this._dom.find('.lh-leftnav__item', itemsTmpl); navItem.href = `#${category.id}`; - this._dom.find('.leftnav-item__category', navItem).textContent = category.name; + this._dom.find('.leftnav-item__category', navItem).textContent = category.title; const score = this._dom.find('.leftnav-item__score', navItem); score.classList.add(`lh-audit--${Util.calculateRating(category.score)}`); score.textContent = Math.round(100 * category.score); @@ -189,7 +189,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; }); @@ -234,12 +234,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 + * auditRefs: !Array * }} */ ReportRenderer.CategoryJSON; // eslint-disable-line no-unused-expressions diff --git a/lighthouse-core/report/report-generator.js b/lighthouse-core/report/report-generator.js index 0eece310b86d..0a00d1aebd12 100644 --- a/lighthouse-core/report/report-generator.js +++ b/lighthouse-core/report/report-generator.js @@ -70,11 +70,11 @@ class ReportGenerator { // Possible TODO: tightly couple headers and row values const header = ['category', 'name', 'title', 'type', 'score']; const table = lhr.reportCategories.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); }); diff --git a/lighthouse-core/scoring.js b/lighthouse-core/scoring.js index 4db62cfe1898..32d61ad57f1b 100644 --- a/lighthouse-core/scoring.js +++ b/lighthouse-core/scoring.js @@ -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 @@ -71,7 +71,7 @@ class ReportScoring { return member; }); - const scores = audits.map(auditRef => ({ + const scores = auditRefs.map(auditRef => ({ score: resultsByAuditId[auditRef.id].score, weight: auditRef.weight, })); @@ -79,7 +79,7 @@ class ReportScoring { scoredCategories.push({ ...configCategory, - audits, + auditRefs, id: categoryId, score, }); diff --git a/lighthouse-core/test/config/config-test.js b/lighthouse-core/test/config/config-test.js index d8f98f781289..e3c29e0a894f 100644 --- a/lighthouse-core/test/config/config-test.js +++ b/lighthouse-core/test/config/config-test.js @@ -217,7 +217,7 @@ describe('Config', () => { audits: [], categories: { pwa: { - audits: [ + auditRefs: [ {id: 'missing-audit'}, ], }, @@ -230,7 +230,7 @@ describe('Config', () => { audits: [], categories: { pwa: { - audits: [ + auditRefs: [ 'oops-wrong-format', ], }, @@ -243,7 +243,7 @@ describe('Config', () => { audits: ['accessibility/color-contrast'], categories: { accessibility: { - audits: [ + auditRefs: [ {id: 'color-contrast'}, ], }, @@ -262,7 +262,7 @@ describe('Config', () => { audits: ['first-meaningful-paint'], categories: { pwa: { - audits: [ + auditRefs: [ {id: 'first-meaningful-paint', group: 'group-a'}, {id: 'first-meaningful-paint', group: 'missing-group'}, ], @@ -276,7 +276,7 @@ describe('Config', () => { audits: ['manual/pwa-cross-browser'], categories: { accessibility: { - audits: [ + auditRefs: [ {id: 'pwa-cross-browser', weight: 10}, ], }, @@ -302,19 +302,19 @@ describe('Config', () => { ], categories: { 'needed-category': { - audits: [ + auditRefs: [ {id: 'first-meaningful-paint'}, {id: 'first-cpu-idle'}, ], }, 'other-category': { - audits: [ + auditRefs: [ {id: 'color-contrast'}, {id: 'estimated-input-latency'}, ], }, 'unused-category': { - audits: [ + auditRefs: [ {id: 'estimated-input-latency'}, ], }, @@ -325,8 +325,8 @@ describe('Config', () => { assert.equal(config.passes.length, 2, 'preserves both passes'); assert.ok(config.passes[0].recordTrace, 'preserves recordTrace pass'); assert.ok(!config.categories['unused-category'], 'removes unused categories'); - assert.equal(config.categories['needed-category'].audits.length, 2); - assert.equal(config.categories['other-category'].audits.length, 1); + assert.equal(config.categories['needed-category'].auditRefs.length, 2); + assert.equal(config.categories['other-category'].auditRefs.length, 1); }); it('filters the config w/ skipAudits', () => { @@ -346,14 +346,14 @@ describe('Config', () => { ], categories: { 'needed-category': { - audits: [ + auditRefs: [ {id: 'first-meaningful-paint'}, {id: 'first-cpu-idle'}, {id: 'color-contrast'}, ], }, 'other-category': { - audits: [ + auditRefs: [ {id: 'color-contrast'}, {id: 'estimated-input-latency'}, ], @@ -364,7 +364,7 @@ describe('Config', () => { assert.equal(config.audits.length, 3, 'skips the FMP audit'); assert.equal(config.passes.length, 2, 'preserves both passes'); assert.ok(config.passes[0].recordTrace, 'preserves recordTrace pass'); - assert.equal(config.categories['needed-category'].audits.length, 2, + assert.equal(config.categories['needed-category'].auditRefs.length, 2, 'removes skipped audit from category'); }); @@ -397,7 +397,7 @@ describe('Config', () => { }); assert.ok(config.audits.length, 'inherited audits by extension'); - assert.equal(config.audits.length, origConfig.categories.performance.audits.length + 1); + assert.equal(config.audits.length, origConfig.categories.performance.auditRefs.length + 1); assert.equal(config.passes.length, 1, 'filtered out passes'); }); @@ -559,13 +559,13 @@ describe('Config', () => { }); it('should merge categories', () => { - const configA = {categories: {A: {name: 'Acat'}, B: {name: 'Bcat'}}}; - const configB = {categories: {C: {name: 'Ccat'}}}; + const configA = {categories: {A: {title: 'Acat'}, B: {title: 'Bcat'}}}; + const configB = {categories: {C: {title: 'Ccat'}}}; const merged = Config.extendConfigJSON(configA, configB); assert.deepStrictEqual(merged.categories, { - A: {name: 'Acat'}, - B: {name: 'Bcat'}, - C: {name: 'Ccat'}, + A: {title: 'Acat'}, + B: {title: 'Bcat'}, + C: {title: 'Ccat'}, }); }); @@ -587,9 +587,9 @@ describe('Config', () => { const categories = Config.getCategories(origConfig); assert.equal(Array.isArray(categories), true); assert.equal(categories.length, 5, 'Found the correct number of categories'); - const haveName = categories.every(cat => cat.name.length); + const haveName = categories.every(cat => cat.title.length); const haveID = categories.every(cat => cat.id.length); - assert.equal(haveName === haveID === true, true, 'they have IDs and names'); + assert.equal(haveName === haveID === true, true, 'they have IDs and titles'); }); }); @@ -626,7 +626,7 @@ describe('Config', () => { it('should only run audits for ones named by the category', () => { const config = Config.generateNewFilteredConfig(origConfig, ['performance']); const selectedCategory = origConfig.categories.performance; - const auditCount = Object.keys(selectedCategory.audits).length; + const auditCount = Object.keys(selectedCategory.auditRefs).length; assert.equal(config.audits.length, auditCount, '# of audits match category list'); }); @@ -641,7 +641,7 @@ describe('Config', () => { const config = Config.generateNewFilteredConfig(origConfig, ['performance'], ['works-offline']); const selectedCategory = origConfig.categories.performance; - const auditCount = Object.keys(selectedCategory.audits).length + 1; + const auditCount = Object.keys(selectedCategory.auditRefs).length + 1; assert.equal(config.passes.length, 2, 'incorrect # of passes'); assert.equal(config.audits.length, auditCount, 'audit filtering failed'); }); @@ -649,7 +649,7 @@ describe('Config', () => { it('should support redundant filtering', () => { const config = Config.generateNewFilteredConfig(origConfig, ['pwa'], ['is-on-https']); const selectedCategory = origConfig.categories.pwa; - const auditCount = Object.keys(selectedCategory.audits).length; + const auditCount = Object.keys(selectedCategory.auditRefs).length; assert.equal(config.passes.length, 3, 'incorrect # of passes'); assert.equal(config.audits.length, auditCount, 'audit filtering failed'); }); diff --git a/lighthouse-core/test/report/html/renderer/category-renderer-test.js b/lighthouse-core/test/report/html/renderer/category-renderer-test.js index 1a94deed3c94..401bf6a071e7 100644 --- a/lighthouse-core/test/report/html/renderer/category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/category-renderer-test.js @@ -47,20 +47,20 @@ describe('CategoryRenderer', () => { }); it('renders an audit', () => { - const audit = sampleResults.reportCategories - .find(c => c.id === 'pwa').audits + const auditRef = sampleResults.reportCategories + .find(c => c.id === 'pwa').auditRefs .find(a => a.id === 'works-offline'); - const auditDOM = renderer.renderAudit(audit); + const auditDOM = renderer.renderAudit(auditRef); assert.equal(auditDOM.nodeType, 1, 'Audit returns an element'); const title = auditDOM.querySelector('.lh-audit__title'); const description = auditDOM.querySelector('.lh-audit__description'); - assert.equal(title.textContent, audit.result.description); + assert.equal(title.textContent, auditRef.result.description); assert.ok(description.querySelector('a'), 'audit help text contains coverted markdown links'); assert.ok(auditDOM.classList.contains('lh-audit--fail')); - assert.ok(auditDOM.classList.contains(`lh-audit--${audit.result.scoreDisplayMode}`)); + assert.ok(auditDOM.classList.contains(`lh-audit--${auditRef.result.scoreDisplayMode}`)); }); it('renders an audit explanation when appropriate', () => { @@ -97,10 +97,10 @@ describe('CategoryRenderer', () => { assert.deepEqual(categoryEl, categoryEl.firstElementChild, 'first child is a score'); const scoreInDom = Number(value.textContent); assert.ok(Number.isInteger(scoreInDom) && scoreInDom > 10, 'category score is rounded'); - assert.equal(title.textContent, category.name, 'title is set'); + assert.equal(title.textContent, category.title, 'title is set'); const audits = categoryDOM.querySelectorAll('.lh-audit'); - assert.equal(audits.length, category.audits.length, 'renders correct number of audits'); + assert.equal(audits.length, category.auditRefs.length, 'renders correct number of audits'); }); it('handles markdown in category descriptions a category', () => { @@ -148,7 +148,7 @@ describe('CategoryRenderer', () => { assert.ok(categoryDOM.querySelector( '.lh-audit-group--not-applicable .lh-audit-group__summary')); - const notApplicableCount = a11yCategory.audits.reduce((sum, audit) => + const notApplicableCount = a11yCategory.auditRefs.reduce((sum, audit) => sum += audit.result.scoreDisplayMode === 'not-applicable' ? 1 : 0, 0); assert.equal( categoryDOM.querySelectorAll('.lh-audit-group--not-applicable .lh-audit').length, @@ -178,14 +178,14 @@ describe('CategoryRenderer', () => { assert.deepEqual(score, score.firstElementChild, 'first child is a score'); const scoreInDom = Number(value.textContent); assert.ok(Number.isInteger(scoreInDom) && scoreInDom > 10, 'score is rounded out of 100'); - assert.equal(title.textContent, category.name, 'title is set'); + assert.equal(title.textContent, category.title, 'title is set'); assert.ok(description.querySelector('a'), 'description contains converted markdown links'); }); // TODO waiting for decision regarding this header it.skip('renders the failed audits grouped by group', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); - const failedAudits = category.audits.filter(audit => { + const failedAudits = category.auditRefs.filter(audit => { return audit.result.score !== 1 && !audit.result.scoreDisplayMode === 'not-applicable'; }); const failedAuditTags = new Set(failedAudits.map(audit => audit.group)); @@ -196,7 +196,7 @@ describe('CategoryRenderer', () => { it('renders the passed audits grouped by group', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); - const passedAudits = category.audits.filter(audit => + const passedAudits = category.auditRefs.filter(audit => audit.result.scoreDisplayMode !== 'not-applicable' && audit.result.score === 1); const passedAuditTags = new Set(passedAudits.map(audit => audit.group)); @@ -207,7 +207,7 @@ describe('CategoryRenderer', () => { it('renders all the audits', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); const auditsElements = categoryDOM.querySelectorAll('.lh-audit'); - assert.equal(auditsElements.length, category.audits.length); + assert.equal(auditsElements.length, category.auditRefs.length); }); }); @@ -227,7 +227,7 @@ describe('CategoryRenderer', () => { it('doesnt create a passed section if there were 0 passed', () => { const origCategory = sampleResults.reportCategories.find(c => c.id === 'pwa'); const category = JSON.parse(JSON.stringify(origCategory)); - category.audits.forEach(audit => audit.result.score = 0); + category.auditRefs.forEach(audit => audit.result.score = 0); const elem = renderer.render(category, sampleResults.reportGroups); const passedAudits = elem.querySelectorAll('.lh-passed-audits > .lh-audit'); const failedAudits = elem.querySelectorAll('.lh-failed-audits > .lh-audit'); diff --git a/lighthouse-core/test/report/html/renderer/performance-category-renderer-test.js b/lighthouse-core/test/report/html/renderer/performance-category-renderer-test.js index 49df1c89f011..b8988f8f1250 100644 --- a/lighthouse-core/test/report/html/renderer/performance-category-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/performance-category-renderer-test.js @@ -61,7 +61,7 @@ describe('PerfCategoryRenderer', () => { assert.deepEqual(score, score.firstElementChild, 'first child is a score'); const scoreInDom = Number(value.textContent); assert.ok(Number.isInteger(scoreInDom) && scoreInDom > 10, 'category score is rounded'); - assert.equal(title.textContent, category.name, 'title is set'); + assert.equal(title.textContent, category.title, 'title is set'); }); it('renders the sections', () => { @@ -74,7 +74,7 @@ describe('PerfCategoryRenderer', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); const metricsSection = categoryDOM.querySelectorAll('.lh-category > .lh-audit-group')[0]; - const metricAudits = category.audits.filter(audit => audit.group === 'metrics'); + const metricAudits = category.auditRefs.filter(audit => audit.group === 'metrics'); const timelineElements = metricsSection.querySelectorAll('.lh-metric'); const nontimelineElements = metricsSection.querySelectorAll('.lh-audit'); assert.equal(timelineElements.length + nontimelineElements.length, metricAudits.length); @@ -83,7 +83,7 @@ describe('PerfCategoryRenderer', () => { it('renders the failing performance opportunities', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); - const oppAudits = category.audits.filter(audit => audit.group === 'load-opportunities' && + const oppAudits = category.auditRefs.filter(audit => audit.group === 'load-opportunities' && audit.result.score !== 1); const oppElements = categoryDOM.querySelectorAll('.lh-load-opportunity'); assert.equal(oppElements.length, oppAudits.length); @@ -108,7 +108,7 @@ describe('PerfCategoryRenderer', () => { }, }; - const fakeCategory = Object.assign({}, category, {audits: [auditWithDebug]}); + const fakeCategory = Object.assign({}, category, {auditRefs: [auditWithDebug]}); const categoryDOM = renderer.render(fakeCategory, sampleResults.reportGroups); const debugEl = categoryDOM.querySelector('.lh-load-opportunity .lh-debug'); @@ -119,7 +119,7 @@ describe('PerfCategoryRenderer', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); const diagnosticSection = categoryDOM.querySelectorAll('.lh-category > .lh-audit-group')[2]; - const diagnosticAudits = category.audits.filter(audit => audit.group === 'diagnostics' && + const diagnosticAudits = category.auditRefs.filter(audit => audit.group === 'diagnostics' && audit.result.score !== 1 && audit.result.scoreDisplayMode !== 'not-applicable'); const diagnosticElements = diagnosticSection.querySelectorAll('.lh-audit'); assert.equal(diagnosticElements.length, diagnosticAudits.length); @@ -129,7 +129,7 @@ describe('PerfCategoryRenderer', () => { const categoryDOM = renderer.render(category, sampleResults.reportGroups); const passedSection = categoryDOM.querySelector('.lh-category > .lh-passed-audits'); - const passedAudits = category.audits.filter(audit => + const passedAudits = category.auditRefs.filter(audit => audit.group && audit.group !== 'metrics' && (audit.result.score === 1 || audit.result.scoreDisplayMode === 'not-applicable')); const passedElements = passedSection.querySelectorAll('.lh-audit'); diff --git a/lighthouse-core/test/report/html/renderer/report-renderer-test.js b/lighthouse-core/test/report/html/renderer/report-renderer-test.js index 607e1d60553c..2183d27f3e4e 100644 --- a/lighthouse-core/test/report/html/renderer/report-renderer-test.js +++ b/lighthouse-core/test/report/html/renderer/report-renderer-test.js @@ -131,7 +131,7 @@ describe('ReportRenderer', () => { const categories = header.querySelectorAll('.leftnav-item__category'); const scores = header.querySelectorAll('.leftnav-item__score'); sampleResults.reportCategories.forEach((cat, i) => { - assert.equal(categories[i].textContent, cat.name); + assert.equal(categories[i].textContent, cat.title); assert.equal(Number(scores[i].textContent), cat.score * 100); }); }); diff --git a/lighthouse-core/test/results/sample_v2.json b/lighthouse-core/test/results/sample_v2.json index f4ef9cbcbafb..855d844ebe8d 100644 --- a/lighthouse-core/test/results/sample_v2.json +++ b/lighthouse-core/test/results/sample_v2.json @@ -4400,8 +4400,8 @@ }, "reportCategories": [ { - "name": "Performance", - "audits": [ + "title": "Performance", + "auditRefs": [ { "id": "first-contentful-paint", "weight": 3, @@ -4559,10 +4559,10 @@ "score": 0.69 }, { - "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 @@ -4624,10 +4624,10 @@ "score": 0.36 }, { - "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": 0, @@ -4848,8 +4848,8 @@ "score": 0.35 }, { - "name": "Best Practices", - "audits": [ + "title": "Best Practices", + "auditRefs": [ { "id": "appcache-manifest", "weight": 1 @@ -4919,10 +4919,10 @@ "score": 0 }, { - "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, diff --git a/lighthouse-core/test/runner-test.js b/lighthouse-core/test/runner-test.js index 9255e7977e4a..0820c11a1145 100644 --- a/lighthouse-core/test/runner-test.js +++ b/lighthouse-core/test/runner-test.js @@ -430,9 +430,9 @@ describe('Runner', () => { ], categories: { category: { - name: 'Category', + title: 'Category', description: '', - audits: [ + auditRefs: [ {id: 'content-width', weight: 1}, ], }, @@ -447,7 +447,7 @@ describe('Runner', () => { assert.equal(results.lhr.audits['content-width'].name, 'content-width'); assert.equal(results.lhr.audits['content-width'].score, 1); assert.equal(results.lhr.reportCategories[0].score, 1); - assert.equal(results.lhr.reportCategories[0].audits[0].id, 'content-width'); + assert.equal(results.lhr.reportCategories[0].auditRefs[0].id, 'content-width'); }); }); diff --git a/lighthouse-core/test/scoring-test.js b/lighthouse-core/test/scoring-test.js index d8bab73007ec..b0bdbd26b77e 100644 --- a/lighthouse-core/test/scoring-test.js +++ b/lighthouse-core/test/scoring-test.js @@ -43,9 +43,9 @@ describe('ReportScoring', () => { }; const categories = { - categoryA: {audits: [{id: 'my-audit'}]}, + categoryA: {auditRefs: [{id: 'my-audit'}]}, categoryB: { - audits: [ + auditRefs: [ {id: 'my-boolean-audit', weight: 1}, {id: 'my-scored-audit', weight: 1}, {id: 'my-failed-audit', weight: 1}, @@ -72,7 +72,7 @@ describe('ReportScoring', () => { const categories = { categoryA: { - audits: [ + auditRefs: [ {id: 'my-boolean-audit', weight: 1}, {id: 'my-scored-audit', weight: 1}, {id: 'my-failed-audit', weight: 1}, diff --git a/lighthouse-extension/app/src/lighthouse-background.js b/lighthouse-extension/app/src/lighthouse-background.js index 3e33a6d288ca..eb100c20d952 100644 --- a/lighthouse-extension/app/src/lighthouse-background.js +++ b/lighthouse-extension/app/src/lighthouse-background.js @@ -57,7 +57,7 @@ window.runLighthouseInWorker = function(port, url, options, categoryIDs) { /** * Returns list of top-level categories from the default config. - * @return {!Array<{name: string, id: string}>} + * @return {!Array<{title: string, id: string}>} */ window.getDefaultCategories = function() { return Config.getCategories(defaultConfig); diff --git a/lighthouse-extension/app/src/popup.js b/lighthouse-extension/app/src/popup.js index 6d5b2d549768..8cbe1c1f8f8a 100644 --- a/lighthouse-extension/app/src/popup.js +++ b/lighthouse-extension/app/src/popup.js @@ -165,7 +165,7 @@ function generateOptionsList(background, selectedCategories) { background.getDefaultCategories().forEach(category => { const isChecked = selectedCategories[category.id]; - frag.appendChild(createOptionItem(category.name, category.id, isChecked)); + frag.appendChild(createOptionItem(category.title, category.id, isChecked)); }); const optionsList = document.querySelector('.options__list'); diff --git a/lighthouse-extension/test/extension-test.js b/lighthouse-extension/test/extension-test.js index 829f2cf3090d..5cd767f9c22c 100644 --- a/lighthouse-extension/test/extension-test.js +++ b/lighthouse-extension/test/extension-test.js @@ -15,7 +15,7 @@ const puppeteer = require('../../node_modules/puppeteer/index.js'); const lighthouseExtensionPath = path.resolve(__dirname, '../dist'); const config = require(path.resolve(__dirname, '../../lighthouse-core/config/default-config.js')); -const getAuditsOfCategory = category => config.categories[category].audits; +const getAuditsOfCategory = category => config.categories[category].auditRefs; describe('Lighthouse chrome extension', function() { // eslint-disable-next-line no-console diff --git a/lighthouse-viewer/test/viewer-test-pptr.js b/lighthouse-viewer/test/viewer-test-pptr.js index c9982c11b14b..034b4c55b9e8 100644 --- a/lighthouse-viewer/test/viewer-test-pptr.js +++ b/lighthouse-viewer/test/viewer-test-pptr.js @@ -18,7 +18,7 @@ const sampleLhr = __dirname + '/../../lighthouse-core/test/results/sample_v2.jso const config = require(path.resolve(__dirname, '../../lighthouse-core/config/default-config.js')); const lighthouseCategories = Object.keys(config.categories); -const getAuditsOfCategory = category => config.categories[category].audits; +const getAuditsOfCategory = category => config.categories[category].auditRefs; // TODO: should be combined in some way with lighthouse-extension/test/extension-test.js describe('Lighthouse Viewer', function() { diff --git a/typings/config.d.ts b/typings/config.d.ts index 7ddb48c8166f..7878350d5682 100644 --- a/typings/config.d.ts +++ b/typings/config.d.ts @@ -60,9 +60,9 @@ declare global { } | string; export interface CategoryJson { - name: string; + title: string; description: string; - audits: CategoryMemberJson[]; + auditRefs: CategoryMemberJson[]; } export interface GroupJson { @@ -103,7 +103,7 @@ declare global { // TODO: For now, these are unchanged from JSON and Result versions. Need to harmonize. export interface CategoryMember extends CategoryMemberJson {} export interface Category extends CategoryJson { - audits: CategoryMember[]; + auditRefs: CategoryMember[]; } export interface Group extends GroupJson {} } diff --git a/typings/lhr.d.ts b/typings/lhr.d.ts index cad5b225b131..bb5d7fede664 100644 --- a/typings/lhr.d.ts +++ b/typings/lhr.d.ts @@ -41,7 +41,7 @@ declare global { /** The string identifier of the category. */ id: string; /** The human-friendly name of the category */ - name: string; + title: string; /** A more detailed description of the category and its importance. */ description?: string; /** A description for the manual audits in the category. */ @@ -49,7 +49,7 @@ declare global { /** The overall score of the category, the weighted average of all its audits. */ score: number|null; /** An array of references to all the audit members of this category. */ - audits: CategoryMember[]; + auditRefs: CategoryMember[]; } export interface CategoryMember { From fc3bf572de7329365849eac89fcebc9dc0cb9ec3 Mon Sep 17 00:00:00 2001 From: Patrick Hulce Date: Wed, 9 May 2018 07:18:15 -0700 Subject: [PATCH 2/2] member -> auditRef --- typings/config.d.ts | 8 ++++---- typings/lhr.d.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/typings/config.d.ts b/typings/config.d.ts index 7878350d5682..2b7a3331f44f 100644 --- a/typings/config.d.ts +++ b/typings/config.d.ts @@ -62,7 +62,7 @@ declare global { export interface CategoryJson { title: string; description: string; - auditRefs: CategoryMemberJson[]; + auditRefs: AuditRefJson[]; } export interface GroupJson { @@ -74,7 +74,7 @@ declare global { * Reference to an audit member of a category and how its score should be * weighted and how its results grouped with other members. */ - export interface CategoryMemberJson { + export interface AuditRefJson { id: string; weight: number; group?: string; @@ -101,9 +101,9 @@ declare global { } // TODO: For now, these are unchanged from JSON and Result versions. Need to harmonize. - export interface CategoryMember extends CategoryMemberJson {} + export interface AuditRef extends AuditRefJson {} export interface Category extends CategoryJson { - auditRefs: CategoryMember[]; + auditRefs: AuditRef[]; } export interface Group extends GroupJson {} } diff --git a/typings/lhr.d.ts b/typings/lhr.d.ts index bb5d7fede664..4146ac4ca5a1 100644 --- a/typings/lhr.d.ts +++ b/typings/lhr.d.ts @@ -49,10 +49,10 @@ declare global { /** The overall score of the category, the weighted average of all its audits. */ score: number|null; /** An array of references to all the audit members of this category. */ - auditRefs: CategoryMember[]; + auditRefs: AuditRef[]; } - export interface CategoryMember { + export interface AuditRef { /** Matches the `id` of an Audit.Result. */ id: string; /** The weight of the audit's score in the overall category score. */