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

Migrate evaluateAsync to Runtime.evaluate(awaitPromise) #793

Merged
merged 1 commit into from
Oct 20, 2016

Conversation

pavelfeldman
Copy link
Contributor

@pavelfeldman pavelfeldman commented Oct 19, 2016

edit by paulirish: fixes #580

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

We were waiting until m54 hit stable to do this (#580), but as of this week, 54 is the new stable. \o/

There's a few issues that travis picked up in the PR:
https://travis-ci.org/GoogleChrome/lighthouse/jobs/168801013#L290

Aside from those, this is looking on point. Excited to simplify this stuff.

@pavelfeldman
Copy link
Contributor Author

Made the tests happy

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

just a few things, half of which are fixing up what the code should have already been doing :)

// If this gets to 60s and it hasn't been resolved, reject the Promise.
asyncTimeout = setTimeout(
let asyncTimeout = setTimeout(
Copy link
Member

Choose a reason for hiding this comment

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

const

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

});
axe.a11yCheck(document, fulfill);
return result;
Copy link
Member

Choose a reason for hiding this comment

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

rather than expose the resolve function external to the promise, you could instead do

function runA11yChecks() {
  return new Promise((resolve, reject) => {
    axe.a11yCheck(document, resolve);
  });
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. We are using single line callback -> Promise conversion in devtools, but with your linting it does not fit a line, so your version works better in your source base.

});
}).catch(_ => {
__returnResults(undefined);
// Empty catch
Copy link
Member

Choose a reason for hiding this comment

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

while you're changing this, maybe we should just drop the catch handler here? It isn't providing additional feedback and a rejected promise from evaluateAsync is caught in afterPass anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -146,48 +146,20 @@ class Driver {

evaluateAsync(asyncExpression) {
Copy link
Member

Choose a reason for hiding this comment

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

While you're in here, would you mind adding a doc string? Maybe something like

/**
 * Evaluate an expression in the context of the current page. Expression must
 * evaluate to a Promise. Returns a promise that resolves on asyncExpression's
 * resolved value.
 * @param {string} asyncExpression
 * @return {!Promise<*>}
 */

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@brendankenny
Copy link
Member

when does m54 go 100%? End of the week?

@addyosmani
Copy link
Member

M54 is rolling out today so should be a few days. I've heard it occasionally takes up to a week to fully ramp up to 100% but given this is master and we're not tagging a release anytime soon, it seems okay to land.

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM. We can wait for @paulirish's +1 before merging

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

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

So good.

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.

consider replacing driver.evaluateAsync with new async debugger evaluate
4 participants