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

Add waitFor function to enable waiting for async functions #131

Merged
merged 5 commits into from
Aug 3, 2020

Conversation

bendemboski
Copy link
Contributor

Extracted from #81

A couple of notes:

  • I have not address Wait for coroutine #81 (comment) because I'm still a typescript noob and a jsdoc noob (so noob squared here)
  • I had to do some interesting acrobatics to keep the waitForPromise tests reasonably DRY -- I'm definitely open to other ideas if anyone has any

@scalvert scalvert force-pushed the wait-for-promise-multiform branch from 674a7f2 to deacb7a Compare August 3, 2020 19:33
@scalvert
Copy link
Collaborator

scalvert commented Aug 3, 2020

@bendemboski - @rwjblue and I revived this one. Thanks so much for taking it as far as you did!

We've made a few changes, namely kept the waitForPromise API as it was, and added the waitFor API to provide the async function/decorator support. I think this will be a really nice addition to the addon.

Let me know if you have any thoughts/suggestions.

@scalvert scalvert requested a review from rwjblue August 3, 2020 20:40
@bendemboski
Copy link
Contributor Author

LGTM. I think the two additional items in the original PR that are probably mostly ready (I'll have to revive them from my repo's branches) are:

  1. babel transform to strip waitForPromise() and waitFor() from the build
  2. waitForCoroutine()

Any changes on those fronts, or continue with the original plans?

@scalvert
Copy link
Collaborator

scalvert commented Aug 3, 2020

I think the idea is that we layer on generator support into waitFor. Let me sync with @rwjblue after this is merged and we'll articulate the changes in an issue. I'll make sure to @ you on it.

As for the stripping, is that so we can reduce the size of the bundle?

@bendemboski
Copy link
Contributor Author

I think the idea is that we layer on generator support into waitFor. Let me sync with @rwjblue after this is merged and we'll articulate the changes in an issue. I'll make sure to @ you on it.

Oh, gotcha, that makes sense from an API standpoint. And I think I can maybe picture how to implement it? We'd need to make the wrapper function look at the return value, and if it looks like an iterator, then wrap it in our own iterator instrumented with test waiter calls, instead of wrapping it in waitForPromise(), and return that...I think that would work?

As for the stripping, is that so we can reduce the size of the bundle?

Yeah, this was originally something requested by @rwjblue and my cut at it was here.

@scalvert
Copy link
Collaborator

scalvert commented Aug 3, 2020

@bendemboski yes that's exactly what we were thinking WRT the generator - essentially inspecting the shape of the return value to determine if it's an iterator, and wrapping it as you said.

As for stripping, I think we can wait on that. I think the idea we had was to still ship these things in the prod bundle, as we ultimately want to be able to run tests against a prod bundle, but still have it wait for async. If we strip, we can't do that.

This is predicated on us moving away from using the DEBUG flag, but something intermediate to evaluate whether we're in test mode or not.

@rwjblue
Copy link
Member

rwjblue commented Aug 3, 2020

As for stripping, I think we can wait on that. I think the idea we had was to still ship these things in the prod bundle, as we ultimately want to be able to run tests against a prod bundle, but still have it wait for async.

Ya, this just means we need another flag (DEBUG is not good enough here, because we need ember test --environment=production to be able to work.

@bendemboski
Copy link
Contributor Author

Gotcha. Okay, once this is finalized/merged I'll make some time to port the waitForCoroutine() implementation into waitFor().

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
addon/ember-test-waiters/types/index.ts Show resolved Hide resolved
addon/ember-test-waiters/types/index.ts Show resolved Hide resolved
addon/ember-test-waiters/wait-for.ts Show resolved Hide resolved
addon/ember-test-waiters/wait-for.ts Outdated Show resolved Hide resolved
addon/ember-test-waiters/wait-for.ts Outdated Show resolved Hide resolved
Comment on lines +81 to +85
if (isThenable(result)) {
return waitForPromise(result, label);
} else {
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.

Note: @bendemboski I think we would add the check for iterator here just like the isThenable thing (iterator being something with a typeof result.next === 'function' I believe)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ya maybe add an isIterable?

@scalvert scalvert merged commit f3afa63 into emberjs:master Aug 3, 2020
@scalvert scalvert changed the title Extend waitForPromise to work in function form Add waitFor function to enable waiting for async functions Aug 4, 2020
@scalvert scalvert added the enhancement New feature or request label Aug 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants