-
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,954 additions
and
14 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
42 changes: 42 additions & 0 deletions
42
addon-test-support/@ember/test-helpers/-internal/get-component-manager.ts
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,42 @@ | ||
import Ember from 'ember'; | ||
import { | ||
macroCondition, | ||
importSync, | ||
dependencySatisfies, | ||
} from '@embroider/macros'; | ||
import type { InternalComponentManager } from '@glimmer/interfaces'; | ||
|
||
let getComponentManager: ( | ||
definition: object, | ||
owner: object | ||
) => InternalComponentManager | null; | ||
|
||
if (macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1'))) { | ||
let _getComponentManager = | ||
//@ts-ignore | ||
importSync('@glimmer/manager').getInternalComponentManager; | ||
|
||
getComponentManager = (definition: object, owner: object) => { | ||
return _getComponentManager(definition, true); | ||
}; | ||
} else if ( | ||
macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1')) | ||
) { | ||
let _getComponentManager = (Ember as any).__loader.require( | ||
'@glimmer/manager' | ||
).getInternalComponentManager; | ||
|
||
getComponentManager = (definition: object, owner: object) => { | ||
return _getComponentManager(definition, true); | ||
}; | ||
} else { | ||
let _getComponentManager = (Ember as any).__loader.require( | ||
'@glimmer/runtime' | ||
).getComponentManager; | ||
|
||
getComponentManager = (definition: object, owner: object) => { | ||
return _getComponentManager(owner, definition); | ||
}; | ||
} | ||
|
||
export default getComponentManager; |
26 changes: 26 additions & 0 deletions
26
addon-test-support/@ember/test-helpers/-internal/is-component.ts
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,26 @@ | ||
import { macroCondition, dependencySatisfies } from '@embroider/macros'; | ||
|
||
import getComponentManager from './get-component-manager'; | ||
|
||
/** | ||
* We should ultimately get a new API from @glimmer/runtime that provides this functionality | ||
* (see https://github.com/emberjs/rfcs/pull/785 for more info). | ||
* @private | ||
* @param {Object} maybeComponent The thing you think might be a component | ||
* @param {Object} owner Owner, we need this for old versions of getComponentManager | ||
* @returns {boolean} True if it's a component, false if not | ||
*/ | ||
function isComponent(maybeComponent: object, owner: object): boolean { | ||
if (macroCondition(dependencySatisfies('ember-source', '>=3.25.0-beta.1'))) { | ||
return !!getComponentManager(maybeComponent, owner); | ||
} else { | ||
return ( | ||
!!getComponentManager(maybeComponent, owner) || | ||
['@ember/component', '@ember/component/template-only'].includes( | ||
maybeComponent.toString() | ||
) | ||
); | ||
} | ||
} | ||
|
||
export default isComponent; |
31 changes: 31 additions & 0 deletions
31
addon-test-support/@ember/test-helpers/-internal/render-settled.ts
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,31 @@ | ||
import Ember from 'ember'; | ||
import { | ||
macroCondition, | ||
importSync, | ||
dependencySatisfies, | ||
} from '@embroider/macros'; | ||
|
||
let renderSettled: () => Promise<void>; | ||
|
||
// TODO need to add the actual version `@ember/renderer` landed once we know it | ||
if (macroCondition(dependencySatisfies('ember-source', '>=4.9999999.0'))) { | ||
//@ts-ignore | ||
renderSettled = importSync('@ember/renderer').renderSettled; | ||
} else if ( | ||
macroCondition(dependencySatisfies('ember-source', '>=3.27.0-alpha.1')) | ||
) { | ||
//@ts-ignore | ||
renderSettled = importSync('@ember/-internals/glimmer').renderSettled; | ||
} else if ( | ||
macroCondition(dependencySatisfies('ember-source', '>=3.6.0-alpha.1')) | ||
) { | ||
renderSettled = (Ember as any).__loader.require( | ||
'@ember/-internals/glimmer' | ||
).renderSettled; | ||
} else { | ||
renderSettled = (Ember as any).__loader.require( | ||
'ember-glimmer' | ||
).renderSettled; | ||
} | ||
|
||
export default renderSettled; |
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,21 @@ | ||
import renderSettled from './-internal/render-settled'; | ||
|
||
/** | ||
Returns a promise which will resolve when rendering has completed. In | ||
this context, rendering is completed when all auto-tracked state that is | ||
consumed in the template (including any tracked state in models, services, | ||
etc. that are then used in a template) has been updated in the DOM. | ||
For example, in a test you might want to update some tracked state and | ||
then run some assertions after rendering has completed. You _could_ use | ||
`await settled()` in that location, but in some contexts you don't want to | ||
wait for full settledness (which includes test waiters, pending AJAX/fetch, | ||
run loops, etc) but instead only want to know when that updated value has | ||
been rendered in the DOM. **THAT** is what `await rerender()` is _perfect_ | ||
for. | ||
@public | ||
@returns {Promise<void>} a promise which fulfills when rendering has completed | ||
*/ | ||
export default function rerender() { | ||
return renderSettled(); | ||
} |
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
Oops, something went wrong.