Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 3, 2018
1 parent ff070b4 commit 472898a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 34 deletions.
24 changes: 4 additions & 20 deletions lighthouse-core/report/html/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,16 @@ class Util {
// TODO(phulce): we all agree this is technical debt we should fix
if (typeof clone.categories !== 'object') throw new Error('No categories provided.');
clone.reportCategories = Object.values(clone.categories);
Util.smooshAuditResultsIntoCategories(clone.audits, clone.reportCategories);
return clone;
}

/**
* Place the AuditResult into the auditDfn (which has just weight & group)
* @param {Object<string, LH.Audit.Result>} audits
* @param {Array<LH.ReportResult.Category>} reportCategories
*/
static smooshAuditResultsIntoCategories(audits, reportCategories) {
for (const category of reportCategories) {
// For convenience, smoosh all AuditResults into their auditDfn (which has just weight & group)
for (const category of clone.reportCategories) {
category.auditRefs.forEach(auditMeta => {
const result = audits[auditMeta.id];
const result = clone.audits[auditMeta.id];
auditMeta.result = result;
});
}
}

/**
* @param {LH.I18NRendererStrings} rendererFormattedStrings
*/
static updateAllUIStrings(rendererFormattedStrings) {
// TODO(i18n): don't mutate these here but on the LHR and pass that around everywhere
for (const [key, value] of Object.entries(rendererFormattedStrings)) {
Util.UIStrings[key] = value;
}
return clone;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const DetailsRenderer = require('../../../../report/html/renderer/details-render
const CriticalRequestChainRenderer = require(
'../../../../report/html/renderer/crc-details-renderer.js');
const CategoryRenderer = require('../../../../report/html/renderer/category-renderer.js');
const ReportRenderer = require('../../../../report/html/renderer/report-renderer.js');
const sampleResults = require('../../../results/sample_v2.json');
const sampleResultsOrig = require('../../../results/sample_v2.json');

const TEMPLATE_FILE = fs.readFileSync(__dirname +
'/../../../../report/html/templates.html', 'utf8');

describe('CategoryRenderer', () => {
let renderer;
let sampleResults;

beforeAll(() => {
global.URL = URL;
Expand All @@ -36,9 +36,7 @@ describe('CategoryRenderer', () => {
const detailsRenderer = new DetailsRenderer(dom);
renderer = new CategoryRenderer(dom, detailsRenderer);

sampleResults.reportCategories = Object.values(sampleResults.categories);
ReportRenderer.smooshAuditResultsIntoCategories(sampleResults.audits,
sampleResults.reportCategories);
sampleResults = Util.prepareReportResult(sampleResultsOrig);
});

afterAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ const DetailsRenderer = require('../../../../report/html/renderer/details-render
const CriticalRequestChainRenderer = require(
'../../../../report/html/renderer/crc-details-renderer.js');
const CategoryRenderer = require('../../../../report/html/renderer/category-renderer.js');
const ReportRenderer = require('../../../../report/html/renderer/report-renderer.js');
const sampleResults = require('../../../results/sample_v2.json');
const sampleResultsOrig = require('../../../results/sample_v2.json');

const TEMPLATE_FILE = fs.readFileSync(__dirname +
'/../../../../report/html/templates.html', 'utf8');

describe('PerfCategoryRenderer', () => {
let category;
let renderer;
let sampleResults;

beforeAll(() => {
global.URL = URL;
Expand All @@ -40,10 +40,9 @@ describe('PerfCategoryRenderer', () => {
const dom = new DOM(document);
const detailsRenderer = new DetailsRenderer(dom);
renderer = new PerformanceCategoryRenderer(dom, detailsRenderer);
sampleResults.reportCategories = Object.values(sampleResults.categories);

sampleResults = Util.prepareReportResult(sampleResultsOrig);
category = sampleResults.reportCategories.find(cat => cat.id === 'performance');
ReportRenderer.smooshAuditResultsIntoCategories(sampleResults.audits,
sampleResults.reportCategories);
});

afterAll(() => {
Expand Down
5 changes: 1 addition & 4 deletions lighthouse-core/test/report/html/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ describe('util helpers', () => {
});

describe('getFinalScreenshot', () => {
const cloneResults = JSON.parse(JSON.stringify(sampleResults));
cloneResults.reportCategories = Object.values(cloneResults.categories);
ReportRenderer.smooshAuditResultsIntoCategories(cloneResults.audits,
cloneResults.reportCategories);
const cloneResults = Util.prepareReportResult(sampleResults);

it('gets a datauri as a string', () => {
const datauri = Util.getFinalScreenshot(cloneResults);
Expand Down

0 comments on commit 472898a

Please sign in to comment.