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

report: hidden group backcompat #13310

Merged
merged 12 commits into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ A Lighthouse plugin is just a node module with a name that starts with `lighthou
"name": "lighthouse-plugin-cats",
"main": "plugin.js",
"peerDependencies": {
"lighthouse": "^8.6.0"
"lighthouse": "^8.7.0"
},
"devDependencies": {
"lighthouse": "^8.6.0"
"lighthouse": "^8.7.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/recipes/custom-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"private": true,
"scripts": {},
"devDependencies": {
"lighthouse": "^8.6.0"
"lighthouse": "^8.7.0"
}
}
2 changes: 1 addition & 1 deletion docs/recipes/gulp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"devDependencies": {
"gulp": "^3.9.1",
"gulp-connect": "^5.0.0",
"lighthouse": "^8.6.0"
"lighthouse": "^8.7.0"
}
}
2 changes: 1 addition & 1 deletion docs/recipes/lighthouse-plugin-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"main": "./plugin.js",
"peerDependencies": {
"lighthouse": "^8.6.0"
"lighthouse": "^8.7.0"
},
"devDependencies": {
"lighthouse": "^8.6.0"
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/test/results/sample_v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"axe-core": "4.2.3"
}
},
"lighthouseVersion": "8.6.0",
"lighthouseVersion": "8.7.0",
"fetchTime": "2021-09-07T20:11:11.853Z",
"requestedUrl": "http://localhost:10200/dobetterweb/dbw_tester.html",
"finalUrl": "http://localhost:10200/dobetterweb/dbw_tester.html",
Expand Down
16 changes: 16 additions & 0 deletions lighthouse-core/util-commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ class Util {
/** @type {Map<string, Array<LH.ReportResult.AuditRef>>} */
const relevantAuditToMetricsMap = new Map();

// Old LHR versions (<=8.6.0) do not have the "hidden" group.
// This backcompat converts the LHR to use the new "hidden" group.
const [major, minor] = clone.lighthouseVersion.split('.').map(Number);
adamraine marked this conversation as resolved.
Show resolved Hide resolved
const perfCategory = clone.categories['performance'];
if (major <= 8 && minor <= 6 && perfCategory) {
if (!clone.categoryGroups) clone.categoryGroups = {};
clone.categoryGroups['hidden'] = {title: ''};
for (const auditRef of perfCategory.auditRefs) {
if (!auditRef.group) {
auditRef.group = 'hidden';
} else if (['load-opportunities', 'diagnostics'].includes(auditRef.group)) {
delete auditRef.group;
}
}
}

for (const category of Object.values(clone.categories)) {
// Make basic lookup table for relevantAudits
category.auditRefs.forEach(metricRef => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lighthouse",
"version": "8.6.0",
"version": "8.7.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

pretty weird, wish I had an alternative idea. At least, how about 9.0.0-alpha.0?

Copy link
Member

Choose a reason for hiding this comment

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

this is fine. i considered it but got scared. but sure.

"description": "Automated auditing, performance metrics, and best practices for the web.",
"main": "./lighthouse-core/index.js",
"bin": {
Expand Down
16 changes: 16 additions & 0 deletions report/renderer/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ class Util {
/** @type {Map<string, Array<LH.ReportResult.AuditRef>>} */
const relevantAuditToMetricsMap = new Map();

// Old LHR versions (<=8.6.0) do not have the "hidden" group.
// This backcompat converts the LHR to use the new "hidden" group.
const [major, minor] = clone.lighthouseVersion.split('.').map(Number);
connorjclark marked this conversation as resolved.
Show resolved Hide resolved
const perfCategory = clone.categories['performance'];
if (major <= 8 && minor <= 6 && perfCategory) {
if (!clone.categoryGroups) clone.categoryGroups = {};
clone.categoryGroups['hidden'] = {title: ''};
for (const auditRef of perfCategory.auditRefs) {
if (!auditRef.group) {
auditRef.group = 'hidden';
} else if (['load-opportunities', 'diagnostics'].includes(auditRef.group)) {
delete auditRef.group;
}
}
}

for (const category of Object.values(clone.categories)) {
// Make basic lookup table for relevantAudits
category.auditRefs.forEach(metricRef => {
Expand Down
22 changes: 22 additions & 0 deletions report/test/renderer/util-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ describe('util helpers', () => {
const preparedResult = Util.prepareReportResult(clonedSampleResult);
assert.deepStrictEqual(preparedResult.audits, sampleResult.audits);
});

it('corrects performance category without hidden group', () => {
const clonedSampleResult = JSON.parse(JSON.stringify(sampleResult));

clonedSampleResult.lighthouseVersion = '8.6.0';
delete clonedSampleResult.categoryGroups['hidden'];
for (const auditRef of clonedSampleResult.categories['performance'].auditRefs) {
if (auditRef.group === 'hidden') {
delete auditRef.group;
} else if (!auditRef.group) {
auditRef.group = 'diagnostics';
}
}
assert.notDeepStrictEqual(clonedSampleResult.categories, sampleResult.categories);
assert.notDeepStrictEqual(clonedSampleResult.categoryGroups, sampleResult.categoryGroups);

// Original audit results should be restored.
const clonedPreparedResult = Util.prepareReportResult(clonedSampleResult);
const preparedResult = Util.prepareReportResult(sampleResult);
assert.deepStrictEqual(clonedPreparedResult.categories, preparedResult.categories);
assert.deepStrictEqual(clonedPreparedResult.categoryGroups, preparedResult.categoryGroups);
});
});

it('appends stack pack descriptions to auditRefs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Generate report: enabled visible

=============== Lighthouse Results ===============
URL: http://127.0.0.1:8000/devtools/lighthouse/resources/lighthouse-emulate-pass.html
Version: 8.6.0
Version: 8.7.0
formFactor: mobile
screenEmulation: {
"mobile": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ Generating results...

=============== Lighthouse Results ===============
URL: http://127.0.0.1:8000/devtools/lighthouse/resources/lighthouse-basic.html
Version: 8.6.0
Version: 8.7.0
ViewportDimensions: {
"innerWidth": 980,
"innerHeight": 1743,
Expand Down