diff --git a/lighthouse-core/report/v2/renderer/report-renderer.js b/lighthouse-core/report/v2/renderer/report-renderer.js index 1c9dc39c0cd0..56889559137c 100644 --- a/lighthouse-core/report/v2/renderer/report-renderer.js +++ b/lighthouse-core/report/v2/renderer/report-renderer.js @@ -274,7 +274,12 @@ class ReportRenderer { } if (typeof module !== 'undefined' && module.exports) { - module.exports = ReportRenderer; + module.exports = { + formatDateTime, + formatNumber, + calculateRating, + ReportRenderer + }; } /** @typedef {{id: string, weight: number, score: number, result: {description: string, displayValue: string, helpText: string, score: number|boolean, details: DetailsRenderer.DetailsJSON|undefined}}} */ diff --git a/lighthouse-core/test/report/v2/renderer/dom-test.js b/lighthouse-core/test/report/v2/renderer/dom-test.js index b1c711a20139..7f0a17357805 100644 --- a/lighthouse-core/test/report/v2/renderer/dom-test.js +++ b/lighthouse-core/test/report/v2/renderer/dom-test.js @@ -62,6 +62,12 @@ describe('DOM', () => { assert.ok(clone.querySelector('.lh-score')); }); + it('should clone a template from a context scope', () => { + const heading = dom.cloneTemplate('#tmpl-lh-heading'); + const items = dom.cloneTemplate('#tmpl-lh-env__items', heading); + assert.ok(items.querySelector('.lh-env__item')); + }); + it('fails when template cannot be found', () => { assert.throws(() => dom.cloneTemplate('#unknown-selector')); }); diff --git a/lighthouse-core/test/report/v2/renderer/report-renderer-test.js b/lighthouse-core/test/report/v2/renderer/report-renderer-test.js index 5e76a9c399fc..b70843125432 100644 --- a/lighthouse-core/test/report/v2/renderer/report-renderer-test.js +++ b/lighthouse-core/test/report/v2/renderer/report-renderer-test.js @@ -15,7 +15,7 @@ */ 'use strict'; -/* eslint-env mocha, browser */ +/* eslint-env mocha */ const assert = require('assert'); const fs = require('fs'); @@ -44,7 +44,7 @@ describe('ReportRenderer V2', () => { }; }; const document = jsdom.jsdom(TEMPLATE_FILE); - renderer = new ReportRenderer(document); + renderer = new ReportRenderer.ReportRenderer(document); }); after(() => { @@ -56,6 +56,29 @@ describe('ReportRenderer V2', () => { global.matchMedia = undefined; }); + describe('format helpers', () => { + it('formats a date', () => { + const timestamp = ReportRenderer.formatDateTime(sampleResults.generatedTime); + assert.equal(timestamp, 'Apr 5, 2017, 3:41 PM PDT'); + }); + + it('formats a number', () => { + assert.strictEqual(ReportRenderer.formatNumber(10), '10'); + assert.strictEqual(ReportRenderer.formatNumber(100.01), '100'); + assert.strictEqual(ReportRenderer.formatNumber(13000.456), '13,000.5'); + }); + + it('calculates a score ratings', () => { + assert.equal(ReportRenderer.calculateRating(0), 'fail'); + assert.equal(ReportRenderer.calculateRating(10), 'fail'); + assert.equal(ReportRenderer.calculateRating(45), 'average'); + assert.equal(ReportRenderer.calculateRating(55), 'average'); + assert.equal(ReportRenderer.calculateRating(75), 'pass'); + assert.equal(ReportRenderer.calculateRating(80), 'pass'); + assert.equal(ReportRenderer.calculateRating(100), 'pass'); + }); + }); + describe('renderReport', () => { it('should render a report', () => { const container = renderer._dom._document.body;