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

Fix issues with embroider-optimized scenarios. #1221

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 10 additions & 28 deletions addon-test-support/@ember/test-helpers/setup-rendering-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import hasEmberVersion from './has-ember-version';
import isComponent from './-internal/is-component';
import { macroCondition, dependencySatisfies } from '@embroider/macros';
import { ComponentRenderMap, SetUsage } from './setup-context';
import { ensureSafeComponent } from '@embroider/util';
import type { ComponentInstance } from '@glimmer/interfaces';

const OUTLET_TEMPLATE = hbs`{{outlet}}`;
const EMPTY_TEMPLATE = hbs``;
const INVOKE_PROVIDED_COMPONENT = hbs`<this.ProvidedComponent />`;
const DYNAMIC_INVOKE_PROVIDED_COMPONENT = hbs`{{component this.ProvidedComponent}}`;

export interface RenderingTestContext extends TestContext {
render(template: TemplateFactory): Promise<void>;
Expand Down Expand Up @@ -157,33 +157,15 @@ export function render(
);
}

if (
macroCondition(
dependencySatisfies('ember-source', '>=3.25.0-beta.1')
)
) {
// In 3.25+, we can treat components as one big object and just pass them around/invoke them
// wherever, so we just assign the component to the `ProvidedComponent` property and invoke it
// in the test's template
context = {
ProvidedComponent: templateOrComponent,
};
templateOrComponent = INVOKE_PROVIDED_COMPONENT;
} else {
// Below 3.25, however, we *cannot* treat components as one big object and instead have to
// register their class and template independently and then invoke them with the `component`
// helper so they can actually be found by the resolver and rendered
templateId += 1;
let name = `-undertest-${templateId}`;
let componentFullName = `component:${name}`;
let templateFullName = `template:components/${name}`;
context = {
ProvidedComponent: name,
};
ownerToRenderFrom.register(componentFullName, templateOrComponent);
templateOrComponent = DYNAMIC_INVOKE_PROVIDED_COMPONENT;
ownerToRenderFrom.register(templateFullName, templateOrComponent);
}
let ProvidedComponent = ensureSafeComponent(
templateOrComponent,
context
);

context = {
ProvidedComponent,
};
templateOrComponent = INVOKE_PROVIDED_COMPONENT;
} else {
templateId += 1;
let templateFullName = `template:-undertest-${templateId}`;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dependencies": {
"@ember/test-waiters": "^3.0.0",
"@embroider/macros": "^1.6.0",
"@embroider/util": "^1.6.0",
"broccoli-debug": "^0.6.5",
"broccoli-funnel": "^3.0.8",
"ember-cli-babel": "^7.26.6",
Expand Down
17 changes: 13 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1810,7 +1810,7 @@
ember-cli-version-checker "^5.1.2"
semver "^7.3.5"

"@embroider/macros@^1.6.0":
"@embroider/macros@1.6.0", "@embroider/macros@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@embroider/macros/-/macros-1.6.0.tgz#2b764f965c645fdcfbf05897c88195368b046ba1"
integrity sha512-yUEXJGJGP3rjtxorxrbkdxriBFEwnmzOrNk4zK64IXKBfyRjiDZFUHV9DSTrbaYLS29Mw5yK73ZIwi8L13C4Zw==
Expand Down Expand Up @@ -1851,6 +1851,15 @@
semver "^7.3.2"
typescript-memoize "^1.0.0-alpha.3"

"@embroider/util@^1.6.0":
version "1.6.0"
resolved "https://registry.yarnpkg.com/@embroider/util/-/util-1.6.0.tgz#6a817dfd5192afaab41e80ebce623d5812b30985"
integrity sha512-oUQDAMiAATHsiNwEMH/SzNSQ/Z5wDr9f6NImsDIFLvDT6T34/p7cqR4wyfrfMRtcc1EB6PbwhZ6bXYsJ6QPWRA==
dependencies:
"@embroider/macros" "1.6.0"
broccoli-funnel "^3.0.5"
ember-cli-babel "^7.23.1"

"@eslint/eslintrc@^0.4.3":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.4.3.tgz#9e42981ef035beb3dd49add17acb96e8ff6f394c"
Expand Down Expand Up @@ -6587,9 +6596,9 @@ ember-source-channel-url@^3.0.0:
node-fetch "^2.6.0"

ember-source@~3.28.4:
version "3.28.4"
resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-3.28.4.tgz#b6ac2b1e369ef533d05164c65078b4ceafdb6390"
integrity sha512-s7kVy0E08erAHUTI/8SZZvXt3an/xb2g5K+m4Rybvo8Tr/noMk3lIdtyQkSvmgMZ/BbvoW8spS630sO0/JN4Eg==
version "3.28.9"
resolved "https://registry.yarnpkg.com/ember-source/-/ember-source-3.28.9.tgz#804c56b2d71d3cc3decff15a3273bb35d668300a"
integrity sha512-Fy7V3yvj+3oyo2+ke52aaihKMcFnnF7Oj9ixj547yzh2faqRfqouB5ZSiwXFH8rxw22rKaM8DiuQO4JN2Ay6xQ==
dependencies:
"@babel/helper-module-imports" "^7.8.3"
"@babel/plugin-transform-block-scoping" "^7.8.3"
Expand Down