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 octane component blueprint and octane blueprint tests #17740

Merged
merged 1 commit into from
Mar 14, 2019
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
27 changes: 25 additions & 2 deletions blueprints/component-addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const useEditionDetector = require('../edition-detector');

module.exports = {
module.exports = useEditionDetector({
description: 'Generates a component.',

fileMapTokens: function() {
Expand All @@ -28,6 +29,18 @@ module.exports = {
}
return 'app';
},
__templatepath__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'templates/components';
},
__templatename__: function(options) {
if (options.pod) {
return 'template';
}
return options.dasherizedModuleName;
},
};
},

Expand All @@ -40,14 +53,24 @@ module.exports = {
let addonName = stringUtil.dasherize(addonRawName);
let fileName = stringUtil.dasherize(options.entity.name);
let importPathName = [addonName, 'components', fileName].join('/');
let templatePath = '';

if (options.pod) {
importPathName = [addonName, 'components', fileName, 'component'].join('/');
}

if (this.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
if (options.pod) {
templatePath = './template';
} else {
templatePath = [addonName, 'templates/components', fileName].join('/');
}
}

return {
modulePath: importPathName,
templatePath,
path: getPathOption(options),
};
},
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= modulePath %>';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '<%= templatePath %>';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Component from '@glimmer/component';
<%= importTemplate %>
export default class <%= classifiedModuleName %>Component extends Component {<%= contents %>

export default class <%= classifiedModuleName %>Component extends Component {
}
117 changes: 72 additions & 45 deletions node-tests/blueprints/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,13 +516,11 @@ describe('Blueprint: component', function() {

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js')).to.equal(
fixture('component/native-component.js')
);
expect(_file('app/components/foo.js')).to.equal(fixture('component/native-component.js'));

expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}');
expect(_file('app/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/component-test.js')).to.equal(
expect(_file('tests/integration/components/foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
Expand All @@ -535,13 +533,13 @@ describe('Blueprint: component', function() {

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js')).to.equal(
expect(_file('app/components/x-foo.js')).to.equal(
fixture('component/native-component-dash.js')
);

expect(_file('src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('app/templates/components/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/x-foo/component-test.js')).to.equal(
expect(_file('tests/integration/components/x-foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
Expand All @@ -554,13 +552,13 @@ describe('Blueprint: component', function() {

it('component foo/x-foo', function() {
return emberGenerateDestroy(['component', 'foo/x-foo'], _file => {
expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal(
expect(_file('app/components/foo/x-foo.js')).to.equal(
fixture('component/native-component-nested.js')
);

expect(_file('src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('app/templates/components/foo/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal(
expect(_file('tests/integration/components/foo/x-foo-test.js')).to.equal(
fixture('component-test/default-curly-template.js', {
replace: {
component: 'foo/x-foo',
Expand Down Expand Up @@ -821,19 +819,23 @@ describe('Blueprint: component', function() {

it('component foo', function() {
return emberGenerateDestroy(['component', 'foo'], _file => {
expect(_file('src/ui/components/foo/component.js')).to.equal(
fixture('component/native-component.js')
expect(_file('addon/components/foo.js')).to.equal(fixture('component/native-component.js'));

expect(_file('addon/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('app/components/foo.js')).to.contain(
"export { default } from 'my-addon/components/foo';"
);

expect(_file('src/ui/components/foo/template.hbs')).to.equal('{{yield}}');
expect(_file('app/templates/components/foo.js')).to.contain(
"export { default } from 'my-addon/templates/components/foo';"
);

expect(_file('src/ui/components/foo/component-test.js')).to.equal(
expect(_file('tests/integration/components/foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
componentInvocation: 'Foo',
path: 'my-addon::',
pathInvocation: 'MyAddon::',
},
})
);
Expand All @@ -842,19 +844,25 @@ describe('Blueprint: component', function() {

it('component x-foo', function() {
return emberGenerateDestroy(['component', 'x-foo'], _file => {
expect(_file('src/ui/components/x-foo/component.js')).to.equal(
expect(_file('addon/components/x-foo.js')).to.equal(
fixture('component/native-component-dash.js')
);

expect(_file('src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('addon/templates/components/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/x-foo/component-test.js')).to.equal(
expect(_file('app/components/x-foo.js')).to.contain(
"export { default } from 'my-addon/components/x-foo';"
);

expect(_file('app/templates/components/x-foo.js')).to.contain(
"export { default } from 'my-addon/templates/components/x-foo';"
);

expect(_file('tests/integration/components/x-foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
componentInvocation: 'XFoo',
path: 'my-addon::',
pathInvocation: 'MyAddon::',
},
})
);
Expand All @@ -863,17 +871,24 @@ describe('Blueprint: component', function() {

it('component foo/x-foo', function() {
return emberGenerateDestroy(['component', 'foo/x-foo'], _file => {
expect(_file('src/ui/components/foo/x-foo/component.js')).to.equal(
expect(_file('addon/components/foo/x-foo.js')).to.equal(
fixture('component/native-component-nested.js')
);

expect(_file('src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('addon/templates/components/foo/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.equal(
expect(_file('app/components/foo/x-foo.js')).to.contain(
"export { default } from 'my-addon/components/foo/x-foo';"
);

expect(_file('app/templates/components/foo/x-foo.js')).to.contain(
"export { default } from 'my-addon/templates/components/foo/x-foo';"
);

expect(_file('tests/integration/components/foo/x-foo-test.js')).to.equal(
fixture('component-test/default-curly-template.js', {
replace: {
component: 'foo/x-foo',
path: 'my-addon::',
},
})
);
Expand All @@ -882,29 +897,31 @@ describe('Blueprint: component', function() {

it('component x-foo --dummy', function() {
return emberGenerateDestroy(['component', 'x-foo', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/components/x-foo/component.js')).to.equal(
expect(_file('tests/dummy/app/components/x-foo.js')).to.equal(
fixture('component/native-component-dash.js')
);

expect(_file('tests/dummy/src/ui/components/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('tests/dummy/app/templates/components/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/x-foo/component.js')).to.not.exist;
expect(_file('app/components/x-foo.js')).to.not.exist;
expect(_file('app/templates/components/x-foo.js')).to.not.exist;

expect(_file('src/ui/components/x-foo/component-test.js')).to.not.exist;
expect(_file('tests/integration/components/x-foo-test.js')).to.not.exist;
});
});

it('component foo/x-foo --dummy', function() {
return emberGenerateDestroy(['component', 'foo/x-foo', '--dummy'], _file => {
expect(_file('tests/dummy/src/ui/components/foo/x-foo/component.js')).to.equal(
expect(_file('tests/dummy/app/components/foo/x-foo.js')).to.equal(
fixture('component/native-component-nested.js')
);

expect(_file('tests/dummy/src/ui/components/foo/x-foo/template.hbs')).to.equal('{{yield}}');
expect(_file('tests/dummy/app/templates/components/foo/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('src/ui/components/foo/x-foo/component.js')).to.not.exist;
expect(_file('app/components/foo/x-foo.js')).to.not.exist;
expect(_file('app/templates/components/foo/x-foo.js')).to.not.exist;

expect(_file('src/ui/components/foo/x-foo/component-test.js')).to.not.exist;
expect(_file('tests/integration/components/foo/x-foo-test.js')).to.not.exist;
});
});
});
Expand Down Expand Up @@ -1120,19 +1137,25 @@ describe('Blueprint: component', function() {

it('component foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('packages/my-addon/src/ui/components/foo/component.js')).to.equal(
expect(_file('lib/my-addon/addon/components/foo.js')).to.equal(
fixture('component/native-component.js')
);

expect(_file('packages/my-addon/src/ui/components/foo/template.hbs')).to.equal('{{yield}}');
expect(_file('lib/my-addon/addon/templates/components/foo.hbs')).to.equal('{{yield}}');

expect(_file('packages/my-addon/src/ui/components/foo/component-test.js')).to.equal(
expect(_file('lib/my-addon/app/components/foo.js')).to.contain(
"export { default } from 'my-addon/components/foo';"
);

expect(_file('lib/my-addon/app/templates/components/foo.js')).to.contain(
"export { default } from 'my-addon/templates/components/foo';"
);

expect(_file('tests/integration/components/foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'foo',
componentInvocation: 'Foo',
path: 'my-addon::',
pathInvocation: 'MyAddon::',
},
})
);
Expand All @@ -1141,21 +1164,25 @@ describe('Blueprint: component', function() {

it('component x-foo --in-repo-addon=my-addon', function() {
return emberGenerateDestroy(['component', 'x-foo', '--in-repo-addon=my-addon'], _file => {
expect(_file('packages/my-addon/src/ui/components/x-foo/component.js')).to.equal(
expect(_file('lib/my-addon/addon/components/x-foo.js')).to.equal(
fixture('component/native-component-dash.js')
);

expect(_file('packages/my-addon/src/ui/components/x-foo/template.hbs')).to.equal(
'{{yield}}'
expect(_file('lib/my-addon/addon/templates/components/x-foo.hbs')).to.equal('{{yield}}');

expect(_file('lib/my-addon/app/components/x-foo.js')).to.contain(
"export { default } from 'my-addon/components/x-foo';"
);

expect(_file('packages/my-addon/src/ui/components/x-foo/component-test.js')).to.equal(
expect(_file('lib/my-addon/app/templates/components/x-foo.js')).to.contain(
"export { default } from 'my-addon/templates/components/x-foo';"
);

expect(_file('tests/integration/components/x-foo-test.js')).to.equal(
fixture('component-test/default-template.js', {
replace: {
component: 'x-foo',
componentInvocation: 'XFoo',
path: 'my-addon::',
pathInvocation: 'MyAddon::',
},
})
);
Expand Down
Loading