diff --git a/gruntfile.js b/gruntfile.js index fc78013..6a696eb 100644 --- a/gruntfile.js +++ b/gruntfile.js @@ -100,6 +100,15 @@ module.exports = function (grunt) { } ] }, + flatten: { + options: { + files: [ + [['node_modules/expect.js/index.js']], + [[['test/**/*.js']]] + ] + }, + singleRun: true + }, background: { background: true, files: [ @@ -138,7 +147,8 @@ module.exports = function (grunt) { 'eslint', 'karma:single', 'karma:config', - 'karma:merge' + 'karma:merge', + 'karma:flatten' ]) grunt.registerTask('default', ['test']) grunt.registerTask('bgtest', ['karma:background', 'watch:bgtest']) diff --git a/tasks/grunt-karma.js b/tasks/grunt-karma.js index 40bce1d..97b1cf0 100644 --- a/tasks/grunt-karma.js +++ b/tasks/grunt-karma.js @@ -71,22 +71,27 @@ module.exports = function (grunt) { data.configFile = path.resolve(data.configFile) } - if (data.files || options.files) { - data.files = [].concat.apply(options.files || [], this.files.map(function (file) { - return file.src.map(function (src) { - var obj = { - pattern: src - } - var opts = ['watched', 'served', 'included'] - opts.forEach(function (opt) { - if (opt in file) { - obj[opt] = file[opt] + if (this.files.length || options.files) { + data.files = [].concat.apply( + // For the 'files' option, we support nested arrays as a convenient + // way to specify files without needing the user to concat or + // flatten them ahead of time. + _.flattenDeep(options.files || []), + this.files.map(function (file) { + return file.src.map(function (src) { + var obj = { + pattern: src } + var opts = ['watched', 'served', 'included'] + opts.forEach(function (opt) { + if (opt in file) { + obj[opt] = file[opt] + } + }) + return obj }) - return obj }) - })) - data.files = _.flattenDeep(data.files) + ) } // Allow the use of templates in preprocessors