Skip to content

Commit d70afb0

Browse files
Turbo87bmac
authored andcommitted
[BUGFIX beta] Add test blueprints from "ember-cli-mocha"
The filesPath() method will automatically figure out if "qunit" or "mocha" files should be used by looking at the project packages. (cherry picked from commit 7dc3218)
1 parent ae12e05 commit d70afb0

File tree

14 files changed

+125
-13
lines changed

14 files changed

+125
-13
lines changed

blueprints/adapter-test/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/*jshint node:true*/
22

33
var testInfo = require('ember-cli-test-info');
4+
var useTestFrameworkDetector = require('../test-framework-detector');
45

5-
module.exports = {
6+
module.exports = useTestFrameworkDetector({
67
description: 'Generates an ember-data adapter unit test',
8+
79
locals: function(options) {
810
return {
911
friendlyTestDescription: testInfo.description(options.entity.name, "Unit", "Adapter")
1012
};
1113
}
12-
};
14+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* jshint expr:true */
2+
import { expect } from 'chai';
3+
import { describeModule, it } from 'ember-mocha';
4+
5+
describeModule(
6+
'adapter:<%= dasherizedModuleName %>',
7+
'<%= friendlyTestDescription %>',
8+
{
9+
// Specify the other units that are required for this test.
10+
// needs: ['serializer:foo']
11+
},
12+
function() {
13+
// Replace this with your real tests.
14+
it('exists', function() {
15+
let adapter = this.subject();
16+
expect(adapter).to.be.ok;
17+
});
18+
}
19+
);

blueprints/model-test/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
var ModelBlueprint = require('../model');
44
var testInfo = require('ember-cli-test-info');
5+
var useTestFrameworkDetector = require('../test-framework-detector');
56

6-
module.exports = {
7+
module.exports = useTestFrameworkDetector({
78
description: 'Generates a model unit test.',
89

910
locals: function(options) {
@@ -13,4 +14,4 @@ module.exports = {
1314

1415
return result;
1516
}
16-
};
17+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* jshint expr:true */
2+
import { expect } from 'chai';
3+
import { describeModel, it } from 'ember-mocha';
4+
5+
describeModel(
6+
'<%= dasherizedModuleName %>',
7+
'<%= friendlyDescription %>',
8+
{
9+
// Specify the other units that are required for this test.
10+
<%= typeof needs !== 'undefined' ? needs : '' %>
11+
},
12+
function() {
13+
// Replace this with your real tests.
14+
it('exists', function() {
15+
let model = this.subject();
16+
// var store = this.store();
17+
expect(model).to.be.ok;
18+
});
19+
}
20+
);

blueprints/serializer-test/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/*jshint node:true*/
22

33
var testInfo = require('ember-cli-test-info');
4+
var useTestFrameworkDetector = require('../test-framework-detector');
45

5-
module.exports = {
6+
module.exports = useTestFrameworkDetector({
67
description: 'Generates a serializer unit test.',
8+
79
locals: function(options) {
810
return {
911
friendlyTestDescription: testInfo.description(options.entity.name, "Unit", "Serializer")
1012
};
11-
},
12-
};
13+
}
14+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* jshint expr:true */
2+
import { expect } from 'chai';
3+
import { describeModel, it } from 'ember-mocha';
4+
5+
describeModel(
6+
'<%= dasherizedModuleName %>',
7+
'<%= friendlyTestDescription %>',
8+
{
9+
// Specify the other units that are required for this test.
10+
needs: ['serializer:<%= dasherizedModuleName %>']
11+
},
12+
function() {
13+
// Replace this with your real tests.
14+
it('serializes records', function() {
15+
let record = this.subject();
16+
17+
let serializedRecord = record.serialize();
18+
19+
expect(serializedRecord).to.be.ok;
20+
});
21+
}
22+
);

blueprints/test-framework-detector.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
var path = require('path');
2+
3+
module.exports = function(blueprint) {
4+
blueprint.supportsAddon = function() {
5+
return false;
6+
};
7+
8+
blueprint.filesPath = function() {
9+
var type;
10+
11+
if ('ember-cli-mocha' in this.project.addonPackages) {
12+
type = 'mocha';
13+
} else if ('ember-cli-qunit' in this.project.addonPackages) {
14+
type = 'qunit';
15+
} else {
16+
this.ui.writeLine('Couldn\'t determine test style - using QUnit');
17+
type = 'qunit';
18+
}
19+
20+
return path.join(this.path, type + '-files');
21+
};
22+
23+
return blueprint;
24+
};

blueprints/transform-test/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/*jshint node:true*/
22

33
var testInfo = require('ember-cli-test-info');
4+
var useTestFrameworkDetector = require('../test-framework-detector');
45

5-
module.exports = {
6+
module.exports = useTestFrameworkDetector({
67
description: 'Generates a transform unit test.',
8+
79
locals: function(options) {
810
return {
911
friendlyTestDescription: testInfo.description(options.entity.name, "Unit", "Transform")
1012
};
11-
},
12-
};
13+
}
14+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* jshint expr:true */
2+
import { expect } from 'chai';
3+
import { describeModule, it } from 'ember-mocha';
4+
5+
describeModule(
6+
'transform:<%= dasherizedModuleName %>',
7+
'<%= friendlyTestDescription %>',
8+
{
9+
// Specify the other units that are required for this test.
10+
// needs: ['transform:foo']
11+
},
12+
function() {
13+
// Replace this with your real tests.
14+
it('exists', function() {
15+
let transform = this.subject();
16+
expect(transform).to.be.ok;
17+
});
18+
}
19+
);

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@
5353
"broccoli-yuidoc": "^2.1.0",
5454
"ember-cli": "1.13.12",
5555
"ember-cli-app-version": "0.5.0",
56-
"ember-cli-blueprint-test-helpers": "^0.6.0",
56+
"ember-cli-blueprint-test-helpers": "^0.8.0",
5757
"ember-cli-content-security-policy": "0.4.0",
5858
"ember-cli-dependency-checker": "^1.0.1",
5959
"ember-cli-htmlbars": "0.7.9",
6060
"ember-cli-htmlbars-inline-precompile": "^0.2.0",
6161
"ember-cli-ic-ajax": "0.2.1",
6262
"ember-cli-inject-live-reload": "^1.3.1",
63-
"ember-cli-internal-test-helpers": "^0.5.0",
63+
"ember-cli-internal-test-helpers": "^0.8.0",
6464
"ember-cli-qunit": "^1.0.0",
6565
"ember-cli-release": "0.2.3",
6666
"ember-cli-uglify": "^1.2.0",
@@ -87,6 +87,7 @@
8787
"configPath": "tests/dummy/config",
8888
"paths": [
8989
"lib/enable-optional-features-via-url"
90-
]
90+
],
91+
"after": "ember-cli-mocha"
9192
}
9293
}

0 commit comments

Comments
 (0)