Skip to content

Commit

Permalink
core(bf-cache): count failures based on affected frames (#14823)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Feb 23, 2023
1 parent 4ef4cfb commit 8ab11e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/audits/bf-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ class BFCache extends Audit {
// TODO: Analyze more than one bf cache failure.
const {notRestoredReasonsTree} = failures[0];

let totalIssues = 0;

/** @type {LH.Audit.Details.TableItem[]} */
const results = [];

for (const failureType of ORDERED_FAILURE_TYPES) {
const reasonsMap = notRestoredReasonsTree[failureType];

for (const [reason, frameUrls] of Object.entries(reasonsMap)) {
totalIssues += frameUrls.length;

results.push({
reason: NotRestoredReasonDescription[reason]?.name ?? reason,
failureType: FAILURE_TYPE_TO_STRING[failureType],
Expand All @@ -104,8 +108,8 @@ class BFCache extends Audit {

const details = Audit.makeTableDetails(headings, results);

const displayValue = results.length ?
str_(UIStrings.displayValue, {itemCount: results.length}) :
const displayValue = totalIssues ?
str_(UIStrings.displayValue, {itemCount: totalIssues}) :
undefined;

return {
Expand Down
2 changes: 1 addition & 1 deletion core/test/audits/bf-cache-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('BFCache audit', () => {

const result = await BFCache.audit(artifacts);

expect(result.displayValue).toBeDisplayString('3 failure reasons');
expect(result.displayValue).toBeDisplayString('4 failure reasons');
expect(result.score).toEqual(0);

if (result.details?.type !== 'table') throw new Error('details were not a table');
Expand Down

0 comments on commit 8ab11e9

Please sign in to comment.