Skip to content

Commit

Permalink
update for dom report
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce committed Mar 25, 2017
1 parent a69b508 commit 775d7b2
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 41 deletions.
2 changes: 1 addition & 1 deletion lighthouse-cli/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function saveResults(results: Results,
}, Promise.resolve(results));
} else {
let outputPath = flags.outputPath || `${resolvedPath}.report.${flags.output}`;
outputPath = outputPath.replace(/\.htmlv2$/, '.html');
outputPath = outputPath.replace(/\.domhtml$/, '.html');
return Printer.write(results, flags.output, outputPath).then(results => {
if (flags.output === Printer.OutputMode[Printer.OutputMode.html]) {
if (flags.view) {
Expand Down
8 changes: 4 additions & 4 deletions lighthouse-cli/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* 'json': JSON formatted results
* 'html': An HTML report
*/
enum OutputMode { json, html, htmlv2 };
type Mode = 'json' | 'html' | 'htmlv2';
enum OutputMode { json, html, domhtml };
type Mode = 'json' | 'html' | 'domhtml';

import {Results} from './types/types';

Expand Down Expand Up @@ -56,7 +56,7 @@ function createOutput(results: Results, outputMode: OutputMode): string {
return reportGenerator.generateHTML(results, 'cli');
}

if (outputMode === OutputMode.htmlv2) {
if (outputMode === OutputMode.domhtml) {
return new ReportGeneratorV2().generateReportHtml(results);
}

Expand Down Expand Up @@ -123,7 +123,7 @@ function write(results: Results, mode: Mode, path: string): Promise<Results> {
function GetValidOutputOptions():Array<Mode> {
return [OutputMode[OutputMode.json] as Mode,
OutputMode[OutputMode.html] as Mode,
OutputMode[OutputMode.htmlv2] as Mode];
OutputMode[OutputMode.domhtml] as Mode];
}

export {
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@
"categories": {
"pwa": {
"name": "Progressive Web App",
"weight": 1,
"description": "These audits validate the aspects of a Progressive Web App. They are a subset of the [PWA Checklist](https://developers.google.com/web/progressive-web-apps/checklist).",
"audits": [
{"id": "service-worker", "weight": 1},
Expand Down
35 changes: 2 additions & 33 deletions lighthouse-core/report/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,45 +148,14 @@ class ReportGenerator {
});
}

/**
* Returns aggregations directly from results or maps Config v2 categories to equivalent Config
* v1 aggregations.
* @param {{aggregations: !Array<!Object>, reportCategories: !Array<!Object>}} results
* @param {boolean=} forceV2
* @return {!Array<!Aggregation>}
*/
_getAggregations(results, forceV2 = false) {
if (results.aggregations.length && !forceV2) {
return results.aggregations;
}

return results.reportCategories.map(category => {
const name = category.name;
const description = category.description;

return {
name, description,
categorizable: false,
scored: category.id === 'pwa',
total: category.score / 100,
score: [{
name, description,
overall: category.score / 100,
subItems: category.audits.map(child => child.result),
}],
};
});
}

/**
* Generates the Lighthouse report HTML.
* @param {!Object} results Lighthouse results.
* @param {!string} reportContext What app is requesting the report (eg. devtools, extension)
* @param {?Object} reportsCatalog Basic info about all the reports to include in left nav bar
* @param {boolean=} forceV2
* @return {string} HTML of the report page.
*/
generateHTML(results, reportContext = 'extension', reportsCatalog, forceV2) {
generateHTML(results, reportContext = 'extension', reportsCatalog) {
this._registerPartials(results.audits);

results.aggregations.forEach(aggregation => {
Expand All @@ -207,7 +176,7 @@ class ReportGenerator {
stylesheets: this.getReportCSS(),
reportContext: reportContext,
scripts: this.getReportJS(reportContext),
aggregations: this._getAggregations(results, forceV2),
aggregations: results.aggregations,
auditsByCategory: this._createPWAAuditsByCategory(results.aggregations),
runtimeConfig: results.runtimeConfig,
reportsCatalog
Expand Down
3 changes: 2 additions & 1 deletion lighthouse-core/report/v2/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class ReportGeneratorV2 {
return Object.assign({}, category, {audits, score});
});

return {categories};
const score = ReportGeneratorV2.arithmeticMean(categories);
return {score, categories};
}

/**
Expand Down
19 changes: 19 additions & 0 deletions lighthouse-core/report/v2/report-renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* Copyright 2017 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
'use strict';

/* eslint-env browser */

class ReportRenderer {
/**
* @param {!Object} report
Expand Down
7 changes: 5 additions & 2 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,13 @@ class Runner {
a => Aggregate.aggregate(a, runResults.auditResults));
}

// compute config v2 categories if available
let reportCategories = [];
let score = 0;
if (config.categories) {
const reportGenerator = new ReportGeneratorV2();
reportCategories = reportGenerator.generateReportJson(config, resultsById).categories;
const report = reportGenerator.generateReportJson(config, resultsById);
reportCategories = report.categories;
score = report.score;
}

return {
Expand All @@ -150,6 +152,7 @@ class Runner {
audits: resultsById,
artifacts: runResults.artifacts,
runtimeConfig: Runner.getRuntimeConfig(opts.flags),
score,
reportCategories,
aggregations
};
Expand Down
12 changes: 12 additions & 0 deletions lighthouse-core/test/report/v2/report-generator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ describe('ReportGeneratorV2', () => {
});

describe('#generateReportJson', () => {
it('should return a score', () => {
const result = new ReportGeneratorV2().generateReportJson({
categories: {
'categoryA': {weight: 1, audits: [{id: 'auditA', weight: 1}]},
'categoryB': {weight: 4, audits: [{id: 'auditB', weight: 1}]},
'categoryC': {audits: []},
}
}, {auditA: {score: 50}, auditB: {score: 100}});

assert.equal(result.score, 90);
});

it('should return categories', () => {
const result = new ReportGeneratorV2().generateReportJson({
categories: {
Expand Down

0 comments on commit 775d7b2

Please sign in to comment.