Skip to content

Commit 058ea18

Browse files
committed
Add --type option for unit and integration tests
1 parent da73bca commit 058ea18

File tree

20 files changed

+152
-61
lines changed

20 files changed

+152
-61
lines changed

blueprints/feature-index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
'use strict';
22

3+
const annotationMap = {
4+
acceptance: '@application',
5+
integration: '@rendering',
6+
unit: '@context'
7+
};
8+
39
module.exports = {
410
description: 'Adds a feature to the project',
11+
availableOptions: [
12+
{ name: 'type', type: String, aliases: ['t'], default: 'acceptance' },
13+
],
514

615
locals(options) {
716
return {
@@ -18,7 +27,9 @@ module.exports = {
1827
return './';
1928
}
2029
return (path + '/').replace(/.+?\//g, '../');
21-
}())
30+
}()),
31+
type: options.type,
32+
annotation: annotationMap[options.type] || ''
2233
};
2334
},
2435

@@ -32,6 +43,9 @@ module.exports = {
3243
return {
3344
__folder__: function(options) {
3445
return options.locals.folder;
46+
},
47+
__type__: function(options) {
48+
return options.locals.type;
3549
}
3650
};
3751
}

blueprints/feature-unit-index.js

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import yadda from '../../helpers/yadda';
2+
import { expect } from 'chai';
3+
4+
export default function() {
5+
return yadda.localisation.English.library()
6+
.given('I type "Ember g feature make-feature"', function(){
7+
expect(true, this.step).to.be.true;
8+
})
9+
.when('I look in the folder', function(){
10+
expect(true, this.step).to.be.true;
11+
});
12+
}

blueprints/mocha/feature/files/tests/acceptance/__folder__/__name__.feature renamed to blueprints/mocha/feature/files/tests/__type__/__folder__/__name__.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@application
1+
<%= annotation %>
22
Feature: <%= featureName %>
33

44
Scenario: the one where I type ember g feature
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import yadda from '../../helpers/yadda';
2+
3+
export default function(assert) {
4+
return yadda.localisation.English.library()
5+
.given('I type "Ember g feature make-feature"', function(){
6+
assert.ok(true, this.step);
7+
})
8+
.when('I look in the folder', function(){
9+
assert.ok(true, this.step);
10+
});
11+
}

blueprints/qunit/feature-unit/files/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

blueprints/qunit/feature-unit/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

blueprints/qunit/feature/files/tests/acceptance/__folder__/__name__.feature renamed to blueprints/qunit/feature/files/tests/__type__/__folder__/__name__.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@application
1+
<%= annotation %>
22
Feature: <%= featureName %>
33

44
Scenario: the one where I type ember g feature

node-tests/blueprints/feature-test.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,25 @@ const expect = require('ember-cli-blueprint-test-helpers/chai').expect;
1010

1111
const fixture = require('../helpers/fixture');
1212

