diff --git a/README.md b/README.md index 2046d38..02d4195 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,36 @@ karma: { To change the `logLevel` in the grunt config file instead of the karma config, use one of the following strings: `OFF`, `ERROR`, `WARN`, `INFO`, `DEBUG` +The `files` option can be extended "per-target" in the typical way +Grunt handles [files][grunt-config-files]: + +```js +karma: { + options: { + files: ['lib/**/*.js'] + }, + unit: { + files: [ + { src: ['test/**/*.js'] } + ] + } +} +``` + +When using the "Grunt way" of specifying files, you can also extend the +file objects with the options [supported by karma][karma-config-files]: + +```js +karma: { + unit: { + files: [ + { src: ['test/**/*.js'], served: true }, + { src: ['lib/**/*.js'], served: true, included: false } + ] + } +} +``` + ### Config with Grunt Template Strings in `files` When using template strings in the `files` option, the results will flattened. Therefore, if you include a variable that includes an array, the array will be flattened before being passed to Karma. @@ -200,7 +230,9 @@ $ grunt karma:dev watch --grep=mypattern ## License MIT License -[karma-config-file]: http://karma-runner.github.com/0.8/config/configuration-file.html +[karma-config-file]: http://karma-runner.github.com/0.12/config/configuration-file.html +[karma-config-files]: http://karma-runner.github.io/0.12/config/files.html +[grunt-config-files]: http://gruntjs.com/configuring-tasks#files [grunt-contrib-watch]: https://github.com/gruntjs/grunt-contrib-watch [PhantomJS]: http://phantomjs.org/ [karma-mocha]: https://github.com/karma-runner/karma-mocha diff --git a/tasks/grunt-karma.js b/tasks/grunt-karma.js index a43eea6..6593eb4 100644 --- a/tasks/grunt-karma.js +++ b/tasks/grunt-karma.js @@ -30,12 +30,11 @@ module.exports = function(grunt) { grunt.registerMultiTask('karma', 'run karma.', function() { var done = this.async(); var options = this.options({ - background: false + background: false, + files: [], + client: {} }); - if (!options.client) { - options.client = {}; - } // Allow for passing cli arguments to `client.args` using `--grep=x` var args = parseArgs(process.argv.slice(2)); if (_.isArray(options.client.args)) { @@ -69,9 +68,20 @@ module.exports = function(grunt) { data.configFile = path.resolve(data.configFile); } - if (data.files){ - data.files = _.flatten(data.files); - } + data.files = [].concat.apply(options.files, this.files.map(function(file) { + return file.src.map(function(src) { + var obj = { + pattern: src + }; + + ['watched', 'served', 'included'].forEach(function(opt) { + if (opt in file) { + obj[opt] = file[opt]; + } + }); + return obj; + }); + })); // Allow the use of templates in preprocessors if (_.isPlainObject(data.preprocessors)) {