Skip to content

Commit 04428d3

Browse files
authored
Merge pull request #111 from typed-ember/easy-generators
The rest of the generators
2 parents ea24362 + aac345d commit 04428d3

File tree

117 files changed

+3984
-61
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+3984
-61
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
- EMBER_TRY_SCENARIO=ember-beta
2525
- EMBER_TRY_SCENARIO=ember-canary
2626
- EMBER_TRY_SCENARIO=ember-default
27+
- EMBER_TRY_SCENARIO=integrated-node-tests
2728

2829
matrix:
2930
fast_finish: true
@@ -35,7 +36,6 @@ install:
3536

3637
script:
3738
- yarn lint:js
38-
- yarn ember try:one integrated-node-tests
3939
# Usually, it's ok to finish the test scenario without reverting
4040
# to the addon's original dependency state, skipping "cleanup".
4141
- yarn ember try:one $EMBER_TRY_SCENARIO --skip-cleanup

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"files.exclude": {
3+
"**/.git": true,
4+
"**/.svn": true,
5+
"**/.hg": true,
6+
"**/CVS": true,
7+
"**/.DS_Store": true,
8+
"node_modules": true,
9+
"dist": true,
10+
"tmp": true,
11+
"integrated-node-tests": true,
12+
"ember-lts-2.12": true,
13+
"ember-lts-2.16": true,
14+
"ember-release": true,
15+
"ember-beta": true,
16+
"ember-canary": true,
17+
"ember-default": true
18+
}
19+
}

