This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
improve component blueprint for octane #218
Open
BryanCrotaz
wants to merge
34
commits into
typed-ember:master
Choose a base branch
from
BryanCrotaz:octane-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 eb10f74
remove unnecessary element definition
BryanCrotaz 6fbeb4e
Update blueprints/component/files/__root__/__path__/__name__.ts
BryanCrotaz 3111707
remove module unification files
BryanCrotaz 6055241
remove ember-cli-shims and add peer dependencies
BryanCrotaz b9e0ad2
use node 12 to build on travis
BryanCrotaz 25f77b0
fix no-prototype-builtins
BryanCrotaz 71a2331
fix typo
BryanCrotaz 8a74fee
add extraneous modules
BryanCrotaz 7bf4065
move extraneous packages to dependencies
BryanCrotaz 48fb02d
fix no-undef
BryanCrotaz ad17126
run with node 12 on appveyor
BryanCrotaz bb3bd3f
remove comment
BryanCrotaz 018efdc
Merge branch master into octane-3
BryanCrotaz eedab5d
tidy up
BryanCrotaz 1931c0a
Merge remote-tracking branch 'upstream/master' into octane-3
BryanCrotaz c1b73fb
yarn lock clean up
BryanCrotaz 71dae68
remove jquery from generated tests
BryanCrotaz 5123288
use ember-cli-htmlbars for testing this addon
BryanCrotaz 83bbd00
Update node-tests/fixtures/component/component-nested.ts
BryanCrotaz e59a57f
Update node-tests/fixtures/component/component.ts
BryanCrotaz f4c3748
Update node-tests/fixtures/component/component-addon.ts
BryanCrotaz cead5d8
Update node-tests/fixtures/component/component-addon-nested.ts
BryanCrotaz cf0761b
clean up fixtures
BryanCrotaz 5682b8c
fix linting and clean packages
BryanCrotaz 7569313
remove unit tests for components
BryanCrotaz 38ee3cd
update fixtures to remove unit tests
BryanCrotaz 5b262cd
remove tests for unit testing components
BryanCrotaz 4fe2936
fix helper test import of hbs
BryanCrotaz 7f3d40c
use correct component name in tests
BryanCrotaz d7c98e4
generate correct component name
BryanCrotaz fd0febb
correct the component name creation
BryanCrotaz a878d30
fix component name generation
BryanCrotaz c0a09b9
bring in default blueprints from ember.js
BryanCrotaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/* eslint-env node */ | ||
module.exports = { | ||
root: true, | ||
parserOptions: { | ||
|
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,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, | ||
}; | ||
} | ||
}); |
34 changes: 34 additions & 0 deletions
34
blueprints/component-test/mocha-files/__root__/__testType__/__path__/__test__.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,34 @@ | ||
import { expect } from 'chai'; | ||
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;<% } %> | ||
}); | ||
} | ||
); |
40 changes: 40 additions & 0 deletions
40
blueprints/component-test/qunit-files/__root__/__testType__/__path__/__test__.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,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); | ||
}); | ||
}); | ||
<% } > |
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,4 @@ | ||
import Component from '@ember/component'; | ||
<%= importTemplate %> | ||
export default class <%= classifiedModuleName %> extends Component { | ||
BryanCrotaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; |
1 change: 1 addition & 0 deletions
1
blueprints/component/files/__root__/__templatepath__/__templatename__.hbs
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 @@ | ||
{{yield}} |
1 change: 1 addition & 0 deletions
1
blueprints/component/glimmer-files/__root__/__path__/__name__.hbs
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 @@ | ||
{{yield}} |
7 changes: 7 additions & 0 deletions
7
blueprints/component/glimmer-files/__root__/__path__/__name__.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,7 @@ | ||
import Component from '@glimmer/component'; | ||
|
||
interface <%= classifiedModuleName %>Args { | ||
} | ||
|
||
export default class <%= classifiedModuleName %> extends Component<<%= classifiedModuleName %>Args> { | ||
}; |
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,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 | ||
}; | ||
}, | ||
}; |
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 @@ | ||
{"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove this, please! |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!).