Skip to content

Commit d488153

Browse files
committed
Add mixin, mixin-test generators.
1 parent ba17114 commit d488153

File tree

12 files changed

+376
-0
lines changed

12 files changed

+376
-0
lines changed

blueprints/mixin-test/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
const useTestFrameworkDetector = require('../test-framework-detector');
4+
5+
module.exports = useTestFrameworkDetector({
6+
description: 'Generates a mixin unit test.',
7+
locals: function(options) {
8+
return {
9+
projectName: options.inRepoAddon ? options.inRepoAddon : options.project.name(),
10+
friendlyTestName: ['Unit', 'Mixin', options.entity.name].join(' | ')
11+
};
12+
}
13+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from 'chai';
2+
import { describe, it } from 'mocha';
3+
import EmberObject from '@ember/object';
4+
import <%= classifiedModuleName %>Mixin from '<%= dasherizedPackageName %>/mixins/<%= dasherizedModuleName %>';
5+
6+
describe('<%= friendlyTestName %>', function() {
7+
// Replace this with your real tests.
8+
it('works', function() {
9+
let <%= classifiedModuleName %>Object = EmberObject.extend(<%= classifiedModuleName %>Mixin);
10+
let subject = <%= classifiedModuleName %>Object.create();
11+
expect(subject).to.be.ok;
12+
});
13+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import EmberObject from '@ember/object';
2+
import <%= classifiedModuleName %>Mixin from '<%= projectName %>/mixins/<%= dasherizedModuleName %>';
3+
import { module, test } from 'qunit';
4+
5+
module('<%= friendlyTestName %>');
6+
7+
// Replace this with your real tests.
8+
test('it works', function(assert) {
9+
let <%= classifiedModuleName %>Object = EmberObject.extend(<%= classifiedModuleName %>Mixin);
10+
let subject = <%= classifiedModuleName %>Object.create();
11+
assert.ok(subject);
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import EmberObject from '@ember/object';
2+
import <%= classifiedModuleName %>Mixin from '<%= projectName %>/mixins/<%= dasherizedModuleName %>';
3+
import { module, test } from 'qunit';
4+
5+
module('<%= friendlyTestName %>', function() {
6+
// Replace this with your real tests.
7+
test('it works', function (assert) {
8+
let <%= classifiedModuleName %>Object = EmberObject.extend(<%= classifiedModuleName %>Mixin);
9+
let subject = <%= classifiedModuleName %>Object.create();
10+
assert.ok(subject);
11+
});
12+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Mixin from '@ember/object/mixin';
2+
3+
export default Mixin.create({
4+
});

blueprints/mixin/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
module.exports = {
4+
description: 'Generates a mixin.'
5+
};
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
3+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
4+
const setupTestHooks = blueprintHelpers.setupTestHooks;
5+
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7+
const modifyPackages = blueprintHelpers.modifyPackages;
8+
9+
const chai = require('ember-cli-blueprint-test-helpers/chai');
10+
const expect = chai.expect;
11+
12+
const generateFakePackageManifest = require('../helpers/generate-fake-package-manifest');
13+
const fixture = require('../helpers/fixture');
14+
15+
describe('Blueprint: mixin-test', function() {
16+
setupTestHooks(this);
17+
18+
describe('in app', function() {
19+
beforeEach(function() {
20+
return emberNew();
21+
});
22+
23+
it('mixin-test foo', function() {
24+
return emberGenerateDestroy(['mixin-test', 'foo'], _file => {
25+
expect(_file('tests/unit/mixins/foo-test.ts')).to.equal(fixture('mixin-test/default.ts'));
26+
});
27+
});
28+
29+
describe('with ember-cli-mocha', function() {
30+
beforeEach(function() {
31+
modifyPackages([
32+
{ name: 'ember-cli-qunit', delete: true },
33+
{ name: 'ember-cli-mocha', dev: true },
34+
]);
35+
});
36+
37+
it('mixin-test foo', function() {
38+
return emberGenerateDestroy(['mixin-test', 'foo'], _file => {
39+
expect(_file('tests/unit/mixins/foo-test.ts')).to.equal(fixture('mixin-test/mocha.ts'));
40+
});
41+
});
42+
});
43+
44+
describe('with ember-cli-qunit@4.2.0', function() {
45+
beforeEach(function() {
46+
generateFakePackageManifest('ember-cli-qunit', '4.2.0');
47+
});
48+
49+
it('mixin-test foo', function() {
50+
return emberGenerateDestroy(['mixin-test', 'foo'], _file => {
51+
expect(_file('tests/unit/mixins/foo-test.ts')).to.equal(fixture('mixin-test/rfc232.ts'));
52+
});
53+
});
54+
});
55+
});
56+
57+
describe('in addon', function() {
58+
beforeEach(function() {
59+
return emberNew({ target: 'addon' });
60+
});
61+
62+
it('mixin-test foo', function() {
63+
return emberGenerateDestroy(['mixin-test', 'foo'], _file => {
64+
expect(_file('tests/unit/mixins/foo-test.ts')).to.equal(fixture('mixin-test/addon.ts'));
65+
});
66+
});
67+
});
68+
});
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
'use strict';
2+
3+
const blueprintHelpers = require('ember-cli-blueprint-test-helpers/helpers');
4+
const setupTestHooks = blueprintHelpers.setupTestHooks;
5+
const emberNew = blueprintHelpers.emberNew;
6+
const emberGenerateDestroy = blueprintHelpers.emberGenerateDestroy;
7+
const setupPodConfig = blueprintHelpers.setupPodConfig;
8+
9+
const chai = require('ember-cli-blueprint-test-helpers/chai');
10+
const expect = chai.expect;
11+
12+
describe('Blueprint: mixin', function() {
13+
setupTestHooks(this);
14+
15+
describe('in app', function() {
16+
beforeEach(function() {
17+
return emberNew();
18+
});
19+
20+
it('mixin foo', function() {
21+
return emberGenerateDestroy(['mixin', 'foo'], _file => {
22+
expect(_file('app/mixins/foo.ts'))
23+
.to.contain("import Mixin from '@ember/object/mixin';")
24+
.to.contain('export default Mixin.create({\n});');
25+
26+
expect(_file('tests/unit/mixins/foo-test.ts')).to.contain(
27+
"import FooMixin from 'my-app/mixins/foo';"
28+
);
29+
});
30+
});
31+
32+
it('mixin foo/bar', function() {
33+
return emberGenerateDestroy(['mixin', 'foo/bar'], _file => {
34+
expect(_file('app/mixins/foo/bar.ts'))
35+
.to.contain("import Mixin from '@ember/object/mixin';")
36+
.to.contain('export default Mixin.create({\n});');
37+
38+
expect(_file('tests/unit/mixins/foo/bar-test.ts')).to.contain(
39+
"import FooBarMixin from 'my-app/mixins/foo/bar';"
40+
);
41+
});
42+
});
43+
44+
it('mixin foo/bar/baz', function() {
45+
return emberGenerateDestroy(['mixin', 'foo/bar/baz'], _file => {
46+
expect(_file('tests/unit/mixins/foo/bar/baz-test.ts')).to.contain(
47+
"import FooBarBazMixin from 'my-app/mixins/foo/bar/baz';"
48+
);
49+
});
50+
});
51+
52+
it('mixin foo --pod', function() {
53+
return emberGenerateDestroy(['mixin', 'foo', '--pod'], _file => {
54+
expect(_file('app/mixins/foo.ts'))
55+
.to.contain("import Mixin from '@ember/object/mixin';")
56+
.to.contain('export default Mixin.create({\n});');
57+
58+
expect(_file('tests/unit/mixins/foo-test.ts')).to.contain(
59+
"import FooMixin from 'my-app/mixins/foo';"
60+
);
61+
});
62+
});
63+
64+
it('mixin foo/bar --pod', function() {
65+
return emberGenerateDestroy(['mixin', 'foo/bar', '--pod'], _file => {
66+
expect(_file('app/mixins/foo/bar.ts'))
67+
.to.contain("import Mixin from '@ember/object/mixin';")
68+
.to.contain('export default Mixin.create({\n});');
69+
70+
expect(_file('tests/unit/mixins/foo/bar-test.ts')).to.contain(
71+
"import FooBarMixin from 'my-app/mixins/foo/bar';"
72+
);
73+
});
74+
});
75+
76+
it('mixin foo/bar/baz --pod', function() {
77+
return emberGenerateDestroy(['mixin', 'foo/bar/baz', '--pod'], _file => {
78+
expect(_file('tests/unit/mixins/foo/bar/baz-test.ts')).to.contain(
79+
"import FooBarBazMixin from 'my-app/mixins/foo/bar/baz';"
80+
);
81+
});
82+
});
83+
84+
describe('with podModulePrefix', function() {
85+
beforeEach(function() {
86+
setupPodConfig({ podModulePrefix: true });
87+
});
88+
89+
it('mixin foo --pod', function() {
90+
return emberGenerateDestroy(['mixin', 'foo', '--pod'], _file => {
91+
expect(_file('app/mixins/foo.ts'))
92+
.to.contain("import Mixin from '@ember/object/mixin';")
93+
.to.contain('export default Mixin.create({\n});');
94+
95+
expect(_file('tests/unit/mixins/foo-test.ts')).to.contain(
96+
"import FooMixin from 'my-app/mixins/foo';"
97+
);
98+
});
99+
});
100+
101+
it('mixin foo/bar --pod', function() {
102+
return emberGenerateDestroy(['mixin', 'foo/bar', '--pod'], _file => {
103+
expect(_file('app/mixins/foo/bar.ts'))
104+
.to.contain("import Mixin from '@ember/object/mixin';")
105+
.to.contain('export default Mixin.create({\n});');
106+
107+
expect(_file('tests/unit/mixins/foo/bar-test.ts')).to.contain(
108+
"import FooBarMixin from 'my-app/mixins/foo/bar';"
109+
);
110+
});
111+
});
112+
});
113+
});
114+
115+
describe('in addon', function() {
116+
beforeEach(function() {
117+
return emberNew({ target: 'addon' });
118+
});
119+
120+
it('mixin foo', function() {
121+
return emberGenerateDestroy(['mixin', 'foo'], _file => {
122+
expect(_file('addon/mixins/foo.ts'))
123+
.to.contain("import Mixin from '@ember/object/mixin';")
124+
.to.contain('export default Mixin.create({\n});');
125+
126+
expect(_file('tests/unit/mixins/foo-test.ts')).to.contain(
127+
"import FooMixin from 'my-addon/mixins/foo';"
128+
);
129+
130+
expect(_file('app/mixins/foo.ts')).to.not.exist;
131+
});
132+
});
133+
134+
it('mixin foo/bar', function() {
135+
return emberGenerateDestroy(['mixin', 'foo/bar'], _file => {
136+
expect(_file('addon/mixins/foo/bar.ts'))
137+
.to.contain("import Mixin from '@ember/object/mixin';")
138+
.to.contain('export default Mixin.create({\n});');
139+
140+
expect(_file('tests/unit/mixins/foo/bar-test.ts')).to.contain(
141+
"import FooBarMixin from 'my-addon/mixins/foo/bar';"
142+
);
143+
144+
expect(_file('app/mixins/foo/bar.ts')).to.not.exist;
145+
});
146+
});
147+
148+
it('mixin foo/bar/baz', function() {
149+
return emberGenerateDestroy(['mixin', 'foo/bar/baz'], _file => {
150+
expect(_file('addon/mixins/foo/bar/baz.ts'))
151+
.to.contain("import Mixin from '@ember/object/mixin';")
152+
.to.contain('export default Mixin.create({\n});');
153+
154+
expect(_file('tests/unit/mixins/foo/bar/baz-test.ts')).to.contain(
155+
"import FooBarBazMixin from 'my-addon/mixins/foo/bar/baz';"
156+
);
157+
158+
expect(_file('app/mixins/foo/bar/baz.ts')).to.not.exist;
159+
});
160+
});
161+
});
162+
163+
describe('in in-repo-addon', function() {
164+
beforeEach(function() {
165+
return emberNew({ target: 'in-repo-addon' });
166+
});
167+
168+
it('mixin foo --in-repo-addon=my-addon', function() {
169+
return emberGenerateDestroy(['mixin', 'foo', '--in-repo-addon=my-addon'], _file => {
170+
expect(_file('lib/my-addon/addon/mixins/foo.ts'))
171+
.to.contain("import Mixin from '@ember/object/mixin';")
172+
.to.contain('export default Mixin.create({\n});');
173+
174+
expect(_file('tests/unit/mixins/foo-test.ts')).to.contain(
175+
"import FooMixin from 'my-addon/mixins/foo';"
176+
);
177+
});
178+
});
179+
180+
it('mixin foo/bar --in-repo-addon=my-addon', function() {
181+
return emberGenerateDestroy(['mixin', 'foo/bar', '--in-repo-addon=my-addon'], _file => {
182+
expect(_file('lib/my-addon/addon/mixins/foo/bar.ts'))
183+
.to.contain("import Mixin from '@ember/object/mixin';")
184+
.to.contain('export default Mixin.create({\n});');
185+
186+
expect(_file('tests/unit/mixins/foo/bar-test.ts')).to.contain(
187+
"import FooBarMixin from 'my-addon/mixins/foo/bar';"
188+
);
189+
});
190+
});
191+
192+
it('mixin foo/bar/baz --in-repo-addon=my-addon', function() {
193+
return emberGenerateDestroy(['mixin', 'foo/bar/baz', '--in-repo-addon=my-addon'], _file => {
194+
expect(_file('tests/unit/mixins/foo/bar/baz-test.ts')).to.contain(
195+
"import FooBarBazMixin from 'my-addon/mixins/foo/bar/baz';"
196+
);
197+
});
198+
});
199+
});
200+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import EmberObject from '@ember/object';
2+
import FooMixin from 'my-addon/mixins/foo';
3+
import { module, test } from 'qunit';
4+
5+
module('Unit | Mixin | foo');
6+
7+
// Replace this with your real tests.
8+
test('it works', function(assert) {
9+
let FooObject = EmberObject.extend(FooMixin);
10+
let subject = FooObject.create();
11+
assert.ok(subject);
12+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import EmberObject from '@ember/object';
2+
import FooMixin from 'my-app/mixins/foo';
3+
import { module, test } from 'qunit';
4+
5+
module('Unit | Mixin | foo');
6+
7+
// Replace this with your real tests.
8+
test('it works', function(assert) {
9+
let FooObject = EmberObject.extend(FooMixin);
10+
let subject = FooObject.create();
11+
assert.ok(subject);
12+
});

0 commit comments

Comments
 (0)