Skip to content

Commit 458a2f6

Browse files
committed
feat(server): added mocha test configuration
split grunt test into 3 tasks, grunt test:server, grunt test:client, and grunt test to run both
1 parent 31d6eb9 commit 458a2f6

File tree

7 files changed

+60
-8
lines changed

7 files changed

+60
-8
lines changed

Diff for: app/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ var Generator = module.exports = function Generator(args, options) {
109109
this.invoke('karma:app', {
110110
options: {
111111
coffee: this.options.coffee,
112+
testPath: 'test/client',
112113
travis: true,
113114
'skip-install': true,
114115
components: [
@@ -472,6 +473,7 @@ Generator.prototype.serverFiles = function () {
472473
this.template('../../templates/express/server.js', 'server.js');
473474
this.copy('../../templates/express/jshintrc', 'lib/.jshintrc');
474475
this.template('../../templates/express/controllers/api.js', 'lib/controllers/api.js');
476+
this.template('../../templates/express/test/api/api.js', 'test/server/api/api.js');
475477
this.template('../../templates/express/controllers/index.js', 'lib/controllers/index.js');
476478
this.template('../../templates/express/routes.js', 'lib/routes.js');
477479

Diff for: templates/common/Gruntfile.js

+32-6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ module.exports = function (grunt) {
6262
livereload: true
6363
}
6464
},
65+
mochaTest: {
66+
files: ['test/server/{,*/}*.js'],
67+
tasks: ['mochaTest']
68+
},
6569
jsTest: {
6670
files: ['test/spec/{,*/}*.js'],
6771
tasks: ['newer:jshint:test', 'karma']
@@ -424,6 +428,12 @@ module.exports = function (grunt) {
424428
configFile: 'karma.conf.js',
425429
singleRun: true
426430
}
431+
},
432+
mochaTest: {
433+
options: {
434+
reporter: 'spec'
435+
},
436+
src: ['test/server/**/*.js']
427437
}
428438
});
429439

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

467-
grunt.registerTask('test', [
468-
'clean:server',
469-
'concurrent:test',
470-
'autoprefixer',
471-
'karma'
472-
]);
477+
grunt.registerTask('test', function(target) {
478+
if (target === 'server') {
479+
return grunt.task.run(['mochaTest']);
480+
}
481+
482+
if (target === 'client') {
483+
return grunt.task.run([
484+
'clean:server',
485+
'concurrent:test',
486+
'autoprefixer',
487+
'karma'
488+
]);
489+
}
490+
491+
grunt.task.run([
492+
'mochaTest',
493+
'clean:server',
494+
'concurrent:test',
495+
'autoprefixer',
496+
'karma'
497+
]);
498+
});
473499

474500
grunt.registerTask('build', [
475501
'clean:dist',

Diff for: templates/common/_bower.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
"devDependencies": {
1717
"angular-mocks": "1.2.11",
1818
"angular-scenario": "1.2.11"
19-
}
19+
},
20+
"testPath": "test/client/spec"
2021
}

Diff for: templates/common/_package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@
5353
"karma-coffee-preprocessor": "~0.1.2",
5454
"karma-phantomjs-launcher": "~0.1.1",
5555
"karma": "~0.10.9",
56-
"karma-ng-html2js-preprocessor": "~0.1.0"
56+
"karma-ng-html2js-preprocessor": "~0.1.0",
57+
"grunt-mocha-test": "~0.8.1",
58+
"supertest": "~0.8.2",
59+
"should": "~2.1.0"
5760
},
5861
"engines": {
5962
"node": ">=0.10.0"
File renamed without changes.

Diff for: templates/express/test/api/api.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
var should = require('should'),
4+
app = require('../../../server'),
5+
request = require('supertest');
6+
7+
describe('GET /api/awesomeThings', function() {
8+
9+
it('should respond with JSON array', function(done) {
10+
request(app)
11+
.get('/api/awesomeThings')
12+
.expect(200)
13+
.expect('Content-Type', /json/)
14+
.end(function(err, res) {
15+
if (err) return done(err);
16+
res.body.should.be.instanceof(Array);
17+
done();
18+
});
19+
});
20+
});

0 commit comments

Comments
 (0)