From a68f3b4f1a8d59aeca70fc235d03d1c78c823dc3 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Wed, 10 Apr 2024 11:07:34 -0700 Subject: [PATCH] core(scoring): set is-crawlable weight high enough to fail SEO category (#15933) --- core/config/default-config.js | 7 +++++- core/test/config/default-config-test.js | 11 ++++++++++ .../reports/sample-flow-result.json | 22 +++++++++---------- core/test/results/sample_v2.json | 12 +++++----- .../test/generator/report-generator-test.js | 2 +- 5 files changed, 35 insertions(+), 19 deletions(-) diff --git a/core/config/default-config.js b/core/config/default-config.js index 05bcaf8a9662..085b090ba696 100644 --- a/core/config/default-config.js +++ b/core/config/default-config.js @@ -603,12 +603,17 @@ const defaultConfig = { manualDescription: str_(UIStrings.seoCategoryManualDescription), supportedModes: ['navigation', 'snapshot'], auditRefs: [ + // Should be at least 31% of the score, such that this audit failing + // results in the SEO category failing. + // Solve for w: + // w / (w + T) >= 0.31 + // where T is the sum of all the other weights. + {id: 'is-crawlable', weight: 93 / 23, group: 'seo-crawl'}, {id: 'document-title', weight: 1, group: 'seo-content'}, {id: 'meta-description', weight: 1, group: 'seo-content'}, {id: 'http-status-code', weight: 1, group: 'seo-crawl'}, {id: 'link-text', weight: 1, group: 'seo-content'}, {id: 'crawlable-anchors', weight: 1, group: 'seo-crawl'}, - {id: 'is-crawlable', weight: 1, group: 'seo-crawl'}, {id: 'robots-txt', weight: 1, group: 'seo-crawl'}, {id: 'image-alt', weight: 1, group: 'seo-content'}, {id: 'hreflang', weight: 1, group: 'seo-content'}, diff --git a/core/test/config/default-config-test.js b/core/test/config/default-config-test.js index 77ca4e5df62e..e5cc28140358 100644 --- a/core/test/config/default-config-test.js +++ b/core/test/config/default-config-test.js @@ -7,6 +7,7 @@ import assert from 'assert/strict'; import defaultConfig from '../../config/default-config.js'; +import {ReportScoring} from '../../scoring.js'; describe('Default Config', () => { it('relevantAudits map to existing perf audit', () => { @@ -23,4 +24,14 @@ describe('Default Config', () => { } } }); + + it('SEO fails if is-crawlable is failing', () => { + const scores = defaultConfig.categories.seo.auditRefs.map(auditRef => ({ + score: auditRef.id === 'is-crawlable' ? 0 : 1, + weight: auditRef.weight, + })); + const score = ReportScoring.arithmeticMean(scores); + assert(score < 0.7); + assert(score >= 0.65); + }); }); diff --git a/core/test/fixtures/user-flows/reports/sample-flow-result.json b/core/test/fixtures/user-flows/reports/sample-flow-result.json index b7ee7dfe6fb6..e3d58c210eaa 100644 --- a/core/test/fixtures/user-flows/reports/sample-flow-result.json +++ b/core/test/fixtures/user-flows/reports/sample-flow-result.json @@ -4531,6 +4531,11 @@ "snapshot" ], "auditRefs": [ + { + "id": "is-crawlable", + "weight": 4.043478260869565, + "group": "seo-crawl" + }, { "id": "document-title", "weight": 1, @@ -4556,11 +4561,6 @@ "weight": 1, "group": "seo-crawl" }, - { - "id": "is-crawlable", - "weight": 1, - "group": "seo-crawl" - }, { "id": "robots-txt", "weight": 0, @@ -22110,6 +22110,11 @@ "snapshot" ], "auditRefs": [ + { + "id": "is-crawlable", + "weight": 4.043478260869565, + "group": "seo-crawl" + }, { "id": "document-title", "weight": 1, @@ -22135,11 +22140,6 @@ "weight": 1, "group": "seo-crawl" }, - { - "id": "is-crawlable", - "weight": 1, - "group": "seo-crawl" - }, { "id": "robots-txt", "weight": 0, @@ -22166,7 +22166,7 @@ } ], "id": "seo", - "score": 0.88 + "score": 0.91 }, "pwa": { "title": "PWA", diff --git a/core/test/results/sample_v2.json b/core/test/results/sample_v2.json index be8a9bfb059a..a5f960d95a95 100644 --- a/core/test/results/sample_v2.json +++ b/core/test/results/sample_v2.json @@ -6618,6 +6618,11 @@ "snapshot" ], "auditRefs": [ + { + "id": "is-crawlable", + "weight": 4.043478260869565, + "group": "seo-crawl" + }, { "id": "document-title", "weight": 1, @@ -6643,11 +6648,6 @@ "weight": 1, "group": "seo-crawl" }, - { - "id": "is-crawlable", - "weight": 1, - "group": "seo-crawl" - }, { "id": "robots-txt", "weight": 0, @@ -6674,7 +6674,7 @@ } ], "id": "seo", - "score": 0.63 + "score": 0.73 }, "pwa": { "title": "PWA", diff --git a/report/test/generator/report-generator-test.js b/report/test/generator/report-generator-test.js index 94e60b37a7a4..e0c2d8edbf05 100644 --- a/report/test/generator/report-generator-test.js +++ b/report/test/generator/report-generator-test.js @@ -109,7 +109,7 @@ category,score \\"performance\\",\\"0.28\\" \\"accessibility\\",\\"0.78\\" \\"best-practices\\",\\"0.39\\" -\\"seo\\",\\"0.63\\" +\\"seo\\",\\"0.73\\" \\"pwa\\",\\"0.38\\" category,audit,score,displayValue,description