Skip to content

Commit 1adfc51

Browse files
committed
Refactor karma configs and use grunt-karma
1 parent 0d7ba02 commit 1adfc51

File tree

7 files changed

+78
-93
lines changed

7 files changed

+78
-93
lines changed

Gruntfile.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
var util = require('./test/lib/karma-util.js');
21
module.exports = function(grunt) {
32

43
grunt.loadNpmTasks('grunt-shell');
@@ -7,6 +6,7 @@ module.exports = function(grunt) {
76
grunt.loadNpmTasks('grunt-contrib-uglify');
87
grunt.loadNpmTasks('grunt-contrib-concat');
98
grunt.loadNpmTasks('grunt-contrib-connect');
9+
grunt.loadNpmTasks('grunt-karma');
1010

1111
grunt.initConfig({
1212
shell: {
@@ -17,26 +17,44 @@ module.exports = function(grunt) {
1717
command: 'cp -R components/components-font-awesome/font app/font'
1818
}
1919
},
20+
2021
connect: {
22+
options: {
23+
port: 8000,
24+
base: './app'
25+
},
2126
server: {
2227
options: {
23-
port: 8000,
24-
hostname: '0.0.0.0',
25-
base: './app',
2628
keepalive: true
2729
}
28-
}
29-
},
30-
test: {
31-
unit: './test/karma-unit.conf.js',
32-
midway: './test/karma-midway.conf.js',
33-
e2e: './test/karma-e2e.conf.js'
30+
},
31+
testserver: {}
3432
},
35-
autotest: {
36-
unit: './test/karma-unit.conf.js',
37-
midway: './test/karma-midway.conf.js',
38-
e2e: './test/karma-e2e.conf.js'
33+
34+
karma: {
35+
unit: {
36+
configFile: './test/karma-unit.conf.js',
37+
autoWatch: false,
38+
singleRun: true
39+
},
40+
unit_auto: {
41+
configFile: './test/karma-unit.conf.js'
42+
},
43+
midway: {
44+
configFile: './test/karma-midway.conf.js',
45+
autoWatch: false,
46+
singleRun: true
47+
},
48+
midway_auto: {
49+
configFile: './test/karma-midway.conf.js'
50+
},
51+
e2e: {
52+
configFile: './test/karma-e2e.conf.js',
53+
autoWatch: false,
54+
singleRun: true
55+
}
3956
},
57+
4058
watch: {
4159
scripts: {
4260
files: ['app/scripts/**/*.js','app/styles/**/*.css'],
@@ -46,6 +64,7 @@ module.exports = function(grunt) {
4664
},
4765
},
4866
},
67+
4968
concat: {
5069
styles: {
5170
dest: './app/assets/app.css',
@@ -54,7 +73,7 @@ module.exports = function(grunt) {
5473
'components/components-font-awesome/css/font-awesome.css',
5574
'components/bootstrap.css/css/bootstrap.css',
5675
'app/styles/app.css'
57-
]
76+
]
5877
},
5978
scripts: {
6079
options: {
@@ -76,13 +95,8 @@ module.exports = function(grunt) {
7695
}
7796
});
7897

79-
grunt.registerMultiTask('test', 'Run and watch the unit tests with Karma', function() {
80-
util.startKarma.call(util, this.data, true, this.async());
81-
});
82-
83-
grunt.registerMultiTask('autotest', 'Run and watch the unit tests with Karma', function(){
84-
util.startKarma.call(util, this.data, false, this.async());
85-
});
98+
grunt.registerTask('test:e2e', ['connect:testserver', 'karma:e2e']);
99+
grunt.registerTask('test', ['karma:unit', 'karma:midway', 'test:e2e']);
86100

87101
//installation-related
88102
grunt.registerTask('install', ['shell:install','shell:font_awesome_fonts']);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
"grunt-contrib-watch": "~0.4.4",
1616
"grunt-shell": "~0.2.2",
1717
"grunt-contrib-copy": "~0.4.1",
18+
"grunt-karma": "git://github.com/karma-runner/grunt-karma.git#karma-v0.10",
1819
"bower": "~0.9.2",
19-
"karma": "0.9.3",
20+
"karma": "~0.9.5",
2021
"karma-mocha": "latest",
2122
"karma-chrome-launcher": "latest",
2223
"karma-safari-launcher": "latest",

test/karma-e2e.conf.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
module.exports = function(karma) {
2-
shared = require(__dirname + "/karma-shared.conf.js").shared;
3-
karma.configure({
4-
urlRoot: '/_karma_/',
5-
plugins: shared.plugins,
1+
var shared = require('./karma-shared.conf');
2+
3+
module.exports = function(config) {
4+
shared(config);
5+
6+
config.set({
67
frameworks: ['ng-scenario'],
7-
basePath: shared.basePath,
8-
browsers: shared.browsers,
9-
autoWatch: shared.autoWatch,
10-
reporters: shared.reporters,
11-
singleRun: shared.singleRun,
12-
colors: shared.colors,
13-
proxies: shared.proxies,
14-
files: [
15-
'./test/e2e/**/*.js'
16-
]
8+
files: ['test/e2e/**/*.js'],
9+
urlRoot: '/_karma_/',
10+
proxies: {
11+
'/': 'http://localhost:8000/'
12+
}
1713
});
1814
};

test/karma-midway.conf.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
module.exports = function(karma) {
2-
config = require(__dirname + "/karma-shared.conf.js").shared;
3-
config.files = config.files.concat([
1+
var shared = require('./karma-shared.conf');
2+
3+
module.exports = function(config) {
4+
shared(config);
5+
6+
config.files = shared.files.concat([
47
//extra testing code
58
'components/ngMidwayTester/Source/ngMidwayTester.js',
69

710
//test files
8-
'./test/midway/**/*.js'
11+
'test/midway/**/*.js'
912
]);
10-
config.logLevel = karma.LOG_ERROR;
11-
karma.configure(config);
1213
};

test/karma-shared.conf.js

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
var shared = {};
2-
shared.plugins = [
3-
'karma-mocha',
4-
'karma-ng-scenario',
5-
'karma-chrome-launcher',
6-
'karma-firefox-launcher',
7-
'karma-safari-launcher',
8-
'karma-ng-scenario'
9-
];
10-
11-
shared.frameworks = ['mocha'];
12-
shared.basePath = '../';
13-
shared.singleRun = false
14-
shared.autoWatch = true
15-
shared.colors = true
1+
var shared = function(config) {
2+
config.set({
3+
basePath: '../',
4+
frameworks: ['mocha'],
5+
reporters: ['progress'],
6+
browsers: ['Chrome'],
7+
autoWatch: true,
168

17-
shared.reporters = ['progress'];
18-
shared.browsers = ['Chrome'];
19-
shared.proxies = {
20-
'/': 'http://localhost:8000/'
9+
// these are default values anyway
10+
singleRun: false,
11+
colors: true,
12+
});
2113
};
2214

2315
shared.files = [
24-
'./test/mocha.conf.js',
16+
'test/mocha.conf.js',
2517

2618
//3rd Party Code
2719
'components/angularjs/index.js',
@@ -37,9 +29,9 @@ shared.files = [
3729
'app/scripts/app.js',
3830

3931
//Test-Specific Code
40-
'./node_modules/chai/chai.js',
41-
'./test/lib/chai-should.js',
42-
'./test/lib/chai-expect.js'
32+
'node_modules/chai/chai.js',
33+
'test/lib/chai-should.js',
34+
'test/lib/chai-expect.js'
4335
];
4436

45-
exports.shared = shared;
37+
module.exports = shared;

test/karma-unit.conf.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
module.exports = function(karma) {
2-
config = require(__dirname + "/karma-shared.conf.js").shared;
3-
config.files = config.files.concat([
1+
var shared = require('./karma-shared.conf');
2+
3+
module.exports = function(config) {
4+
shared(config);
5+
6+
config.files = shared.files.concat([
47
//extra testing code
58
'components/angular-mocks/index.js',
69

710
//test files
811
'./test/unit/**/*.js'
912
]);
10-
karma.configure(config);
1113
};

test/lib/karma-util.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)