Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 92 additions & 5 deletions app/templates/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ module.exports = function (grunt) {
},
src: [
'server/**/*.js',
'!server/**/*.spec.js'
'!server/**/*.{spec,e2e}.js'
]
},
serverTest: {
options: {
jshintrc: 'server/.jshintrc-spec'
},
src: ['server/**/*.spec.js']
src: ['server/**/*.{spec,e2e}.js']
},
all: [
'<%%= yeoman.client %>/{app,components}/**/*.js',
Expand Down Expand Up @@ -486,9 +486,60 @@ module.exports = function (grunt) {

mochaTest: {
options: {
reporter: 'spec'
reporter: 'spec',
require: 'mocha.conf.js'
},
src: ['server/**/*.spec.js']
unit: {
src: ['server/**/*.spec.js']
},
e2e: {
src: ['server/**/*.e2e.js']
}
},

mocha_istanbul: {
unit: {
options: {
excludes: [
'**/*.spec.js',
'**/*.mock.js',
'**/*.e2e.js'
],
reporter: 'spec',
require: ['mocha.conf.js'],
mask: '**/*.spec.js',
coverageFolder: 'coverage/unit'
},
src: 'server'
},
e2e: {
options: {
excludes: [
'**/*.spec.js',
'**/*.mock.js',
'**/*.e2e.js'
],
reporter: 'spec',
require: ['mocha.conf.js'],
mask: '**/*.e2e.js',
coverageFolder: 'coverage/e2e'
},
src: 'server'
}
},

istanbul_check_coverage: {
default: {
options: {
coverageFolder: 'coverage/*',
check: {
lines: 80,
statements: 80,
branches: 80,
functions: 80
}
}
}
},

protractor: {
Expand Down Expand Up @@ -769,7 +820,8 @@ module.exports = function (grunt) {
return grunt.task.run([
'env:all',
'env:test',
'mochaTest'
'mochaTest:unit',
'mochaTest:e2e'
]);
}

Expand Down Expand Up @@ -804,6 +856,41 @@ module.exports = function (grunt) {
]);
}

else if (target === 'coverage') {

if (option === 'unit') {
return grunt.task.run([
'env:all',
'env:test',
'mocha_istanbul:unit'
]);
}

else if (option === 'e2e') {
return grunt.task.run([
'env:all',
'env:test',
'mocha_istanbul:e2e'
]);
}

else if (option === 'check') {
return grunt.task.run([
'istanbul_check_coverage'
]);
}

else {
return grunt.task.run([
'env:all',
'env:test',
'mocha_istanbul',
'istanbul_check_coverage'
]);
}

}

else grunt.task.run([
'test:server',
'test:client'
Expand Down
7 changes: 5 additions & 2 deletions app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"socketio-jwt": "^2.0.2"<% } %>
},
"devDependencies": {
"chai-as-promised": "^4.1.1",
"grunt": "~0.4.4",
"grunt-autoprefixer": "~0.7.2",
"grunt-wiredep": "~1.8.0",
Expand Down Expand Up @@ -61,7 +62,8 @@
"grunt-asset-injector": "^0.1.0",
"grunt-karma": "~0.8.2",
"grunt-build-control": "DaftMonk/grunt-build-control",
"grunt-mocha-test": "~0.10.2",<% if(filters.sass) { %>
"grunt-mocha-test": "~0.10.2",
"grunt-mocha-istanbul": "^2.0.0",<% if(filters.sass) { %>
"grunt-contrib-sass": "^0.7.3",<% } %><% if(filters.stylus) { %>
"grunt-contrib-stylus": "latest",<% } %>
"jit-grunt": "^0.5.0",
Expand All @@ -85,8 +87,9 @@
"karma-phantomjs-launcher": "~0.1.4",
"karma": "~0.12.9",
"karma-ng-html2js-preprocessor": "~0.1.0",
"proxyquire": "^1.0.1",
"supertest": "~0.11.0",
"should": "~3.3.1"
"sinon-chai": "^2.5.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down
14 changes: 14 additions & 0 deletions app/templates/mocha.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
var chaiAsPromised = require('chai-as-promised');

global.expect = chai.expect;
global.assert = chai.assert;
global.sinon = sinon;

chai.should();
chai.use(sinonChai);
chai.use(chaiAsPromised);
5 changes: 4 additions & 1 deletion app/templates/server/.jshintrc-spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true
"afterEach": true,
"expect": true,
"assert": true,
"sinon": true
}
}
2 changes: 1 addition & 1 deletion app/templates/server/api/thing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ router.put('/:id', controller.update);
router.patch('/:id', controller.update);
router.delete('/:id', controller.destroy);<% } %>

module.exports = router;
module.exports = router;
85 changes: 85 additions & 0 deletions app/templates/server/api/thing/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
'use strict';

var proxyquire = require('proxyquire').noPreserveCache();

/* thing.controller stub */
var thingCtrl = {
index: 'thingCtrl.index'<% if(filters.mongoose) { %>,
show: 'thingCtrl.show',
create: 'thingCtrl.create',
update: 'thingCtrl.update',
destroy: 'thingCtrl.destroy'<% } %>
},
/* express.Router().router stub */
router = {
get: sinon.spy()<% if(filters.mongoose) { %>,
put: sinon.spy(),
patch: sinon.spy(),
post: sinon.spy(),
delete: sinon.spy()<% } %>
},
/* stubbed thing router */
index = proxyquire('./index.js', {
'express': {
Router: function() {
return router;
}
},
'./thing.controller': thingCtrl
});

describe('Thing API Router:', function() {

it('should return an express router instance', function() {
index.should.equal(router);
});

describe('GET /api/things', function() {

it('should route to thing.controller.index', function() {
return router.get.withArgs('/', 'thingCtrl.index').should.have.been.calledOnce;
});

});<% if(filters.mongoose) { %>

describe('GET /api/things/:id', function() {

it('should route to thing.controller.show', function() {
return router.get.withArgs('/:id', 'thingCtrl.show').should.have.been.calledOnce;
});

});

describe('POST /api/things', function() {

it('should route to thing.controller.create', function() {
return router.post.withArgs('/', 'thingCtrl.create').should.have.been.calledOnce;
});

});

describe('PUT /api/things/:id', function() {

it('should route to thing.controller.update', function() {
return router.put.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce;
});

});

describe('PATCH /api/things/:id', function() {

it('should route to thing.controller.update', function() {
return router.patch.withArgs('/:id', 'thingCtrl.update').should.have.been.calledOnce;
});

});

describe('DELETE /api/things/:id', function() {

it('should route to thing.controller.destroy', function() {
return router.delete.withArgs('/:id', 'thingCtrl.destroy').should.have.been.calledOnce;
});

});<% } %>

});
2 changes: 1 addition & 1 deletion app/templates/server/api/thing/thing.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ exports.destroy = function(req, res) {

function handleError(res, err) {
return res.send(500, err);
}<% } %>
}<% } %>
Loading