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

remove explicit required generateAuditResult() call #1857

Merged
merged 1 commit into from
Mar 13, 2017
Merged

Conversation

brendankenny
Copy link
Member

basically forever we've required audits to call AuditName.generateAuditResult() on the result they're returning.

static audit(artifacts) {
  return MyGreatAudit.generateAuditResult({
    rawValue: false,
  });
}

This just moves the call to the caller of the audit (Runner._runAudit) instead, making writing an audit require just a little less boilerplate :)

static audit(artifacts) {
  return {
    rawValue: false,
  };
}

@brendankenny brendankenny changed the title remove explicit generateAuditResult call remove explicit required generateAuditResult() call Mar 13, 2017
Copy link
Contributor

@ebidel ebidel left a comment

Choose a reason for hiding this comment

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

This is awesome! Thanks for the cleanup.

error?: boolean;
description: string;
name: string;
category: string;
helpText?: string;
requiredArtifacts?: Array<string>;
Copy link
Contributor

Choose a reason for hiding this comment

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

wait, no longer needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is for the AuditResult, not Audit. I'm not sure why requiredArtifacts was on this in the first place

* @param {!AuditResultInput} result
* @return {!AuditResult}
* @param {!Audit} audit
* @param {!AuditResut} result
Copy link
Member

Choose a reason for hiding this comment

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

AuditResut

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch :)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -74,7 +74,6 @@ describe('Performance: speed-index-metric audit', () => {
const artifacts = mockArtifactsWithSpeedlineResult(SpeedlineResult);

return Audit.audit(artifacts).then(response => {
assert.equal(response.displayValue, '845');
Copy link
Member

Choose a reason for hiding this comment

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

i saw when you were debugging this..

looks like you nuked it because .displayValue is never explictly set?

Copy link
Member

Choose a reason for hiding this comment

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

If that's true, what is this bit doing?

let displayValue = result.displayValue;
if (typeof displayValue === 'undefined') {
displayValue = result.rawValue ? result.rawValue : '';
}

Copy link
Member Author

Choose a reason for hiding this comment

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

looks like you nuked it because .displayValue is never explictly set?

yes. That line in audit.js does the same thing as it did before (so the final result output by Lighthouse will have a displayValue of '845'), but since the unit test is calling .audit() directly, it's not getting the version run through generateAuditResult and so won't have displayValue on it

Copy link
Member

Choose a reason for hiding this comment

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

roger that.

@brendankenny brendankenny merged commit 174766f into master Mar 13, 2017
@brendankenny brendankenny deleted the nogenerate branch March 13, 2017 06:29
@brendankenny
Copy link
Member Author

I believe technically all current PRs will still work (no danger in calling Audit.generateAuditResult() on the results of itself), but you can remove Audit.generateAuditResult() from your audit if you feel like it :)

#1840, #1847, #1804, #1695, and #937 looks like they can be updated if desired

@addyosmani
Copy link
Member

Thanks for the ping on the page execution breakdowns PR. This change looks pretty sane. LGTM3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants