Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core(redirects): update to modern opportunity details type #5791

Merged
merged 3 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lighthouse-core/audits/redirects.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ class Redirects extends Audit {
});
}

/** @type {LH.Result.Audit.OpportunityDetails['headings']} */
const headings = [
{key: 'url', itemType: 'text', text: str_(i18n.UIStrings.columnURL)},
{key: 'wastedMs', itemType: 'ms', text: str_(i18n.UIStrings.columnTimeSpent)},
{key: 'url', valueType: 'url', label: str_(i18n.UIStrings.columnURL)},
{key: 'wastedMs', valueType: 'timespanMs', label: str_(i18n.UIStrings.columnTimeSpent)},
];
const summary = {wastedMs: totalWastedMs};
const details = Audit.makeTableDetails(headings, pageRedirects, summary);
const details = Audit.makeOpportunityDetails(headings, pageRedirects, totalWastedMs);

return {
// We award a passing grade if you only have 1 redirect
Expand Down
4 changes: 2 additions & 2 deletions lighthouse-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ const Config = require('./config/config');
*/

/**
* @param {string} url
* @param {string=} url
* @param {LH.Flags=} flags
* @param {LH.Config.Json|undefined} configJSON
* @param {LH.Config.Json=} configJSON
Copy link
Member

@brendankenny brendankenny Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these (and below in runner) were some drive by fixes I noticed since the test is calling index.js directly, and the URL is now optional (in auditMode) after #5495

* @return {Promise<LH.RunnerResult|undefined>}
*/
async function lighthouse(url, flags, configJSON) {
Expand Down
3 changes: 1 addition & 2 deletions lighthouse-core/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ class Runner {
}

// Entering: conclusion of the lighthouse result object
// @ts-ignore - Needs json require() support
const lighthouseVersion = /** @type {string} */ (require('../package.json').version);
const lighthouseVersion = require('../package.json').version;

/** @type {Object<string, LH.Audit.Result>} */
const resultsById = {};
Expand Down
39 changes: 39 additions & 0 deletions lighthouse-core/test/config/default-config-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @license Copyright 2018 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';

const assert = require('assert');
const lighthouse = require('../../index.js');
const defaultConfig = require('../../config/default-config.js');

/* eslint-env jest */

describe.only('Default Config', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only

it('only has opportunity audits that return opportunities details', async () => {
const flags = {
auditMode: __dirname + '/../results/artifacts/',
};
const {lhr} = await lighthouse('', flags);

const opportunityResults = lhr.categories.performance.auditRefs
.filter(ref => ref.group === 'load-opportunities')
.map(ref => lhr.audits[ref.id]);

// Check all expected opportunities were found.
assert.strictEqual(opportunityResults.indexOf(undefined), -1);
const defaultCount = defaultConfig.categories.performance.auditRefs
.filter(ref => ref.group === 'load-opportunities').length;
assert.strictEqual(opportunityResults.length, defaultCount);

// And that they have the correct shape.
opportunityResults.forEach(auditResult => {
assert.strictEqual(auditResult.details.type, 'opportunity');
assert.ok(!auditResult.errorMessage, `${auditResult.id}: ${auditResult.errorMessage}`);
assert.ok(auditResult.details.overallSavingsMs !== undefined,
`${auditResult.id} has an undefined overallSavingsMs`);
});
});
});
6 changes: 2 additions & 4 deletions lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,10 @@
"rawValue": 0,
"displayValue": "",
"details": {
"type": "table",
"type": "opportunity",
"headings": [],
"items": [],
"summary": {
"wastedMs": 0
}
"overallSavingsMs": 0
}
},
"webapp-install-banner": {
Expand Down