Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 3, 2018
1 parent 472898a commit 3a81c69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ let PerformanceCategoryRenderer = null;
const CriticalRequestChainRenderer = require(
'../../../../report/html/renderer/crc-details-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 TIMESTAMP_REGEX = /\d+, \d{4}.*\d+:\d+/;
const TEMPLATE_FILE = fs.readFileSync(__dirname +
'/../../../../report/html/templates.html', 'utf8');

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

beforeAll(() => {
global.URL = URL;
Expand Down Expand Up @@ -57,7 +58,7 @@ describe('ReportRenderer', () => {
const detailsRenderer = new DetailsRenderer(dom);
const categoryRenderer = new CategoryRenderer(dom, detailsRenderer);
renderer = new ReportRenderer(dom, categoryRenderer);
sampleResults.reportCategories = Object.values(sampleResults.categories);
sampleResults = Util.prepareReportResult(sampleResultsOrig);
});

afterAll(() => {
Expand Down
18 changes: 7 additions & 11 deletions lighthouse-core/test/report/html/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
const assert = require('assert');
const Util = require('../../../../report/html/renderer/util.js');

const ReportRenderer = require('../../../../report/html/renderer/report-renderer.js');
const sampleResults = require('../../../results/sample_v2.json');

const NBSP = '\xa0';
Expand Down Expand Up @@ -169,29 +168,26 @@ describe('util helpers', () => {
});

describe('getFinalScreenshot', () => {
const cloneResults = Util.prepareReportResult(sampleResults);

it('gets a datauri as a string', () => {
const cloneResults = Util.prepareReportResult(sampleResults);
const datauri = Util.getFinalScreenshot(cloneResults);
assert.equal(typeof datauri, 'string');
assert.ok(datauri.startsWith('data:image/jpeg;base64,'));
});

it('returns null if there is no perf category', () => {
const lhrWithoutPerf = JSON.parse(JSON.stringify(sampleResults));
delete lhrWithoutPerf.categories.performance;
lhrWithoutPerf.reportCategories = Object.values(lhrWithoutPerf.categories);
const clonedResults = JSON.parse(JSON.stringify(sampleResults));
delete clonedResults.categories.performance;
const lhrWithoutPerf = Util.prepareReportResult(clonedResults);

const datauri = Util.getFinalScreenshot(lhrWithoutPerf);
assert.equal(datauri, null);
});

it('returns null if there is no final-screenshot audit', () => {
const lhrNoFinalSS = JSON.parse(JSON.stringify(sampleResults));
delete lhrNoFinalSS.audits['final-screenshot'];
lhrNoFinalSS.reportCategories = Object.values(lhrNoFinalSS.categories);
ReportRenderer.smooshAuditResultsIntoCategories(lhrNoFinalSS.audits,
lhrNoFinalSS.reportCategories);
const clonedResults = JSON.parse(JSON.stringify(sampleResults));
delete clonedResults.audits['final-screenshot'];
const lhrNoFinalSS = Util.prepareReportResult(clonedResults);

const datauri = Util.getFinalScreenshot(lhrNoFinalSS);
assert.equal(datauri, null);
Expand Down

0 comments on commit 3a81c69

Please sign in to comment.