-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure lazy engines with async routes are handled
Lazy engine routes are initially promises which resolve to route instances once the modules are loaded. In these cases prefetch current throws an error 'TypeError: route.prefetch is not a function' since it tries to call prefetch directly on the promise. It seems this used to be handled properly but was lost in a more recent refactor. This is just adding the functionality back. It's important to note that we do not preload the lazy engine assets in the test environment here because preloaded engine routes are not promises but the actual route instance. - Adds ember-engines to dev dependencies for testing. - Create a lazy engine in the dummy app. - Make sure we can visit this engine without preloading its assets.
- Loading branch information
1 parent
cd654e9
commit 1d3e64d
Showing
19 changed files
with
2,729 additions
and
1,289 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
|
||
# dependencies | ||
/node_modules/ | ||
tests/dummy/lib/**/node_modules | ||
|
||
# misc | ||
/coverage/ | ||
|
This file contains 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 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
# dependencies | ||
/node_modules/ | ||
tests/dummy/lib/**/node_modules | ||
|
||
# misc | ||
/.env* | ||
|
This file contains 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function isThenable(obj) { | ||
if ((typeof obj === 'object' && obj !== null) || typeof obj === 'function') { | ||
return typeof obj.then === 'function'; | ||
} | ||
|
||
return false; | ||
} |
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { module, test } from 'qunit'; | ||
import { visit, currentURL } from '@ember/test-helpers'; | ||
import { setupApplicationTest } from 'ember-qunit'; | ||
|
||
module('Acceptance | lazy engine', function(hooks) { | ||
setupApplicationTest(hooks); | ||
|
||
test('it can load an async route from a lazy loaded engine', async function(assert) { | ||
await visit('/lazy-engine/my-route'); | ||
|
||
assert.dom('#test-my-route-model').hasText('test prefetch hook'); | ||
assert.equal(currentURL(), '/lazy-engine/my-route'); | ||
}); | ||
}); |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import Engine from 'ember-engines/engine'; | ||
import loadInitializers from 'ember-load-initializers'; | ||
import Resolver from './resolver'; | ||
import config from './config/environment'; | ||
|
||
const { modulePrefix } = config; | ||
const Eng = Engine.extend({ | ||
modulePrefix, | ||
Resolver, | ||
}); | ||
|
||
loadInitializers(Eng, modulePrefix); | ||
|
||
export default Eng; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Resolver from 'ember-resolver'; | ||
|
||
export default Resolver; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import buildRoutes from 'ember-engines/routes'; | ||
|
||
export default buildRoutes(function() { | ||
this.route('my-route'); | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Route from '@ember/routing/route'; | ||
import RSVP from 'rsvp'; | ||
|
||
export default Route.extend({ | ||
prefetch() { | ||
return RSVP.Promise.resolve({ test: 'test prefetch hook' }); | ||
}, | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
{{outlet}} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
<div id="test-my-route-model">{{model.test}}</div> |
This file contains 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
module.exports = function(environment) { | ||
let ENV = { | ||
modulePrefix: 'lazy-engine', | ||
environment, | ||
}; | ||
|
||
return ENV; | ||
}; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-env node */ | ||
'use strict'; | ||
|
||
// eslint-disable-next-line node/no-extraneous-require | ||
const EngineAddon = require('ember-engines/lib/engine-addon'); | ||
|
||
module.exports = EngineAddon.extend({ | ||
name: 'lazy-engine', | ||
|
||
lazyLoading: Object.freeze({ | ||
enabled: true, | ||
}), | ||
|
||
isDevelopingAddon() { | ||
return true; | ||
}, | ||
}); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "lazy-engine", | ||
"version": "0.0.0", | ||
"keywords": [ | ||
"ember-addon", | ||
"ember-engine" | ||
], | ||
"ember-addon": { | ||
"engineConfigPath": "ember-config" | ||
}, | ||
"dependencies": { | ||
"ember-cli-babel": "*", | ||
"ember-cli-htmlbars": "*" | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { isThenable } from 'ember-prefetch/-private/utils/is-thenable'; | ||
import { module, test } from 'qunit'; | ||
|
||
module('Unit | Utility | is-thenable', function() { | ||
test('basic sanity check', function(assert) { | ||
const thenable = { then: () => {} }; | ||
assert.equal(isThenable(thenable), true, 'returns true for thenable'); | ||
assert.equal(isThenable({}), false, 'returns false for non thenable'); | ||
assert.equal(isThenable(), false, 'returns false for undefined'); | ||
assert.equal(isThenable(null), false, 'returns false for null'); | ||
}); | ||
}); |
Oops, something went wrong.