Skip to content

Commit aece5a6

Browse files
committed
Add test runner for project
use karma as a test runner and use grunt-karma to integrate with grunt add new dev dependencies to the package.json closes #59 using karma makes is easier to run tests while developing add docs to readme how to use karma test runner
1 parent e88cb02 commit aece5a6

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

Gruntfile.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,22 @@ module.exports = function(grunt) {
8080
dest: '<%= pkg.name %>'
8181
}
8282
},
83-
clean: ["build/"]
83+
clean: ["build/"],
84+
karma: {
85+
options: {
86+
configFile: 'karma.conf.js',
87+
},
88+
unit: {
89+
}
90+
}
8491
});
8592

8693
grunt.loadNpmTasks('grunt-contrib-concat');
8794
grunt.loadNpmTasks('grunt-yui-compressor');
8895
grunt.loadNpmTasks('grunt-contrib-copy');
8996
grunt.loadNpmTasks('grunt-contrib-compress');
9097
grunt.loadNpmTasks('grunt-contrib-clean');
98+
grunt.loadNpmTasks('grunt-karma');
9199

92100
grunt.registerTask('default', ['concat', 'min', 'cssmin', 'copy']);
93101
grunt.registerTask('release', ['concat', 'min', 'cssmin',

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ To build a release you can runt:
7171

7272
This cleans (removes) the build folder after creating both a tgz and a zip file for the version containing the built files.
7373

74+
### Testing
75+
76+
If you want to run the tests use karma with grunt:
77+
78+
grunt karma
79+
7480
### Don't Have Such a Recent Node.js Version?
7581

7682
When developing it's good to set up virtual environments to manage dependencies instead of installing them into your system (and therefore possibly breaking other projects you're working on).

karma.conf.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Karma configuration
2+
// Generated on Mon Apr 20 2015 13:03:10 GMT+0200 (CEST)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['mocha','sinon-chai'],
14+
15+
// list of files / patterns to load in the browser
16+
files: [
17+
"lib/vendor/jquery.js",
18+
"lib/vendor/underscore.js",
19+
"lib/vendor/backbone.js",
20+
"lib/vendor/accounting.js",
21+
"lib/boot.js",
22+
"lib/aggregator.js",
23+
"lib/datastore.js",
24+
"lib/main.js",
25+
"lib/model.js",
26+
"lib/utils/gdocs.js",
27+
"lib/utils/tree.js",
28+
"lib/utils/utils.js",
29+
"lib/widgets.js",
30+
'tests/fixtures.js',
31+
'tests/**/*.coffee'
32+
],
33+
34+
35+
// list of files to exclude
36+
exclude: [
37+
'**/*.swp'
38+
],
39+
40+
41+
// preprocess matching files before serving them to the browser
42+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
43+
preprocessors: {
44+
'**/*.coffee': ['coffee'],
45+
},
46+
47+
48+
// test results reporter to use
49+
// possible values: 'dots', 'progress'
50+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
51+
reporters: ['progress'],
52+
53+
54+
// web server port
55+
port: 9876,
56+
57+
58+
// enable / disable colors in the output (reporters and logs)
59+
colors: true,
60+
61+
62+
// level of logging
63+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
64+
logLevel: config.LOG_INFO,
65+
66+
67+
// enable / disable watching file and executing tests whenever any file changes
68+
autoWatch: true,
69+
70+
71+
// start these browsers
72+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
73+
browsers: ['PhantomJS'],
74+
75+
76+
// Continuous Integration mode
77+
// if true, Karma captures browsers, runs the tests and exits
78+
singleRun: false
79+
});
80+
};

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
"grunt-yui-compressor": "~0.3.0",
99
"grunt-contrib-copy": "~0.4.1",
1010
"grunt-contrib-compress": "~0.5.3",
11-
"grunt-contrib-clean": "~0.5.0"
11+
"grunt-contrib-clean": "~0.5.0",
12+
"grunt-karma": "^0.10.1",
13+
"karma-coffee-preprocessor": "^0.2.1",
14+
"karma-mocha": "^0.1.10",
15+
"karma-mocha-chai-sinon": "0.0.7",
16+
"karma-phantomjs-launcher": "^0.1.4",
17+
"karma-sinon-chai": "^0.3.0"
1218
}
1319
}

0 commit comments

Comments
 (0)