Skip to content

Commit

Permalink
Set proper moduleName values
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Mar 4, 2018
1 parent d652f47 commit 2020953
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ moduleFor('Application test: rendering', class extends ApplicationTest {
template: 'Hi {{person.name}} from component'
});

let expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "template:routeWithError" and modified in "component:x-foo"/;
let expectedBacktrackingMessage = /modified "model\.name" twice on \[object Object\] in a single render\. It was rendered in "template:my-app\/templates\/routeWithError.hbs" and modified in "component:x-foo"/;

return this.visit('/').then(() => {
expectAssertion(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,20 @@ function buildResolver() {
let [sourceType, sourceName ] = sourceFullName.split(':');
let [type, name ] = fullName.split(':');

if (type !== 'template' && sourceType === 'template' && sourceName.slice(0, 11) === 'components/') {
sourceName = sourceName.slice(11);
sourceName = sourceName.replace('my-app/', '');

if (sourceType === 'template' && sourceName.slice(0, 21) === 'templates/components/') {
sourceName = sourceName.slice(21);
}

if (type === 'template' && sourceType === 'template' && name.slice(0, 11) === 'components/') {
name = name.replace('my-app/', '');

if (type === 'template' && name.slice(0, 11) === 'components/') {
name = name.slice(11);
sourceName = `components/${sourceName}`;
}

sourceName = sourceName.replace('.hbs', '');

let result = `${type}:${sourceName}/${name}`;

Expand All @@ -229,13 +235,15 @@ moduleFor('Components test: local lookup with expandLocalLookup feature', class
if (EMBER_MODULE_UNIFICATION) {
class LocalLookupTestResolver extends ModuleBasedTestResolver {
resolve(specifier, referrer) {
let [type, name ] = specifier.split(':');
let fullSpecifier = specifier;

if (referrer) {
let namespace = referrer.split('template:components/')[1];
let namespace = referrer.split('components/')[1] || '';
namespace = namespace.replace('.hbs', '');
if (specifier.indexOf('template:components/') !== -1) {
let name = specifier.split('template:components/')[1];
fullSpecifier = `template:components/${namespace}/${name}`;
name = name.replace('components/', '');
fullSpecifier = `${type}:components/${namespace}/${name}`;
} else if (specifier.indexOf(':') !== -1) {
let [type, name] = specifier.split(':');
fullSpecifier = `${type}:${namespace}/${name}`;
Expand Down Expand Up @@ -272,7 +280,7 @@ if (EMBER_MODULE_UNIFICATION) {

if (typeof template === 'string') {
resolver.add(`template:components/${name}`, this.compile(template, {
moduleName: `components/${name}`
moduleName: `my-name/templates/components/${name}.hbs`
}));
}
}
Expand All @@ -281,7 +289,7 @@ if (EMBER_MODULE_UNIFICATION) {
let { resolver } = this;
if (typeof template === 'string') {
resolver.add(`template:${name}`, this.compile(template, {
moduleName: name
moduleName: `my-name/templates/${name}.hbs`
}));
} else {
throw new Error(`Registered template "${name}" must be a string`);
Expand Down
20 changes: 10 additions & 10 deletions packages/ember-glimmer/tests/integration/mount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ moduleFor('{{mount}} test', class extends ApplicationTest {
}

['@test it boots an engine, instantiates its application controller, and renders its application template'](assert) {
this.engineRegistrations['template:application'] = compile('<h2>Chat here, {{username}}</h2>', { moduleName: 'application' });
this.engineRegistrations['template:application'] = compile('<h2>Chat here, {{username}}</h2>', { moduleName: 'my-app/templates/application.hbs' });

let controller;

Expand Down Expand Up @@ -103,20 +103,20 @@ moduleFor('{{mount}} test', class extends ApplicationTest {
this.addTemplate('index', '');
this.addTemplate('route-with-mount', '{{mount "chat"}}');

this.engineRegistrations['template:application'] = compile('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'application' });
this.engineRegistrations['template:application'] = compile('hi {{person.name}} [{{component-with-backtracking-set person=person}}]', { moduleName: 'my-app/templates/application.hbs' });
this.engineRegistrations['controller:application'] = Controller.extend({
person: { name: 'Alex' }
});

this.engineRegistrations['template:components/component-with-backtracking-set'] = compile('[component {{person.name}}]', { moduleName: 'components/component-with-backtracking-set' });
this.engineRegistrations['template:components/component-with-backtracking-set'] = compile('[component {{person.name}}]', { moduleName: 'my-app/templates/components/component-with-backtracking-set.hbs' });
this.engineRegistrations['component:component-with-backtracking-set'] = Component.extend({
init() {
this._super(...arguments);
this.set('person.name', 'Ben');
}
});

let expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:route-with-mount" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/;
let expectedBacktrackingMessage = /modified "person\.name" twice on \[object Object\] in a single render\. It was rendered in "template:my-app\/templates\/route-with-mount.hbs" \(in "engine:chat"\) and modified in "component:component-with-backtracking-set" \(in "engine:chat"\)/;

return this.visit('/').then(() => {
expectAssertion(() => {
Expand All @@ -143,14 +143,14 @@ moduleFor('{{mount}} test', class extends ApplicationTest {
router: null,
init() {
this._super(...arguments);
this.register('template:application', compile('<h2>Foo Engine</h2>', { moduleName: 'application' }));
this.register('template:application', compile('<h2>Foo Engine</h2>', { moduleName: 'my-app/templates/application.hbs' }));
}
}));
this.add('engine:bar', Engine.extend({
router: null,
init() {
this._super(...arguments);
this.register('template:application', compile('<h2>Bar Engine</h2>', { moduleName: 'application' }));
this.register('template:application', compile('<h2>Bar Engine</h2>', { moduleName: 'my-app/templates/application.hbs' }));
}
}));

Expand Down Expand Up @@ -203,15 +203,15 @@ moduleFor('{{mount}} test', class extends ApplicationTest {
router: null,
init() {
this._super(...arguments);
this.register('template:application', compile('<h2>Foo Engine: {{tagless-component}}</h2>', { moduleName: 'application' }));
this.register('template:application', compile('<h2>Foo Engine: {{tagless-component}}</h2>', { moduleName: 'my-app/templates/application.hbs' }));
this.register('component:tagless-component', Component.extend({
tagName: "",
init() {
this._super(...arguments);
component = this;
}
}));
this.register('template:components/tagless-component', compile('Tagless Component', { moduleName: 'components/tagless-component' }));
this.register('template:components/tagless-component', compile('Tagless Component', { moduleName: 'my-app/templates/components/tagless-component.hbs' }));
}
}));

Expand All @@ -236,7 +236,7 @@ if (EMBER_ENGINES_MOUNT_PARAMS) {
router: null,
init() {
this._super(...arguments);
this.register('template:application', compile('<h2>Param Engine: {{model.foo}}</h2>', { moduleName: 'application' }));
this.register('template:application', compile('<h2>Param Engine: {{model.foo}}</h2>', { moduleName: 'my-app/templates/application.hbs' }));
}
}));
}
Expand Down Expand Up @@ -311,7 +311,7 @@ if (EMBER_ENGINES_MOUNT_PARAMS) {
router: null,
init() {
this._super(...arguments);
this.register('template:application', compile('{{model.foo}}', { moduleName: 'application' }));
this.register('template:application', compile('{{model.foo}}', { moduleName: 'my-app/templates/application.hbs' }));
}
}));
this.addTemplate('engine-params-contextual-component', '{{mount "componentParamEngine" model=(hash foo=(component "foo-component"))}}');
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-glimmer/tests/unit/template-factory-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ moduleFor('Template factory test', class extends RenderingTest {
let { runtimeResolver } = this;

let templateStr = 'Hello {{name}}';
let options = { moduleName: 'some-module' };
let options = { moduleName: 'my-app/templates/some-module.hbs' };

let spec = precompile(templateStr, options);
let body = `exports.default = template(${spec});`;
Expand Down
4 changes: 2 additions & 2 deletions packages/ember/tests/integration/multiple-app-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ moduleFor('View Integration', class extends ApplicationTestCase {
this.compile(`
<h1>Node 1</h1>{{special-button}}
`, {
moduleName: 'index'
moduleName: 'my-app/templates/index.hbs'
})
);
resolver.add(
'template:components/special-button',
this.compile(`
<button class='do-stuff' {{action 'doStuff'}}>Button</button>
`, {
moduleName: 'components/special-button'
moduleName: 'my-app/templates/components/special-button.hbs'
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase {
registerPartial(name, template) {
let owner = this.env.owner || this.owner;
if (typeof template === 'string') {
let moduleName = `template:${name}`;
owner.register(moduleName, this.compile(template, { moduleName }));
owner.register(`template:${name}`, this.compile(template, { moduleName: `my-app/templates/-${name}.hbs` }));
}
}

Expand All @@ -112,7 +111,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase {

if (typeof template === 'string') {
owner.register(`template:components/${name}`, this.compile(template, {
moduleName: `components/${name}`
moduleName: `my-app/templates/components/${name}.hbs`
}));
}
}
Expand All @@ -121,7 +120,7 @@ export default class AbstractRenderingTestCase extends AbstractTestCase {
let { owner } = this;
if (typeof template === 'string') {
owner.register(`template:${name}`, this.compile(template, {
moduleName: name
moduleName: `my-app/templates/${name}.hbs`
}));
} else {
throw new Error(`Registered template "${name}" must be a string`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class TestResolverApplicationTestCase extends AbstractApplication

addTemplate(templateName, templateString) {
this.resolver.add(`template:${templateName}`, this.compile(templateString, {
moduleName: templateName
moduleName: `my-app/templates/${templateName}.hbs`
}));
}

Expand All @@ -28,7 +28,7 @@ export default class TestResolverApplicationTestCase extends AbstractApplication

if (typeof template === 'string') {
this.resolver.add(`template:components/${name}`, this.compile(template, {
moduleName: `components/${name}`
moduleName: `my-app/templates/components/${name}.hbs`
}));
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/internal-test-helpers/lib/test-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Resolver {
throw new Error(`You called addTemplate for "${templateName}" with a template argument of type of '${templateType}'. addTemplate expects an argument of an uncompiled template as a string.`);
}
return this._registered[serializeKey(`template:${templateName}`)] = compile(template, {
moduleName: templateName
moduleName: `my-app/templates/${templateName}.hbs`
});
}
static create() {
Expand Down

0 comments on commit 2020953

Please sign in to comment.