diff --git a/config.tpl.coffee b/config.tpl.coffee index 9004ed97a..51ee0349d 100644 --- a/config.tpl.coffee +++ b/config.tpl.coffee @@ -20,6 +20,12 @@ module.exports = (config) -> %EXCLUDE% ] + + # preprocess matching files before serving them to the browser + # available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: %PREPROCESSORS% + + # test results reporter to use # possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: ['progress'] diff --git a/config.tpl.js b/config.tpl.js index 080bdbcfe..0cd79c0fe 100644 --- a/config.tpl.js +++ b/config.tpl.js @@ -24,6 +24,11 @@ module.exports = function(config) { ], + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: %PREPROCESSORS%, + + // test results reporter to use // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' reporters: ['progress'], diff --git a/lib/init.js b/lib/init.js index 17cedbdc0..c6b1db54c 100755 --- a/lib/init.js +++ b/lib/init.js @@ -3,6 +3,7 @@ var fs = require('fs'); var util = require('util'); var path = require('path'); var glob = require('glob'); +var mm = require('minimatch'); var exec = require('child_process').exec; var EventEmitter = require('events').EventEmitter; @@ -315,6 +316,21 @@ var formatFiles = function(files) { }; +var pad = function(str, pad) { + return str.replace(/\n/g, '\n' + pad); +}; + + +var formatPreprocessors = function(preprocessors) { + var lines = []; + Object.keys(preprocessors).forEach(function(pattern) { + lines.push(' ' + quote(pattern) + ': [' + preprocessors[pattern].map(quote).join(', ') + ']'); + }); + + return pad('{\n' + lines.join(',\n') + '\n}', ' '); +}; + + var getBasePath = function(configFilePath, cwd) { var configParts = path.dirname(configFilePath).split(path.sep); var cwdParts = cwd.split(path.sep); @@ -355,6 +371,15 @@ var getReplacementsFromAnswers = function(answers, basePath) { frameworks.push('requirejs'); } + var allPatterns = answers.files.concat(answers.includedFiles || []); + var preprocessors = {}; + if (allPatterns.some(function(pattern) { + return mm(pattern, '**/*.coffee'); + })) { + installPackage('karma-coffee-preprocessor'); + preprocessors['**/*.coffee'] = ['coffee']; + } + return { DATE: new Date(), BASE_PATH: basePath, @@ -362,7 +387,8 @@ var getReplacementsFromAnswers = function(answers, basePath) { FILES: formatFiles(files), EXCLUDE: answers.exclude ? formatFiles(answers.exclude.map(quote)) : '', AUTO_WATCH: answers.autoWatch ? 'true' : 'false', - BROWSERS: answers.browsers.map(quote).join(', ') + BROWSERS: answers.browsers.map(quote).join(', '), + PREPROCESSORS: formatPreprocessors(preprocessors) }; };