Skip to content

Commit 733f027

Browse files
committed
Merge branch 'canary' into pr/481
Conflicts: app/templates/server/api/user(auth)/user.model.spec.js
2 parents 6aecdf7 + 4859cc1 commit 733f027

19 files changed

+778
-117
lines changed

Diff for: app/templates/Gruntfile.js

+95-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module.exports = function (grunt) {
1717
cdnify: 'grunt-google-cdn',
1818
protractor: 'grunt-protractor-runner',
1919
injector: 'grunt-asset-injector',
20-
buildcontrol: 'grunt-build-control'
20+
buildcontrol: 'grunt-build-control',
21+
istanbul_check_coverage: 'grunt-mocha-istanbul'
2122
});
2223

2324
// Time how long tasks take. Can help when optimizing build times
@@ -169,14 +170,14 @@ module.exports = function (grunt) {
169170
},
170171
src: [
171172
'server/**/*.js',
172-
'!server/**/*.spec.js'
173+
'!server/**/*.{spec,e2e}.js'
173174
]
174175
},
175176
serverTest: {
176177
options: {
177178
jshintrc: 'server/.jshintrc-spec'
178179
},
179-
src: ['server/**/*.spec.js']
180+
src: ['server/**/*.{spec,e2e}.js']
180181
},
181182
all: [
182183
'<%%= yeoman.client %>/{app,components}/**/*.js',
@@ -486,9 +487,60 @@ module.exports = function (grunt) {
486487

487488
mochaTest: {
488489
options: {
489-
reporter: 'spec'
490+
reporter: 'spec',
491+
require: 'mocha.conf.js'
490492
},
491-
src: ['server/**/*.spec.js']
493+
unit: {
494+
src: ['server/**/*.spec.js']
495+
},
496+
e2e: {
497+
src: ['server/**/*.e2e.js']
498+
}
499+
},
500+
501+
mocha_istanbul: {
502+
unit: {
503+
options: {
504+
excludes: [
505+
'**/*.spec.js',
506+
'**/*.mock.js',
507+
'**/*.e2e.js'
508+
],
509+
reporter: 'spec',
510+
require: ['mocha.conf.js'],
511+
mask: '**/*.spec.js',
512+
coverageFolder: 'coverage/server/unit'
513+
},
514+
src: 'server'
515+
},
516+
e2e: {
517+
options: {
518+
excludes: [
519+
'**/*.spec.js',
520+
'**/*.mock.js',
521+
'**/*.e2e.js'
522+
],
523+
reporter: 'spec',
524+
require: ['mocha.conf.js'],
525+
mask: '**/*.e2e.js',
526+
coverageFolder: 'coverage/server/e2e'
527+
},
528+
src: 'server'
529+
}
530+
},
531+
532+
istanbul_check_coverage: {
533+
default: {
534+
options: {
535+
coverageFolder: 'coverage/**',
536+
check: {
537+
lines: 80,
538+
statements: 80,
539+
branches: 80,
540+
functions: 80
541+
}
542+
}
543+
}
492544
},
493545

494546
protractor: {
@@ -764,12 +816,13 @@ module.exports = function (grunt) {
764816
grunt.task.run(['serve']);
765817
});
766818

767-
grunt.registerTask('test', function(target) {
819+
grunt.registerTask('test', function(target, option) {
768820
if (target === 'server') {
769821
return grunt.task.run([
770822
'env:all',
771823
'env:test',
772-
'mochaTest'
824+
'mochaTest:unit',
825+
'mochaTest:e2e'
773826
]);
774827
}
775828

@@ -804,6 +857,41 @@ module.exports = function (grunt) {
804857
]);
805858
}
806859

860+
else if (target === 'coverage') {
861+
862+
if (option === 'unit') {
863+
return grunt.task.run([
864+
'env:all',
865+
'env:test',
866+
'mocha_istanbul:unit'
867+
]);
868+
}
869+
870+
else if (option === 'e2e') {
871+
return grunt.task.run([
872+
'env:all',
873+
'env:test',
874+
'mocha_istanbul:e2e'
875+
]);
876+
}
877+
878+
else if (option === 'check') {
879+
return grunt.task.run([
880+
'istanbul_check_coverage'
881+
]);
882+
}
883+
884+
else {
885+
return grunt.task.run([
886+
'env:all',
887+
'env:test',
888+
'mocha_istanbul',
889+
'istanbul_check_coverage'
890+
]);
891+
}
892+
893+
}
894+
807895
else grunt.task.run([
808896
'test:server',
809897
'test:client'

Diff for: app/templates/_package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"socketio-jwt": "^2.0.2"<% } %>
3131
},
3232
"devDependencies": {
33+
"chai-as-promised": "^4.1.1",
3334
"grunt": "~0.4.4",
3435
"grunt-autoprefixer": "~0.7.2",
3536
"grunt-wiredep": "~1.8.0",
@@ -61,7 +62,8 @@
6162
"grunt-asset-injector": "^0.1.0",
6263
"grunt-karma": "~0.8.2",
6364
"grunt-build-control": "DaftMonk/grunt-build-control",
64-
"grunt-mocha-test": "~0.10.2",<% if(filters.sass) { %>
65+
"grunt-mocha-test": "~0.10.2",
66+
"grunt-mocha-istanbul": "^2.0.0",<% if(filters.sass) { %>
6567
"grunt-contrib-sass": "^0.7.3",<% } %><% if(filters.stylus) { %>
6668
"grunt-contrib-stylus": "latest",<% } %>
6769
"jit-grunt": "^0.5.0",
@@ -85,8 +87,9 @@
8587
"karma-phantomjs-launcher": "~0.1.4",
8688
"karma": "~0.12.9",
8789
"karma-ng-html2js-preprocessor": "~0.1.0",
90+
"proxyquire": "^1.0.1",
8891
"supertest": "~0.11.0",
89-
"should": "~3.3.1"
92+
"sinon-chai": "^2.5.0"
9093
},
9194
"engines": {
9295
"node": ">=0.10.0"

Diff for: app/templates/mocha.conf.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
3+
var chai = require('chai');
4+
var sinon = require('sinon');
5+
var sinonChai = require('sinon-chai');
6+
var chaiAsPromised = require('chai-as-promised');
7+
8+
global.expect = chai.expect;
9+
global.assert = chai.assert;
10+
global.sinon = sinon;
11+
12+
chai.should();
13+
chai.use(sinonChai);
14+
chai.use(chaiAsPromised);

Diff for: app/templates/server/.jshintrc-spec

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"before": true,
77
"beforeEach": true,
88
"after": true,
9-
"afterEach": true
9+
"afterEach": true,
10+
"expect": true,
11+
"assert": true,
12+
"sinon": true
1013
}
1114
}

Diff for: app/templates/server/api/thing/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ router.put('/:id', controller.update);
1212
router.patch('/:id', controller.update);
1313
router.delete('/:id', controller.destroy);<% } %>
1414

15-
module.exports = router;
15+
module.exports = router;

Diff for: app/templates/server/api/thing/index.spec.js

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
'use strict';
2+
3+
var proxyquire = require('proxyquire').noPreserveCache();
4+
5+
/* thing.controller stub */
6+
var thingCtrl = {
7+
index: 'thingCtrl.index'<% if(filters.mongoose) { %>,
8+
show: 'thingCtrl.show',
9+
create: 'thingCtrl.create',
10+
update: 'thingCtrl.update',
11+
destroy: 'thingCtrl.destroy'<% } %>
12+
},
13+
/* express.Router().router stub */
14+
router = {
15+
get: sinon.spy()<% if(filters.mongoose) { %>,
16+
put: sinon.spy(),
17+
patch: sinon.spy(),
18+
post: sinon.spy(),
19+
delete: sinon.spy()<% } %>
20+
},
21+
/* stubbed thing router */
22+
index = proxyquire('./index.js', {
23+
'express': {
24+
Router: function() {
25+
return router;
26+
}
27+
},
28+
'./thing.controller': thingCtrl
29+
});
30+
31+
describe('Thing API Router:', function() {
32+
33+
it('should return an express router instance', function() {
34+
index.should.equal(router);
35+
});
36+
37+
describe('GET /api/things', function() {
38+
39+
it('should route to thing.controller.index', function() {
40+
return router.get.withArgs('/', 'thingCtrl.index').should.have.been.calledOnce;
41+
});
42+
43+
});<% if(filters.mongoose) { %>
44+
45+
describe('GET /api/things/:id', function() {
46+
47+
it('should route to thing.controller.show', function() {
48+
return router.get.withArgs('/:id', 'thingCtrl.show').should.have.been.calledOnce;
49+
});
50+
51+
});
52+
53+
describe('POST /api/things', function() {
54+
55+
it('should route to thing.controller.create', function() {
56+
return router.post.withArgs('/', 'thingCtrl.create').should.have.been.calledOnce;
57+
});
58+
59+
});
60+
61+
describe('PUT /api/things/:id', function() {
62+
63+
it('should route to thing.controller.update', function() {
64+
return router.put.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce;
65+
});
66+
67+
});
68+
69+
describe('PATCH /api/things/:id', function() {
70+
71+
it('should route to thing.controller.update', function() {
72+
return router.patch.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce;
73+
});
74+
75+
});
76+
77+
describe('DELETE /api/things/:id', function() {
78+
79+
it('should route to thing.controller.destroy', function() {
80+
return router.delete.withArgs('/:id', 'thingCtrl.destroy').should.have.been.calledOnce;
81+
});
82+
83+
});<% } %>
84+
85+
});

Diff for: app/templates/server/api/thing/thing.controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ exports.destroy = function(req, res) {
8686

8787
function handleError(res, err) {
8888
return res.send(500, err);
89-
}<% } %>
89+
}<% } %>

0 commit comments

Comments
 (0)