13+
const testTypes = [
14+
'acceptance',
15+
'integration',
16+
'unit',
17+
];
18+
19+
const frameworkTypes = [
20+
'qunit',
21+
'mocha'
22+
];
23+
1324
describe('Acceptance: ember generate and destroy feature', function() {
1425
setupTestHooks(this);
1526

1627
beforeEach(function() {
1728
return emberNew();
1829
});
1930

20-
[
21-
'qunit',
22-
'mocha'
23-
].forEach((testFramework) => {
31+
frameworkTypes.forEach((testFramework) => {
2432

2533
describe(testFramework, function() {
2634

@@ -33,15 +41,27 @@ describe('Acceptance: ember generate and destroy feature', function() {
3341
});
3442
}
3543

36-
it('feature foo', function() {
44+
it('ember g feature foo', function() {
3745
let args = ['feature', 'foo'];
3846

39-
// pass any additional command line options in the arguments array
4047
return emberGenerateDestroy(args, (file) => {
4148
expect(file('tests/acceptance/foo.feature')).to.equal(fixture('acceptance/foo.feature'));
4249
expect(file('tests/acceptance/steps/foo-steps.js')).to.equal(fixture(`acceptance/${testFramework}/foo-steps.js`));
4350
});
4451
});
52+
53+
testTypes.forEach((type) => {
54+
55+
it(`ember g feature foo --type=${type}`, function() {
56+
let args = ['feature', 'foo', `--type=${type}`];
57+
58+
return emberGenerateDestroy(args, (file) => {
59+
expect(file(`tests/${type}/foo.feature`)).to.equal(fixture(`${type}/foo.feature`));
60+
expect(file(`tests/${type}/steps/foo-steps.js`)).to.equal(fixture(`${type}/${testFramework}/foo-steps.js`));
61+
});
62+
});
63+
64+
});
4565
});
4666
});
4767
});

node-tests/blueprints/main-test.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,25 @@ const file = chai.file;
1212

1313
const fixture = require('../helpers/fixture');
1414

15+
const testTypes = [
16+
'acceptance',
17+
'integration',
18+
'unit',
19+
];
20+
21+
const frameworkTypes = [
22+
'qunit',
23+
'mocha'
24+
];
25+
1526
describe('Acceptance: ember generate ember-cli-yadda', function() {
1627
setupTestHooks(this);
1728

1829
beforeEach(function() {
1930
return emberNew();
2031
});
2132

22-
[
23-
'qunit',
24-
'mocha'
25-
].forEach((testFramework) => {
33+
frameworkTypes.forEach((testFramework) => {
2634

2735
describe(testFramework, function() {
2836

@@ -41,9 +49,9 @@ describe('Acceptance: ember generate ember-cli-yadda', function() {
4149
let fixtureFiles = [
4250
'helpers/yadda.js',
4351
'helpers/yadda-annotations.js',
44-
// 'unit/steps/steps.js',
45-
'acceptance/steps/steps.js',
46-
];
52+
].concat(
53+
testTypes.map((type) => `${type}/steps/steps.js`)
54+
);
4755

4856
return emberGenerate(args)
4957
.then(() => fixtureFiles.forEach((fileName) => expect(file(`tests/${fileName}`)).to.equal(fixture(`main/${testFramework}/${fileName}`))));
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Feature: <%= featureName %>
1+
@rendering
2+
Feature: foo
23

34
Scenario: the one where I type ember g feature
45

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import steps from './steps';
2+
import { expect } from 'chai';
3+
4+
// step definitions that are shared between features should be moved to the
5+
// tests/acceptance/steps/steps.js file
6+
7+
export default function() {
8+
return steps()
9+
.then('I should find a file', function() {
10+
expect(true, this.step).to.be.true;
11+
});
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import steps from '<%= foldersUp %>steps';
1+
import steps from './steps';
22

33
// step definitions that are shared between features should be moved to the
4-
// tests/unit/steps/steps.js file
4+
// tests/acceptance/steps/steps.js file
55

66
export default function(assert) {
77
return steps(assert)
8-
.then('I should find a file', function(next){
8+
.then('I should find a file', function() {
99
assert.ok(true, this.step);
10-
next();
1110
});
1211
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import yadda from '../../helpers/yadda';
2+
import { expect } from 'chai';
3+
4+
export default function() {
5+
return yadda.localisation.English.library()
6+
.given('I type "Ember g feature make-feature"', function(){
7+
expect(true, this.step).to.be.true;
8+
})
9+
.when('I look in the folder', function(){
10+
expect(true, this.step).to.be.true;
11+
});
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import yadda from '../../helpers/yadda';
2+
3+
export default function(assert) {
4+
return yadda.localisation.English.library()
5+
.given('I type "Ember g feature make-feature"', function(){
6+
assert.ok(true, this.step);
7+
})
8+
.when('I look in the folder', function(){
9+
assert.ok(true, this.step);
10+
});
11+
}

node-tests/fixtures/unit/foo.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@context
2+
Feature: foo
3+
4+
Scenario: the one where I type ember g feature
5+
6+
Given I type "Ember g feature make-feature"
7+
When I look in the folder
8+
Then I should find a file
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import steps from './steps';
2+
import { expect } from 'chai';
3+
4+
// step definitions that are shared between features should be moved to the
5+
// tests/acceptance/steps/steps.js file
6+
7+
export default function() {
8+
return steps()
9+
.then('I should find a file', function() {
10+
expect(true, this.step).to.be.true;
11+
});
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import steps from './steps';
2+
3+
// step definitions that are shared between features should be moved to the
4+
// tests/acceptance/steps/steps.js file
5+
6+
export default function(assert) {
7+
return steps(assert)
8+
.then('I should find a file', function() {
9+
assert.ok(true, this.step);
10+
});
11+
}

0 commit comments

Comments
 (0)