Skip to content

Commit

Permalink
All audits must specify helpText and failureDescription (#2737)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Aug 2, 2017
1 parent ac99084 commit db3f324
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions docs/recipes/custom-audit/searchable-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class LoadAudit extends Audit {
category: 'MyCustomCategory',
name: 'searchable-audit',
description: 'Search box initialized and ready',
failureDescription: 'Search box slow to initialize',
helpText: 'Used to measure time from navigationStart to when the search' +
' box is initialized and ready to search.',

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PasswordInputsCanBePastedIntoAudit extends Audit {
name: 'password-inputs-can-be-pasted-into',
description: 'Allows users to paste into password fields',
failureDescription: 'Prevents users to paste into password fields',
helpText: '',
helpText: 'Preventing password pasting undermines good security policy. ' +
'[Learn more](https://www.ncsc.gov.uk/blog-post/let-them-paste-passwords)',
requiredArtifacts: ['PasswordInputsWithPreventedPaste']
};
}
Expand Down
6 changes: 5 additions & 1 deletion lighthouse-core/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,17 @@ function assertValidAudit(auditDefinition, auditPath) {
if (typeof auditDefinition.meta.failureDescription !== 'string' &&
auditDefinition.meta.informative !== true &&
auditDefinition.meta.scoringMode !== Audit.SCORING_MODES.NUMERIC) {
log.warn('config', `${auditName} has no failureDescription and should.`);
throw new Error(`${auditName} has no failureDescription and should.`);
}

if (typeof auditDefinition.meta.helpText !== 'string') {
throw new Error(
`${auditName} has no meta.helpText property, or the property is not a string.`
);
} else if (auditDefinition.meta.helpText === '') {
throw new Error(
`${auditName} has an empty meta.helpText string. Please add a description for the UI.`
);
}

if (!Array.isArray(auditDefinition.meta.requiredArtifacts)) {
Expand Down
4 changes: 3 additions & 1 deletion lighthouse-core/test/config/config-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ describe('Config', () => {
name: 'MyAudit',
category: 'mine',
description: 'My audit',
helpText: '',
failureDescription: 'My failing audit',
helpText: '.',
requiredArtifacts: []
};
}
Expand Down Expand Up @@ -443,6 +444,7 @@ describe('Config', () => {
name: 'custom-audit',
category: 'none',
description: 'none',
failureDescription: 'none',
helpText: 'none',
requiredArtifacts: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class MissingRequiredArtifacts extends LighthouseAudit {
name: 'missing-category',
category: 'Custom',
description: 'Missing required artifacts',
helpText: '',
helpText: 'This is missing required artifacts',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MissingRequiredArtifacts extends LighthouseAudit {
return {
name: 'missing-category',
description: 'Missing required artifacts',
helpText: '',
helpText: 'This is missing a required category',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MissingRequiredArtifacts extends LighthouseAudit {
return {
name: 'missing-description',
category: 'Custom',
helpText: '',
helpText: 'This is missing required description (and failure description)',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class MissingRequiredArtifacts {
category: 'Custom',
name: 'missing-required-artifacts',
description: 'Missing required artifacts',
helpText: '',
helpText: 'This is missing required artifacts',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MissingRequiredArtifacts extends LighthouseAudit {
name: 'missing-description',
category: 'Custom',
description: 'Missing required artifacts',
failureDescription: 'Missing required artifacts is failing',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MissingRequiredArtifacts extends LighthouseAudit {
return {
category: 'Custom',
description: 'Missing name',
helpText: '',
helpText: 'This is missing required name',
requiredArtifacts: ['HTML']
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class MissingRequiredArtifacts extends LighthouseAudit {
category: 'Custom',
name: 'missing-required-artifacts',
description: 'Missing required artifacts',
helpText: '',
failureDescription: 'Missing required artifacts is failing',
helpText: 'This is missing required artifacts',
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RequireErrorAudit extends LighthouseAudit {
name: 'require-error',
category: 'Custom',
description: 'Require Error',
helpText: '',
helpText: 'This one has a bad require()',
requiredArtifacts: ['HTML']
};
}
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/test/fixtures/valid-custom-audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ValidCustomAudit extends LighthouseAudit {
name: 'valid-audit',
category: 'Custom',
description: 'Valid Audit',
failureDescription: 'Valid failing Audit',
helpText: 'Valid-sounding helpText',
requiredArtifacts: ['HTML']
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ describe('CategoryRenderer', () => {
it('renders an audit debug str when appropriate', () => {
const audit1 = renderer._renderAudit({
scoringMode: 'binary', score: 0,
result: {helpText: '', debugString: 'Debug string', description: 'Audit title'},
result: {helpText: 'help text', debugString: 'Debug string', description: 'Audit title'},
});
assert.ok(audit1.querySelector('.lh-debug'));

const audit2 = renderer._renderAudit({
scoringMode: 'binary', score: 0, result: {helpText: '', description: 'Audit title'},
scoringMode: 'binary', score: 0, result: {helpText: 'help text', description: 'Audit title'},
});
assert.ok(!audit2.querySelector('.lh-debug'));
});

it('renders an informative audit', () => {
const auditDOM = renderer._renderAudit({
id: 'informative', score: 0,
result: {description: 'It informs', helpText: '', informative: true},
result: {description: 'It informs', helpText: 'help text', informative: true},
});

assert.ok(auditDOM.querySelector('.lh-score--informative'));
Expand Down
1 change: 1 addition & 0 deletions lighthouse-core/test/runner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ describe('Runner', () => {
category: 'ThrowThrow',
name: 'throwy-audit',
description: 'Always throws',
failureDescription: 'Always throws is failing, natch',
helpText: 'Test for always throwing',
requiredArtifacts: []
};
Expand Down

0 comments on commit db3f324

Please sign in to comment.