Skip to content

Commit 043ee95

Browse files
feat(karma): Simplify karma configuration. Enable 'karma start conf/karma.js' to work (without Grunt). Enable watch:true in karma:debug to enable on-the-fly code/test reload
1 parent a183ebd commit 043ee95

File tree

4 files changed

+54
-55
lines changed

4 files changed

+54
-55
lines changed

Gruntfile.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,33 +86,18 @@ module.exports = function (grunt) {
8686
karma: {
8787
options: {
8888
configFile: 'config/karma.js',
89-
singleRun: true,
90-
exclude: [],
91-
frameworks: ['systemjs', 'jasmine'],
92-
reporters: 'dots', // 'dots' || 'progress'
93-
port: 8080,
94-
colors: true,
95-
autoWatch: false,
96-
autoWatchInterval: 0,
9789
// Serve and load angular files using regular Karma mode
98-
files: files.karmaServedFiles('1.4.1'),
99-
systemjs: {
100-
configFile: 'config/system.config.js',
101-
// These files are served by Karma, but loaded using SystemJS
102-
files: ['src/**/*.ts'].concat(files.testUtils, files.test),
103-
// This is turned into a regexp and used to load specs into Karma
104-
testFileSuffix: "/test/\\S+.[tj]s"
105-
},
10690
browsers: [ grunt.option('browser') || 'PhantomJS' ]
10791
},
10892
// Same as karma:base
10993
unit: {
110-
browsers: [ grunt.option('browser') || 'PhantomJS' ]
11194
},
11295
// Launch Karma in Chrome, click debug button, debug tests
11396
debug: {
11497
singleRun: false,
11598
background: false,
99+
autoWatch: true,
100+
autoWatchInterval: 1,
116101
browsers: [ grunt.option('browser') || 'Chrome' ]
117102
},
118103
// Test with angular 1.2
@@ -128,12 +113,10 @@ module.exports = function (grunt) {
128113
options: { files: files.karmaServedFiles('1.4.1') }
129114
},
130115
background: {
131-
background: true,
132-
browsers: [ grunt.option('browser') || 'PhantomJS' ]
116+
background: true
133117
},
134118
// PhantomJS in the console; watch for changes to tests/src
135119
watch: {
136-
configFile: 'config/karma.js',
137120
singleRun: false,
138121
autoWatch: true,
139122
autoWatchInterval: 1

config/karma.base.js

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

config/karma.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,51 @@
11
// Karma configuration file
2-
var config = require("./karma.base");
2+
3+
var files = require('../files').files;
34

45
module.exports = function (karma) {
5-
config.logLevel = karma.LOG_DEBUG;
6-
karma.set(config)
6+
var config = {
7+
8+
singleRun: true,
9+
autoWatch: false,
10+
autoWatchInterval: 0,
11+
12+
// level of logging
13+
// possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG
14+
logLevel: karma.LOG_DEBUG,
15+
// 'dots', 'progress'
16+
reporters: 'dots',
17+
colors: true,
18+
19+
port: 8080,
20+
21+
// base path, that will be used to resolve files and exclude
22+
basePath: '..',
23+
24+
// Start these browsers, currently available:
25+
// Chrome, ChromeCanary, Firefox, Opera, Safari, PhantomJS
26+
browsers: ['PhantomJS'],
27+
28+
frameworks: ['systemjs', 'jasmine'],
29+
plugins: [
30+
require('karma-systemjs'),
31+
require('karma-jasmine'),
32+
require('karma-phantomjs-launcher'),
33+
require('karma-chrome-launcher')
34+
],
35+
36+
// Karma files available to serve is overridden using files.karmaServedFiles() in some grunt tasks (e.g., karma:ng12)
37+
files: files.karmaServedFiles('1.4.1'),
38+
// Actual tests to load is configured in systemjs.files block
39+
systemjs: {
40+
// Set up systemjs paths
41+
configFile: 'config/system.config.js',
42+
// These files are served by Karma, but loaded using SystemJS
43+
files: ['src/**/*.ts'].concat(files.testUtils, files.test),
44+
// karma-systemjs kludge: This is turned into a regexp and used to load specs into Karma
45+
testFileSuffix: "/test/\\S+.[tj]s"
46+
},
47+
exclude: []
48+
};
49+
50+
karma.set(config);
751
};

files.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ routerFiles = {
4141
// This returns a Karma 'files configuration' for the files served by the Karma web server
4242
// http://karma-runner.github.io/0.8/config/files.html
4343
karmaServedFiles: function(version) {
44-
return [
45-
routerFiles.angular(version),
44+
return routerFiles.angular(version).map(function (pattern) {
45+
return { watched: false, included: true, nocache: true, pattern: pattern };
46+
}).concat([
4647
{ watched: true, included: false, nocache: true, pattern: 'src/**/*.ts' },
4748
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.ts' },
4849
{ watched: true, included: false, nocache: true, pattern: 'test/**/*.js' }
49-
]
50+
]);
5051
}
5152
};
5253

0 commit comments

Comments
 (0)