-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix issues with the recent template factory refactor and @ember/test-helpers v1.6.0 #18168
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
Merged
Merged
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
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 |
|---|---|---|
|
|
@@ -8,6 +8,10 @@ import { SerializedTemplateWithLazyBlock } from '@glimmer/wire-format'; | |
| export type StaticTemplate = SerializedTemplateWithLazyBlock<StaticTemplateMeta>; | ||
| export type OwnedTemplate = Template<OwnedTemplateMeta>; | ||
|
|
||
| export function isTemplateFactory(template: OwnedTemplate | Factory): template is Factory { | ||
|
Contributor
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. Should we rename the interface below to TemplateFactory? |
||
| return typeof template === 'function'; | ||
| } | ||
|
|
||
| export function id(factory: Factory): string { | ||
| return factory.__id; | ||
| } | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| import { Promise } from 'rsvp'; | ||
| import Application from '@ember/application'; | ||
| import { run, hasScheduledTimers, getCurrentRunLoop } from '@ember/runloop'; | ||
| import { compile } from 'ember-template-compiler'; | ||
|
|
||
| const { module, test } = QUnit; | ||
|
|
||
| /* | ||
| This test file is intended to emulate what @ember/test-helpers does, and | ||
| should be considered a "smoke test" of when a given change will break | ||
| existing versions of @ember/test-helpers. | ||
|
|
||
| This generally means that we will have to represent multiple versions of | ||
| `@ember/test-helpers` here (will make a nested module for each significant | ||
| revision). | ||
| */ | ||
| module('@ember/test-helpers emulation test', function() { | ||
| module('v1.6.0', function() { | ||
| let EMPTY_TEMPLATE = compile(''); | ||
|
|
||
| function settled() { | ||
| return new Promise(function(resolve) { | ||
| let watcher = setInterval(() => { | ||
| if (getCurrentRunLoop() || hasScheduledTimers()) { | ||
| return; | ||
| } | ||
|
|
||
| // Stop polling | ||
| clearInterval(watcher); | ||
|
|
||
| // Synchronously resolve the promise | ||
| run(null, resolve); | ||
| }, 10); | ||
| }); | ||
| } | ||
|
|
||
| async function setupContext(context) { | ||
| // condensed version of https://github.com/emberjs/ember-test-helpers/blob/v1.6.0/addon-test-support/%40ember/test-helpers/build-owner.ts#L38 | ||
| // without support for "custom resolver" | ||
| await context.application.boot(); | ||
|
|
||
| context.owner = await context.application.buildInstance().boot(); | ||
| } | ||
|
|
||
| function setupRenderingContext(context) { | ||
| let { owner } = context; | ||
| let OutletView = owner.factoryFor('view:-outlet'); | ||
| let toplevelView = OutletView.create(); | ||
|
|
||
| owner.register('-top-level-view:main', { | ||
| create() { | ||
| return toplevelView; | ||
| }, | ||
| }); | ||
|
|
||
| // initially render a simple empty template | ||
| return render(EMPTY_TEMPLATE, context).then(() => { | ||
| let rootElement = document.querySelector(owner.rootElement); | ||
| run(toplevelView, 'appendTo', rootElement); | ||
|
|
||
| context.element = rootElement; | ||
|
|
||
| return settled(); | ||
| }); | ||
| } | ||
|
|
||
| let templateId = 0; | ||
| function render(template, context) { | ||
| let { owner } = context; | ||
| let toplevelView = owner.lookup('-top-level-view:main'); | ||
| let OutletTemplate = owner.lookup('template:-outlet'); | ||
| templateId += 1; | ||
| let templateFullName = `template:-undertest-${templateId}`; | ||
| owner.register(templateFullName, template); | ||
|
|
||
| let outletState = { | ||
| render: { | ||
| owner, | ||
| into: undefined, | ||
| outlet: 'main', | ||
| name: 'application', | ||
| controller: undefined, | ||
| ViewClass: undefined, | ||
| template: OutletTemplate, | ||
| }, | ||
|
|
||
| outlets: { | ||
| main: { | ||
| render: { | ||
| owner, | ||
| into: undefined, | ||
| outlet: 'main', | ||
| name: 'index', | ||
| controller: context, | ||
| ViewClass: undefined, | ||
| template: owner.lookup(templateFullName), | ||
| outlets: {}, | ||
| }, | ||
| outlets: {}, | ||
| }, | ||
| }, | ||
| }; | ||
| toplevelView.setOutletState(outletState); | ||
|
|
||
| return settled(); | ||
| } | ||
|
|
||
| module('setupRenderingContext', function(hooks) { | ||
| hooks.beforeEach(async function() { | ||
| this.application = Application.create({ | ||
| rootElement: '#qunit-fixture', | ||
| autoboot: false, | ||
| }); | ||
|
|
||
| await setupContext(this); | ||
| await setupRenderingContext(this); | ||
| }); | ||
|
|
||
| hooks.afterEach(function() { | ||
| run(this.owner, 'destroy'); | ||
| run(this.application, 'destroy'); | ||
| }); | ||
|
|
||
| test('it basically works', async function(assert) { | ||
| await render(compile('Hi!'), this); | ||
|
|
||
| assert.equal(this.element.textContent, 'Hi!'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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.
So is the intention to still merge and release emberjs/ember-test-helpers#677 or to rather make a new backwards-incompatible release of
@ember/test-helpersthat drops support for all Ember versions prior to #18096? 🤔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.
Ya, I still think we should still land emberjs/ember-test-helpers#677.