blueprints/adapter-test/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* eslint-env node */
2+
3+
var testInfo = require('ember-cli-test-info');
4+
var useTestFrameworkDetector = require('../test-framework-detector');
5+
6+
module.exports = useTestFrameworkDetector({
7+
description: 'Generates an ember-data adapter unit test',
8+
9+
locals: function(options) {
10+
return {
11+
friendlyTestDescription: testInfo.description(options.entity.name, "Unit", "Adapter")
12+
};
13+
}
14+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupTest } from 'ember-mocha';
4+
5+
describe('<%= friendlyTestDescription %>', function() {
6+
setupTest('adapter:<%= dasherizedModuleName %>', {
7+
// Specify the other units that are required for this test.
8+
// needs: ['serializer:foo']
9+
});
10+
11+
// Replace this with your real tests.
12+
it('exists', function() {
13+
let adapter = this.subject();
14+
expect(adapter).to.be.ok;
15+
});
16+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { moduleFor, test } from 'ember-qunit';
2+
3+
moduleFor('adapter:<%= dasherizedModuleName %>', '<%= friendlyTestDescription %>', {
4+
// Specify the other units that are required for this test.
5+
// needs: ['serializer:foo']
6+
});
7+
8+
// Replace this with your real tests.
9+
test('it exists', function(assert) {
10+
let adapter = this.subject();
11+
assert.ok(adapter);
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('<%= friendlyTestDescription %>', function(hooks) {
5+
setupTest(hooks);
6+
7+
// Replace this with your real tests.
8+
test('it exists', function(assert) {
9+
let adapter = this.owner.lookup('adapter:<%= dasherizedModuleName %>');
10+
assert.ok(adapter);
11+
});
12+
});

blueprints/adapter/files/__root__/__path__/__name__.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<%= importStatement %>
22

33
export default class <%= classifiedModuleName %> extends <%= baseClass %>.extend({
4-
}) {}
4+
// anything which *must* be merged on the prototype
5+
}) {
6+
// normal class body
7+
}
58

69
// DO NOT DELETE: this is how TypeScript knows how to look up your adapters.
710
declare module 'ember-data' {

blueprints/component-test/index.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const stringUtil = require('ember-cli-string-utils');
5+
const isPackageMissing = require('ember-cli-is-package-missing');
6+
const getPathOption = require('ember-cli-get-component-path-option');
7+
8+
const useTestFrameworkDetector = require('../test-framework-detector');
9+
10+
module.exports = useTestFrameworkDetector({
11+
description: 'Generates a component integration or unit test.',
12+
13+
availableOptions: [
14+
{
15+
name: 'test-type',
16+
type: ['integration', 'unit'],
17+
default: 'integration',
18+
aliases: [
19+
{ 'i': 'integration' },
20+
{ 'u': 'unit' },
21+
{ 'integration': 'integration' },
22+
{ 'unit': 'unit' }
23+
]
24+
}
25+
],
26+
27+
fileMapTokens: function() {
28+
return {
29+
__testType__: function(options) {
30+
return options.locals.testType || 'integration';
31+
},
32+
__path__: function(options) {
33+
if (options.pod) {
34+
return path.join(options.podPath, options.locals.path, options.dasherizedModuleName);
35+
}
36+
return 'components';
37+
}
38+
};
39+
},
40+
locals: function(options) {
41+
let dasherizedModuleName = stringUtil.dasherize(options.entity.name);
42+
let componentPathName = dasherizedModuleName;
43+
let testType = options.testType || 'integration';
44+
45+
let friendlyTestDescription = [
46+
testType === 'unit' ? 'Unit' : 'Integration',
47+
'Component',
48+
dasherizedModuleName,
49+
].join(' | ');
50+
51+
if (options.pod && options.path !== 'components' && options.path !== '') {
52+
componentPathName = [options.path, dasherizedModuleName].filter(Boolean).join('/');
53+
}
54+
55+
return {
56+
path: getPathOption(options),
57+
testType: testType,
58+
componentPathName: componentPathName,
59+
friendlyTestDescription: friendlyTestDescription
60+
};
61+
},
62+
afterInstall: function(options) {
63+
if (!options.dryRun && options.testType === 'integration' && isPackageMissing(this, 'ember-cli-htmlbars-inline-precompile')) {
64+
return this.addPackagesToProject([
65+
{ name: 'ember-cli-htmlbars-inline-precompile', target: '^0.3.1' }
66+
]);
67+
}
68+
}
69+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import { setupComponentTest } from 'ember-mocha';<% if (testType === 'integration') { %>
4+
import hbs from 'htmlbars-inline-precompile';<% } %>
5+
6+
describe('<%= friendlyTestDescription %>', function() {
7+
setupComponentTest('<%= componentPathName %>', {
8+
<% if (testType === 'integration' ) { %>integration: true<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
9+
// needs: ['component:foo', 'helper:bar'],
10+
unit: true<% } %>
11+
});
12+
13+
it('renders', function() {
14+
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
15+
// Handle any actions with this.on('myAction', function(val) { ... });
16+
// Template block usage:
17+
// this.render(hbs`
18+
// {{#<%= dasherizedModuleName %>}}
19+
// template content
20+
// {{/<%= dasherizedModuleName %>}}
21+
// `);
22+
23+
this.render(hbs`{{<%= dasherizedModuleName %>}}`);
24+
expect(this.$()).to.have.length(1);<% } else if(testType === 'unit') { %>// creates the component instance
25+
let component = this.subject();
26+
// renders the component on the page
27+
this.render();
28+
expect(component).to.be.ok;
29+
expect(this.$()).to.have.length(1);<% } %>
30+
});
31+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from 'chai';
2+
import { describeComponent, it } from 'ember-mocha';<% if (testType === 'integration') { %>
3+
import hbs from 'htmlbars-inline-precompile';<% } %>
4+
5+
describeComponent('<%= componentPathName %>', '<%= friendlyTestDescription %>',
6+
{
7+
<% if (testType === 'integration' ) { %>integration: true<% } else if(testType === 'unit') { %>// Specify the other units that are required for this test
8+
// needs: ['component:foo', 'helper:bar'],
9+
unit: true<% } %>
10+
},
11+
function() {
12+
it('renders', function() {
13+
<% if (testType === 'integration' ) { %>// Set any properties with this.set('myProperty', 'value');
14+
// Handle any actions with this.on('myAction', function(val) { ... });
15+
// Template block usage:
16+
// this.render(hbs`
17+
// {{#<%= dasherizedModuleName %>}}
18+
// template content
19+
// {{/<%= dasherizedModuleName %>}}
20+
// `);
21+
22+
this.render(hbs`{{<%= dasherizedModuleName %>}}`);
23+
expect(this.$()).to.have.length(1);<% } else if(testType === 'unit') { %>// creates the component instance
24+
let component = this.subject();
25+
// renders the component on the page
26+
this.render();
27+
expect(component).to.be.ok;
28+
expect(this.$()).to.have.length(1);<% } %>
29+
});
30+
}
31+
);

0 commit comments

Comments
 (0)