-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathindex.js
102 lines (96 loc) · 2.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var EOL = require('os').EOL;
module.exports = {
description: 'Generates an ability unit test.',
_getTestStyle: function () {
if ('ember-cli-mocha' in this.project.addonPackages) {
return 'mocha';
} else if ('ember-cli-qunit' in this.project.addonPackages) {
return 'qunit';
}
},
locals: function (options) {
var name = options.entity.name;
var testStyle = this._getTestStyle();
if (!testStyle) {
this.ui.writeLine("Couldn't determine test style - using QUnit");
testStyle = 'qunit';
}
var imports, test;
if (testStyle === 'qunit') {
imports =
"import { module, test } from 'qunit';" +
EOL +
"import { setupTest } from 'ember-qunit';";
test =
"module('Unit | Ability | " +
name +
"', function(hooks) {" +
EOL +
' setupTest(hooks);' +
EOL +
EOL +
" test('it exists', function(assert) {" +
EOL +
" const ability = this.owner.lookup('ability:" +
name +
"');" +
EOL +
' assert.ok(ability);' +
EOL +
' });' +
EOL +
'});';
} else if (testStyle === 'mocha') {
imports =
'/* jshint expr:true */' +
EOL +
"import { expect } from 'chai';" +
EOL +
'import {' +
EOL +
' describeModule,' +
EOL +
' it' +
EOL +
"} from 'ember-mocha';";
test =
'describeModule(' +
EOL +
" 'ability:" +
name +
"'," +
EOL +
" '" +
name +
" Ability'," +
EOL +
' {' +
EOL +
' // Specify the other units that are required for this test.' +
EOL +
" // needs: ['service:foo']" +
EOL +
' },' +
EOL +
' function() {' +
EOL +
' // Replace this with your real tests.' +
EOL +
" it('exists', function() {" +
EOL +
' const ability = this.subject();' +
EOL +
' expect(ability).to.be.ok;' +
EOL +
' });' +
EOL +
' }' +
EOL +
');';
}
return {
imports: imports,
test: test,
};
},
};