Skip to content

Commit

Permalink
feat(server): added mocha test configuration
Browse files Browse the repository at this point in the history
split grunt test into 3 tasks, grunt test:server, grunt test:client, and grunt test to run both
  • Loading branch information
DaftMonk committed Feb 23, 2014
1 parent 31d6eb9 commit 458a2f6
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
2 changes: 2 additions & 0 deletions app/index.js
Expand Up @@ -109,6 +109,7 @@ var Generator = module.exports = function Generator(args, options) {
this.invoke('karma:app', {
options: {
coffee: this.options.coffee,
testPath: 'test/client',
travis: true,
'skip-install': true,
components: [
Expand Down Expand Up @@ -472,6 +473,7 @@ Generator.prototype.serverFiles = function () {
this.template('../../templates/express/server.js', 'server.js');
this.copy('../../templates/express/jshintrc', 'lib/.jshintrc');
this.template('../../templates/express/controllers/api.js', 'lib/controllers/api.js');
this.template('../../templates/express/test/api/api.js', 'test/server/api/api.js');
this.template('../../templates/express/controllers/index.js', 'lib/controllers/index.js');
this.template('../../templates/express/routes.js', 'lib/routes.js');

Expand Down
38 changes: 32 additions & 6 deletions templates/common/Gruntfile.js
Expand Up @@ -62,6 +62,10 @@ module.exports = function (grunt) {
livereload: true
}
},
mochaTest: {
files: ['test/server/{,*/}*.js'],
tasks: ['mochaTest']
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma']
Expand Down Expand Up @@ -424,6 +428,12 @@ module.exports = function (grunt) {
configFile: 'karma.conf.js',
singleRun: true
}
},
mochaTest: {
options: {
reporter: 'spec'
},
src: ['test/server/**/*.js']
}
});

Expand Down Expand Up @@ -464,12 +474,28 @@ module.exports = function (grunt) {
grunt.task.run(['serve']);
});

grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'karma'
]);
grunt.registerTask('test', function(target) {
if (target === 'server') {
return grunt.task.run(['mochaTest']);
}

if (target === 'client') {
return grunt.task.run([
'clean:server',
'concurrent:test',
'autoprefixer',
'karma'
]);
}

grunt.task.run([
'mochaTest',
'clean:server',
'concurrent:test',
'autoprefixer',
'karma'
]);
});

grunt.registerTask('build', [
'clean:dist',
Expand Down
3 changes: 2 additions & 1 deletion templates/common/_bower.json
Expand Up @@ -16,5 +16,6 @@
"devDependencies": {
"angular-mocks": "1.2.11",
"angular-scenario": "1.2.11"
}
},
"testPath": "test/client/spec"
}
5 changes: 4 additions & 1 deletion templates/common/_package.json
Expand Up @@ -53,7 +53,10 @@
"karma-coffee-preprocessor": "~0.1.2",
"karma-phantomjs-launcher": "~0.1.1",
"karma": "~0.10.9",
"karma-ng-html2js-preprocessor": "~0.1.0"
"karma-ng-html2js-preprocessor": "~0.1.0",
"grunt-mocha-test": "~0.8.1",
"supertest": "~0.8.2",
"should": "~2.1.0"
},
"engines": {
"node": ">=0.10.0"
Expand Down
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions templates/express/test/api/api.js
@@ -0,0 +1,20 @@
'use strict';

var should = require('should'),
app = require('../../../server'),
request = require('supertest');

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

it('should respond with JSON array', function(done) {
request(app)
.get('/api/awesomeThings')
.expect(200)
.expect('Content-Type', /json/)
.end(function(err, res) {
if (err) return done(err);
res.body.should.be.instanceof(Array);
done();
});
});
});

0 comments on commit 458a2f6

Please sign in to comment.