Skip to content

Commit

Permalink
core: score of 1 for informative audits (#15689)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed Jan 18, 2024
1 parent e85c2ac commit d69c3ea
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 106 deletions.
12 changes: 6 additions & 6 deletions cli/test/smokehouse/test-definitions/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ const expectations = {
},
},
'duplicate-id-aria': {
score: null,
score: 1,
details: {
items: [
{
Expand Down Expand Up @@ -515,7 +515,7 @@ const expectations = {
},
},
'empty-heading': {
score: null,
score: 1,
details: {
items: [
{
Expand All @@ -531,7 +531,7 @@ const expectations = {
},
},
'form-field-multiple-labels': {
score: null,
score: 1,
scoreDisplayMode: 'informative',
details: {
items: [
Expand Down Expand Up @@ -625,7 +625,7 @@ const expectations = {
scoreDisplayMode: 'notApplicable',
},
'identical-links-same-purpose': {
score: null,
score: 1,
details: {
items: [
{
Expand Down Expand Up @@ -739,7 +739,7 @@ const expectations = {
},
},
'landmark-one-main': {
score: null,
score: 1,
details: {
items: [
{
Expand Down Expand Up @@ -931,7 +931,7 @@ const expectations = {
},
},
'target-size': {
score: null,
score: 1,
details: {
items: [
{
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/test-definitions/dobetterweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ const expectations = {
},
},
'dom-size': {
score: null,
score: 1,
numericValue: 154,
details: {
items: [
Expand Down
4 changes: 2 additions & 2 deletions cli/test/smokehouse/test-definitions/perf-budgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const expectations = {
finalDisplayedUrl: 'http://localhost:10200/perf/perf-budgets/load-things.html',
audits: {
'resource-summary': {
score: null,
score: 1,
details: {
items: [
{resourceType: 'total', requestCount: 10, transferSize: '166472±1000'},
Expand All @@ -83,7 +83,7 @@ const expectations = {
},
},
'performance-budget': {
score: null,
score: 1,
details: {
// Undefined items are asserting that the property isn't included in the table item.
items: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const expectations = {
finalDisplayedUrl: 'http://localhost:10200/perf/animations.html',
audits: {
'non-composited-animations': {
score: null,
score: 1,
displayValue: '1 animated element found',
details: {
items: [
Expand Down
2 changes: 1 addition & 1 deletion cli/test/smokehouse/test-definitions/perf-frame-metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const expectations = {
finalDisplayedUrl: 'http://localhost:10200/perf/frame-metrics.html',
audits: {
'metrics': {
score: null,
score: 1,
details: {
type: 'debugdata',
items: [
Expand Down
4 changes: 2 additions & 2 deletions cli/test/smokehouse/test-definitions/perf-trace-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const expectations = {
},
},
'layout-shift-elements': {
score: null,
score: 1,
displayValue: '2 elements found',
details: {
items: [
Expand Down Expand Up @@ -228,7 +228,7 @@ const expectations = {
},
},
'long-tasks': {
score: null,
score: 1,
details: {
items: {
0: {
Expand Down
4 changes: 4 additions & 0 deletions core/audits/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ class Audit {
* @return {number|null}
*/
static _normalizeAuditScore(score, scoreDisplayMode, auditId) {
if (scoreDisplayMode === Audit.SCORING_MODES.INFORMATIVE) {
return 1;
}

if (scoreDisplayMode !== Audit.SCORING_MODES.BINARY &&
scoreDisplayMode !== Audit.SCORING_MODES.NUMERIC &&
scoreDisplayMode !== Audit.SCORING_MODES.METRIC_SAVINGS) {
Expand Down
4 changes: 4 additions & 0 deletions core/lib/lighthouse-compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function upgradeLhrForCompatibility(lhr) {
audit.scoreDisplayMode = 'notApplicable';
}

if (audit.scoreDisplayMode === 'informative') {
audit.score = 1;
}

if (audit.details) {
// Turn `auditDetails.type` of undefined (LHR <4.2) and 'diagnostic' (LHR <5.0)
// into 'debugdata' (LHR ≥5.0).
Expand Down
6 changes: 3 additions & 3 deletions core/test/audits/audit-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ describe('Audit', () => {
assert.strictEqual(auditResult.score, 1);
});

it('override scoreDisplayMode if set on audit product', () => {
it('switches to INFORMATIVE and set score to 1 if set on audit product', () => {
assert.strictEqual(NumericAudit.meta.scoreDisplayMode, Audit.SCORING_MODES.NUMERIC);
const auditResult = Audit.generateAuditResult(NumericAudit, {
score: 1,
score: null,
scoreDisplayMode: Audit.SCORING_MODES.INFORMATIVE,
});
assert.strictEqual(auditResult.scoreDisplayMode, Audit.SCORING_MODES.INFORMATIVE);
assert.strictEqual(auditResult.score, null);
assert.strictEqual(auditResult.score, 1);
});

it('switches to an ERROR and is not scored if an errorMessage is passed in', () => {
Expand Down
Loading

0 comments on commit d69c3ea

Please sign in to comment.