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

Wait for pending route transitions as part of settledness check #482

Merged
merged 13 commits into from Jan 26, 2019

Conversation

AlexTraher
Copy link
Contributor

This aims to resolve an issue where settled() isn't waiting for router transitions. See here: #411.

This is a combined effort from myself and @dexturr.

@rwjblue
Copy link
Member

rwjblue commented Nov 26, 2018

Oh, no! I had started to work on fixing this bug over the holiday weekend (US Thanksgiving). You can see my WIP over in master...rwjblue:settled-router-transitions if you are curious.

Shall we compare notes?

Copy link
Member

@rwjblue rwjblue left a comment

Choose a reason for hiding this comment

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

Thank you again for picking this up! I've left some inline notes about specific areas for changes, but I'd still like to coordinate on the best way to drive this forward.

I'm happy to port my more "realistic" tests (in place of the mocking tests added here) then look into porting the other features (noop unless visit is called, using only public API's for "Active transition" when possible, etc) over into this PR if you'd like...

Then we can all three tag team issues that crop up, what do you think?

addon-test-support/@ember/test-helpers/settled.ts Outdated Show resolved Hide resolved
addon-test-support/@ember/test-helpers/settled.ts Outdated Show resolved Hide resolved
addon-test-support/@ember/test-helpers/settled.ts Outdated Show resolved Hide resolved
tests/unit/settled-test.js Outdated Show resolved Hide resolved
tests/unit/settled-test.js Outdated Show resolved Hide resolved
tests/unit/setup-application-context-test.js Outdated Show resolved Hide resolved
@AlexTraher
Copy link
Contributor Author

@rwjblue Yeah sounds like a plan - happy to be driven by what you think is best (I am most certainly not an expert!) @dexturr and I can start looking to address your comments 💯.

@rwjblue
Copy link
Member

rwjblue commented Nov 26, 2018

OK, cool, I'll get some of my branches changes landed into this PR in the next hour or so...

Dexter Edwards and others added 8 commits January 26, 2019 13:55
These tests are designed to mimick real world application scenarios, and
confirm that the transitions triggered within each are properly waited
for before a `settled()` promise resolves.
The code added in an earlier commit was working around the underlying
issue. Essentially, using `getContext` in `hasPendingTransition` meant
that we were always using whatever the "last" context was and since
every test does not (and **should not**) call `setContext` we were
accidentally sharing an older tests context.

This change ensures we `setContext` up before these
`setupApplicationContext` tests (which is important), but we _also_
should add more changes to the testing harness in @ember/test-helpers
overall to ensure that each test internally cleans up the context (look
out for future PR's/commits for that)...
@rwjblue
Copy link
Member

rwjblue commented Jan 26, 2019

Rebased with master to fixup conflicts.

This allows `setupTest(hooks)` tests that use `this.owner.setupRouter()`
to also take advantage of the settledness tracking.
The way we are hooking into the application instance registry ultimately means
that we leak "factories". Once the first test resolves a factory for a
given name, **all other tests** will use that factory (even if
`setResolverRegistry` were called again with a different value!1!1!1!1).

This works around the immediate issue by always using the "current"
assert object instead of the closure scoped one because all of the tests
will use the same factory, and using `assert` from the first test will
cause many issues for subsequent tests.

In the long run, we need to fix this in a different way. Most likely
that means changing the way setResolverRegistry works to do something
like:

* hooking into the shared application instance
* calling unregister and reregister for each key in the pojo provided

Alternatively, we could recreate the registry instance itself (therefore
flushing any caches). I think either would work, but am not certain how
hard to implement...
@rwjblue rwjblue changed the title Bugfix/wait for transitions Wait for pending route transitions as part of settledness check Jan 26, 2019
@rwjblue rwjblue added the bug label Jan 26, 2019
@rwjblue rwjblue merged commit d4ef594 into emberjs:master Jan 26, 2019
@rwjblue
Copy link
Member

rwjblue commented Jan 26, 2019

Thank you again @dexturr and @AlexTraher! Your work (and debugging) was very very helpful in getting this over the line...

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.

None yet

3 participants