-
-
Couldn't load subscription status.
- Fork 4.2k
create and (trying to) fix async loading of Routes #19456
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
Open
sly7-7
wants to merge
2
commits into
emberjs:failing-test-case-for-engines
Choose a base branch
from
sly7-7:failing-test-case-for-engines
base: failing-test-case-for-engines
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,11 +2,15 @@ | |
| import { Route } from '@ember/-internals/routing'; | ||
| import Controller from '@ember/controller'; | ||
| import { Object as EmberObject, A as emberA } from '@ember/-internals/runtime'; | ||
| import { moduleFor, ApplicationTestCase, getTextOf } from 'internal-test-helpers'; | ||
| import { | ||
| moduleFor, | ||
| ApplicationTestCase, | ||
| getTextOf, | ||
| runLoopSettled, | ||
| lazyLoadingRouterOptions, | ||
| } from 'internal-test-helpers'; | ||
| import { run } from '@ember/runloop'; | ||
| import { computed, set } from '@ember/-internals/metal'; | ||
| import { isDestroying } from '@glimmer/destroyable'; | ||
| import RSVP from 'rsvp'; | ||
|
|
||
| let originalConsoleError; | ||
|
|
||
|
|
@@ -502,8 +506,6 @@ class LoadingTests extends ApplicationTestCase { | |
| }) | ||
| ); | ||
|
|
||
| this.add('route:loading', Route.extend({})); | ||
| this.add('route:home', Route.extend({})); | ||
| this.add( | ||
| 'route:special', | ||
| Route.extend({ | ||
|
|
@@ -518,7 +520,6 @@ class LoadingTests extends ApplicationTestCase { | |
|
|
||
| this.addTemplate('root.index', '<h3>Home</h3>'); | ||
| this.addTemplate('special', '<p>{{@model.id}}</p>'); | ||
| this.addTemplate('loading', '<p>LOADING!</p>'); | ||
|
|
||
| return this.visit('/').then(() => { | ||
| rootElement = document.getElementById('qunit-fixture'); | ||
|
|
@@ -755,7 +756,7 @@ class LoadingTests extends ApplicationTestCase { | |
| }); | ||
| } | ||
|
|
||
| ['@test Parent route context change'](assert) { | ||
| async ['@test Parent route context change'](assert) { | ||
| let editCount = 0; | ||
| let editedPostIds = emberA(); | ||
|
|
||
|
|
@@ -777,8 +778,8 @@ class LoadingTests extends ApplicationTestCase { | |
| 'route:posts', | ||
| Route.extend({ | ||
| actions: { | ||
| showPost(context) { | ||
| expectDeprecation(() => { | ||
| async showPost(context) { | ||
| await expectDeprecationAsync(() => { | ||
| this.transitionTo('post', context); | ||
| }, /Calling transitionTo on a route is deprecated/); | ||
| }, | ||
|
|
@@ -798,8 +799,8 @@ class LoadingTests extends ApplicationTestCase { | |
| }, | ||
|
|
||
| actions: { | ||
| editPost() { | ||
| expectDeprecation(() => { | ||
| async editPost() { | ||
| await expectDeprecationAsync(() => { | ||
| this.transitionTo('post.edit'); | ||
| }, /Calling transitionTo on a route is deprecated/); | ||
| }, | ||
|
|
@@ -815,22 +816,26 @@ class LoadingTests extends ApplicationTestCase { | |
| editedPostIds.push(postId); | ||
| return null; | ||
| }, | ||
|
|
||
| setup() { | ||
| this._super(...arguments); | ||
| editCount++; | ||
| }, | ||
| }) | ||
| ); | ||
|
|
||
| return this.visit('/posts/1').then(() => { | ||
| assert.ok(true, '/posts/1 has been handled'); | ||
| let router = this.applicationInstance.lookup('router:main'); | ||
| run(() => router.send('editPost')); | ||
| run(() => router.send('showPost', { id: '2' })); | ||
| run(() => router.send('editPost')); | ||
| assert.equal(editCount, 2, 'set up the edit route twice without failure'); | ||
| assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context'); | ||
| }); | ||
| await this.visit('/posts/1'); | ||
| assert.ok(true, '/posts/1 has been handled'); | ||
| let router = this.applicationInstance.lookup('router:main'); | ||
| run(() => router.send('editPost')); | ||
| await runLoopSettled(); | ||
| await runLoopSettled(); | ||
| run(() => router.send('showPost', { id: '2' })); | ||
| await runLoopSettled(); | ||
| run(() => router.send('editPost')); | ||
| await runLoopSettled(); | ||
| assert.equal(editCount, 2, 'set up the edit route twice without failure'); | ||
| assert.deepEqual(editedPostIds, ['1', '2'], 'modelFor posts.post returns the right context'); | ||
| } | ||
|
|
||
| ['@test ApplicationRoute with model does not proxy the currentPath'](assert) { | ||
|
|
@@ -941,6 +946,14 @@ class LoadingTests extends ApplicationTestCase { | |
| assert.equal(childcount, 2); | ||
| }); | ||
| } | ||
|
|
||
| ['@test What about loading states'](assert) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a reminder to me, to remove this test |
||
| assert.expect(1); | ||
| this.add('route:loading', Route.extend({})); | ||
| return this.visit('/').then(() => { | ||
sly7-7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| assert.ok(true); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| moduleFor('Route - model loading', LoadingTests); | ||
|
|
@@ -949,43 +962,7 @@ moduleFor( | |
| 'Route - model loading (simulated within lazy engine)', | ||
| class extends LoadingTests { | ||
| get routerOptions() { | ||
| return { | ||
| location: 'none', | ||
| setupRouter() { | ||
| this._super(...arguments); | ||
| let getRoute = this._routerMicrolib.getRoute; | ||
| this._enginePromises = Object.create(null); | ||
| this._resolvedEngines = Object.create(null); | ||
|
|
||
| let routes = new Map(); | ||
| let routePromises = new Map(); | ||
| this._routerMicrolib.getRoute = (name) => { | ||
| if (routes.has(name)) { | ||
| return routes.get(name); | ||
| } | ||
|
|
||
| if (routePromises.has(name)) { | ||
| return routePromises.get(name); | ||
| } | ||
|
|
||
| let promise = new RSVP.Promise((resolve) => { | ||
| setTimeout(() => { | ||
| if (isDestroying(this)) { | ||
| return; | ||
| } | ||
|
|
||
| let route = getRoute(name); | ||
|
|
||
| routes.set(name, route); | ||
| resolve(route); | ||
| }, 10); | ||
| }); | ||
| routePromises.set(name, promise); | ||
|
|
||
| return promise; | ||
| }; | ||
| }, | ||
| }; | ||
| return lazyLoadingRouterOptions; | ||
| } | ||
| } | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rwjblue I have doubt about that artificial synchronisation