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

Ensure @ember/test-helpers promise based helpers never create a run loop for resolving the promise. #958

Merged
merged 13 commits into from
Dec 4, 2020

Conversation

rwjblue
Copy link
Member

@rwjblue rwjblue commented Dec 4, 2020

This removes the custom RSVP.configure('async', fn) that we have used for a while (introduced in 0da35f4) in favor of using native Promise whenever possible and falling back to a separately loaded (via ember-auto-import) es6-promise polyfill when native Promise is not available.

This does increase the overall size of assets/test-support.js by ~ 27kb (see the es6-promise README), but since that doesn't really affect any production application situations it should be fine. Once we drop support for browsers that do not have a native Promise we can remove ember-auto-import and our es6-promise polyfill.

In order to test that this implementation functions properly in IE11, I had to get the testing infrastructure back into a state where IE11 can run tests. That required a number of changes:

Closes #956
Fixes #947

@rwjblue rwjblue requested a review from scalvert December 4, 2020 17:09
@rwjblue rwjblue added the bug label Dec 4, 2020
@rwjblue rwjblue force-pushed the avoid-rsvp-promises-internally branch from 09968d6 to 04495b7 Compare December 4, 2020 17:13
@scalvert
Copy link
Contributor

scalvert commented Dec 4, 2020

cc/ @drewlee

@rwjblue rwjblue changed the title runHooks results in isSettled() being false when resolved Ensure @ember/test-helpers promise based helpers never create a run loop for resolving the promise. Dec 4, 2020
@rwjblue rwjblue force-pushed the avoid-rsvp-promises-internally branch from 04495b7 to 46439cf Compare December 4, 2020 17:20
Copy link
Contributor

@scalvert scalvert left a comment

Choose a reason for hiding this comment

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

This looks 👍 and is largely what was discussed. Thanks!

This commit introduces a number of (currently failing) tests that are
attempting to confirm that after running various public methods that
we are in a settled state.

The tests all fail at the moment, because the `Promise.all` that is done
wihtin `runHooks` does **not** go through our custom
`RSVP.configure('async', fn)`. This is because the `async` hook in RSVP
only receives a second argument (the `promise` argument) in some
circumstances but not in the case where the parent promise is not in the
pending state ([this branch in
RSVP](https://github.com/tildeio/rsvp.js/blob/429ade2379dfbfb6e2c6f453b4aeb642515dbb74/lib/rsvp/then.js#L28-L33)).
`RSVP.Promise.all([undefined, undefined])` is considered settled
immediately, so `RSVP.Promise.all().then(fn)` returns a promise that
will **not** get our custom promise resolution scheduling.

Since our custom scheduling is not being used here, the normal `RSVP`
integration is used which means that the promise will resolve in the
`actions` queue of the run loop. Ultimately, this is why `isSettled()`
returns false when `await runHooks(...)` completes: a run loop was
started in order to resolve the `runHooks` promise, but it has not
completed yet.
We no longer support Ember < 3.8, so this can be safely removed.
* Removes `RSVP.configure('async', fn)` override
* Updates internals to use native promises where available
* Leaves IE11 support broken (will be fixed in a follow up commit)
* Exports `Promise` from `-utils` (instead of `_Promise`)
Ember should be ensuring an instance on its own here (the act of
setting outletState should ensureInstance, since we know we need to
render), but it is not.

This really needs to be fixed in Ember (and then we can guard this
`ensureInstance` call for newer Ember versions).
This ensures that we support environments without a native `Promise` but
still avoid using the manually configured `Ember.RSVP` runloop
integration.
This ensures that when folks do something like this:

```js
if (typeof Promise === 'undefined') {
  self.Promise = Ember.RSVP.Promise;
}
```

We still use a Promise that is **not** configured on the run loop.
Fixes issues with IE11 compat.
@rwjblue rwjblue force-pushed the avoid-rsvp-promises-internally branch 2 times, most recently from 936e6c9 to 53b1c61 Compare December 4, 2020 21:01
This is normally handled for folks by ember-qunit, but
@ember/test-helpers has to handle it for itself.

We need to get this fixed over in ember-cli...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helpers no longer work properly with scheduled run-loop queues in v2
3 participants