Skip to content

Commit

Permalink
feat(lighthouse-reporter): Better reports (#76)
Browse files Browse the repository at this point in the history
* feat(lighthouse-reporter): Better reports

Report errors and warnings from the target website

Closes #62, #56

* test(core): Fix formatting and tests
  • Loading branch information
andreasonny83 authored Oct 2, 2020
1 parent f14979c commit f613659
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __tests__/reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const writeReport = require('../lib/lighthouse-reporter');
describe('Reporter', () => {
it('should launch Chrome and generate a report', async () => {
jest.setTimeout(20000); // Allows more time to run all tests
const result = await writeReport('http://www.google.com');
const result = await writeReport('http://example.com/');
expect(result).toEqual(
expect.objectContaining({
categoryReport: {
Expand Down
17 changes: 17 additions & 0 deletions lib/lighthouse-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const util = require('util');
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const ReportGenerator = require('lighthouse/lighthouse-core/report/report-generator');
const chalk = require('chalk');
const { createDefaultConfig, getOwnProps, convertToBudgetList, convertToResourceKey } = require('./helpers');

const readFile = util.promisify(fs.readFile);
Expand Down Expand Up @@ -78,6 +79,22 @@ const launchChromeAndRunLighthouse = async (url, chromeFlags, lighthouseFlags, c
const result = await lighthouse(url, flags, config);
await chrome.kill();

if (!result || !result.lhr) {
throw new Error('Something went wrong when running Lighthouse against the given url');
}

if (result.lhr.runtimeError) {
throw new Error(result.lhr.runtimeError.message);
}

if (result.lhr.runWarnings.length >= 1) {
for (const warningMessage of result.lhr.runWarnings) {
console.warn(`\n${chalk.yellow('WARNING:')} ${warningMessage}`);
}

console.warn('\n');
}

return result;
};

Expand Down

0 comments on commit f613659

Please sign in to comment.