Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

improve component blueprint for octane #218

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95b71c3
improve component blueprint for octane
BryanCrotaz Nov 8, 2020
eb10f74
remove unnecessary element definition
BryanCrotaz Nov 8, 2020
6fbeb4e
Update blueprints/component/files/__root__/__path__/__name__.ts
BryanCrotaz Nov 15, 2020
3111707
remove module unification files
BryanCrotaz Nov 15, 2020
6055241
remove ember-cli-shims and add peer dependencies
BryanCrotaz Nov 15, 2020
b9e0ad2
use node 12 to build on travis
BryanCrotaz Nov 15, 2020
25f77b0
fix no-prototype-builtins
BryanCrotaz Nov 15, 2020
71a2331
fix typo
BryanCrotaz Nov 15, 2020
8a74fee
add extraneous modules
BryanCrotaz Nov 15, 2020
7bf4065
move extraneous packages to dependencies
BryanCrotaz Nov 15, 2020
48fb02d
fix no-undef
BryanCrotaz Nov 15, 2020
ad17126
run with node 12 on appveyor
BryanCrotaz Nov 15, 2020
bb3bd3f
remove comment
BryanCrotaz Nov 15, 2020
018efdc
Merge branch master into octane-3
BryanCrotaz Nov 16, 2020
eedab5d
tidy up
BryanCrotaz Nov 16, 2020
1931c0a
Merge remote-tracking branch 'upstream/master' into octane-3
BryanCrotaz Nov 17, 2020
c1b73fb
yarn lock clean up
BryanCrotaz Nov 17, 2020
71dae68
remove jquery from generated tests
BryanCrotaz Nov 17, 2020
5123288
use ember-cli-htmlbars for testing this addon
BryanCrotaz Nov 17, 2020
83bbd00
Update node-tests/fixtures/component/component-nested.ts
BryanCrotaz Nov 17, 2020
e59a57f
Update node-tests/fixtures/component/component.ts
BryanCrotaz Nov 17, 2020
f4c3748
Update node-tests/fixtures/component/component-addon.ts
BryanCrotaz Nov 17, 2020
cead5d8
Update node-tests/fixtures/component/component-addon-nested.ts
BryanCrotaz Nov 17, 2020
cf0761b
clean up fixtures
BryanCrotaz Nov 17, 2020
5682b8c
fix linting and clean packages
BryanCrotaz Nov 17, 2020
7569313
remove unit tests for components
BryanCrotaz Nov 24, 2020
38ee3cd
update fixtures to remove unit tests
BryanCrotaz Nov 24, 2020
5b262cd
remove tests for unit testing components
BryanCrotaz Nov 24, 2020
4fe2936
fix helper test import of hbs
BryanCrotaz Nov 24, 2020
7f3d40c
use correct component name in tests
BryanCrotaz Nov 24, 2020
d7c98e4
generate correct component name
BryanCrotaz Nov 24, 2020
fd0febb
correct the component name creation
BryanCrotaz Nov 24, 2020
a878d30
fix component name generation
BryanCrotaz Nov 24, 2020
c0a09b9
bring in default blueprints from ember.js
BryanCrotaz Nov 24, 2020
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
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-env node */
module.exports = {
root: true,
parserOptions: {
Expand Down
81 changes: 81 additions & 0 deletions blueprints/component-test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
'use strict';

const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const getPathOption = require('ember-cli-get-component-path-option');

const useTestFrameworkDetector = require('../test-framework-detector');

function invocationFor(options) {
let parts = options.entity.name.split('/');
return parts.map((p) => stringUtil.classify(p)).join('::');
}

module.exports = useTestFrameworkDetector({
description: 'Generates a component integration or unit test.',

availableOptions: [
{
name: 'test-type',
type: ['integration', 'unit'],
default: 'integration',
aliases: [
{ i: 'integration' },
{ u: 'unit' },
{ integration: 'integration' },
{ unit: 'unit' },
],
},
],

fileMapTokens: function () {
return {
__root__() {
return 'tests';
},
__testType__(options) {
return options.locals.testType || 'integration';
},
__path__(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
}
return 'components';
},
};
},

locals: function (options) {
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);
let componentPathName = dasherizedModuleName;
let testType = options.testType || 'integration';

let friendlyTestDescription = [
testType === 'unit' ? 'Unit' : 'Integration',
'Component',
dasherizedModuleName,
].join(' | ');

if (options.pod && options.path !== 'components' && options.path !== '') {
componentPathName = [options.path, dasherizedModuleName].filter(Boolean).join('/');
}

let templateInvocation = invocationFor(options);
let componentName = templateInvocation;
let openComponent = (descriptor) => `<${descriptor}>`;
let closeComponent = (descriptor) => `</${descriptor}>`;
let selfCloseComponent = (descriptor) => `<${descriptor} />`;

return {
path: getPathOption(options),
testType: testType,
componentName,
componentPathName,
templateInvocation,
openComponent,
closeComponent,
selfCloseComponent,
friendlyTestDescription,
};
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from 'chai';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file should be replaced with the mocha rfc232 file!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still wrong—until you replace it with the correct file, stuff is going to be broken. Also, while you're at it, go ahead and remove all the shenanigans around supporting unit tests. As noted on the QUnit test blueprint, we only care here about integration tests, esp. b/c unit tests straight-up don't work with Glimmer components (as it should be!).

import { describeComponent, it } from 'ember-mocha';<% if (testType === 'integration') { %>
import hbs from 'htmlbars-inline-precompile';<% } %>

describeComponent('<%= componentPathName %>', '<%= friendlyTestDescription %>',
{
<% if (testType === 'integration' ) { %>integration: true<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar'],
unit: true<% } %>
},
function() {
it('renders', function() {
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });

this.render(hbs`<%= selfCloseComponent(componentName) %>`);
expect(this.element).to.not.be.null;

// Template block usage:
this.render(hbs`
<%= openComponent(componentName) %>
template block text
<%= closeComponent(componentName) %>
`);

expect(this.element.text().trim()).to.equal('template block text');<% } else if(testType === 'unit') { %>// creates the component instance
let component = this.subject();
// renders the component on the page
this.render();
expect(component).to.be.ok;
expect(this.element).to.not.be.null;<% } %>
});
}
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<% if (testType == 'integration') { %>
BryanCrotaz marked this conversation as resolved.
Show resolved Hide resolved
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

module('Integration | Component | <%= dasherizedModuleName %>', function(hooks) {
setupRenderingTest(hooks);

test('it renders', async function(assert) {
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.set('myAction', function(val) { ... });

await render(hbs`<<%= templateInvocation %> />`);

assert.equal(this.element.textContent.trim(), '');

// Template block usage:
await render(hbs`
<<%= templateInvocation %>>
template block text
</<%= templateInvocation %>>
`);

assert.equal(this.element.textContent.trim(), 'template block text');
});
});
<% } else if (testType == 'unit') { %>
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';

module('Unit | Component | <%= dasherizedModuleName %>', function(hooks) {
setupTest(hooks);

test('it exists', function(assert) {
let component = this.owner.factoryFor('component:<%= dasherizedModuleName %>').create();
assert.ok(component);
});
});
<% } >
4 changes: 4 additions & 0 deletions blueprints/component/files/__root__/__path__/__name__.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Component from '@ember/component';
<%= importTemplate %>
export default class <%= classifiedModuleName %> extends Component {
BryanCrotaz marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Component from '@glimmer/component';

interface <%= classifiedModuleName %>Args {
}

export default class <%= classifiedModuleName %> extends Component<<%= classifiedModuleName %>Args> {
};
89 changes: 89 additions & 0 deletions blueprints/component/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
'use strict';

const path = require('path');
const stringUtil = require('ember-cli-string-utils');
const pathUtil = require('ember-cli-path-utils');
const getPathOption = require('ember-cli-get-component-path-option');
const normalizeEntityName = require('ember-cli-normalize-entity-name');
const EOL = require('os').EOL;

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

availableOptions: [
{
name: 'path',
type: String,
default: 'components',
aliases: [{ 'no-path': '' }],
},
],

filesPath: function() {
let filesDirectory = 'files';
let dependencies = this.project.dependencies();

if ('@glimmer/component' in dependencies) {
filesDirectory = 'glimmer-files';
}

return path.join(this.path, filesDirectory);
},

fileMapTokens: function() {
return {
__path__: function(options) {
if (options.pod) {
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
} else {
return 'components';
}
},
__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;
},
};
},

normalizeEntityName: function(entityName) {
return normalizeEntityName(entityName);
},

locals: function(options) {
let templatePath = '';
let importTemplate = '';
let contents = '';

let classifiedModuleName = stringUtil.dasherize(options.entity.name);

// if we're in an addon, build import statement
if (options.project.isEmberCLIAddon() || (options.inRepoAddon && !options.inDummy)) {
if (options.pod) {
templatePath = './template';
} else {
templatePath =
pathUtil.getRelativeParentPath(options.entity.name) +
'templates/components/' +
classifiedModuleName;
}
importTemplate = '// @ts-ignore: Ignore import of compiled template' + EOL + 'import layout from \'' + templatePath + '\';' + EOL;
contents = EOL + ' layout = layout;';
}

return {
importTemplate: importTemplate,
contents: contents,
path: getPathOption(options),
classifiedModuleName
};
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('<%= friendlyTestName %>', function() {

this.render(hbs`{{<%= dasherizedModuleName %> inputValue}}`);

expect(this.$().text().trim()).to.equal('1234');
expect(this.element.text().trim()).to.equal('1234');
});
});
<% } else if (testType == 'unit') { %>import { describe, it } from 'mocha';
Expand Down
1 change: 1 addition & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this, please!

12 changes: 6 additions & 6 deletions lib/utilities/update-paths-for-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = function(paths, addonName, appName, options) {
appStarPaths = paths[appNameStar] = paths[appNameStar] || [];

if (options.removePaths) {
if (paths.hasOwnProperty(addonName)) {
if (Object.prototype.hasOwnProperty.call(paths, addonName)) {
delete paths[addonName];
}
if (paths.hasOwnProperty(addonNameStar)) {
if (Object.prototype.hasOwnProperty.call(paths, addonNameStar)) {
delete paths[addonNameStar]
}
let addonAppPathIndex = appStarPaths.indexOf([addonAppPath, '*'].join('/'));
Expand All @@ -26,16 +26,16 @@ module.exports = function(paths, addonName, appName, options) {
paths[appNameStar] = appStarPaths;
}
} else {
if (!paths.hasOwnProperty(addonName)) {
if (!Object.prototype.hasOwnProperty.call(paths, addonName)) {
paths[addonName] = [ addonAddonPath ];
}
if (!paths.hasOwnProperty(addonNameStar)) {
if (!Object.prototype.hasOwnProperty.call(paths, addonNameStar)) {
paths[addonNameStar] = [ [addonAddonPath, '*'].join('/') ];
}
if (!paths.hasOwnProperty(addonTestSupportPath)) {
if (!Object.prototype.hasOwnProperty.call(paths, addonTestSupportPath)) {
paths[addonTestSupportPath] = [ [addonPath, 'addon-test-support'].join('/') ];
}
if (!paths.hasOwnProperty(addonTestSupportStarPath)) {
if (!Object.prototype.hasOwnProperty.call(paths, addonTestSupportStarPath)) {
paths[addonTestSupportStarPath] = [ [addonPath, 'addon-test-support', '*'].join('/') ];
}
if (appStarPaths.indexOf(addonAppPath) === -1) {
Expand Down
Loading