diff --git a/Gruntfile.coffee b/Gruntfile.coffee index d25dfb8b6..3c99570d8 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -30,7 +30,7 @@ module.exports = (grunt) -> unit: 'simplemocha:unit' tasks: 'simplemocha:tasks' client: 'test/client/karma.conf.js' - e2e: 'test/e2e/*/karma.conf.js' + e2e: ['test/e2e/*/karma.conf.js', 'test/e2e/*/karma.conf.coffee'] simplemocha: diff --git a/config.template b/config.template index c591e9034..0156988b9 100644 --- a/config.template +++ b/config.template @@ -1,74 +1,78 @@ // Karma configuration // Generated on %DATE% +module.exports = function(karma) { + karma.configure({ -// base path, that will be used to resolve files and exclude -basePath = '%BASE_PATH%'; + // base path, that will be used to resolve files and exclude + basePath: '%BASE_PATH%', -// frameworks to use -frameworks = [%FRAMEWORKS%]; + // frameworks to use + frameworks: [%FRAMEWORKS%], -// list of files / patterns to load in the browser -files = [ - %FILES% -]; + // list of files / patterns to load in the browser + files: [ + %FILES% + ], -// list of files to exclude -exclude = [ - %EXCLUDE% -]; + // list of files to exclude + exclude: [ + %EXCLUDE% + ], -// test results reporter to use -// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' -reporters = ['progress']; + // test results reporter to use + // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' + reporters: ['progress'], -// web server port -port = 9876; + // web server port + port: 9876, -// cli runner port -runnerPort = 9100; + // cli runner port + runnerPort: 9100, -// enable / disable colors in the output (reporters and logs) -colors = true; + // enable / disable colors in the output (reporters and logs) + colors: true, -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; + // level of logging + // possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG + logLevel: karma.LOG_INFO, -// enable / disable watching file and executing tests whenever any file changes -autoWatch = %AUTO_WATCH%; + // enable / disable watching file and executing tests whenever any file changes + autoWatch: %AUTO_WATCH%, -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -browsers = [%BROWSERS%]; + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari (only Mac) + // - PhantomJS + // - IE (only Windows) + browsers: [%BROWSERS%], -// If browser does not capture in given timeout [ms], kill it -captureTimeout = 60000; + // If browser does not capture in given timeout [ms], kill it + captureTimeout: 60000, -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false, -// plugins to load -plugins = [ - %PLUGINS% -]; + // plugins to load + plugins: [ + %PLUGINS% + ], + }); +}; diff --git a/lib/config.js b/lib/config.js index 58821c8a6..f73937b52 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,12 +1,13 @@ -var fs = require('fs'); var path = require('path'); -var vm = require('vm'); -var coffee = require('coffee-script'); var log = require('./logger').create('config'); var helper = require('./helper'); var constant = require('./constants'); +// Coffee is required here to enable config files written in coffee-script. +// It's not directly used in this file. +require('coffee-script'); + var Pattern = function(pattern, served, included, watched) { this.pattern = pattern; @@ -39,8 +40,7 @@ var createPatternObject = function(pattern) { return new Pattern(null, false, false, false); }; - -var normalizeConfig = function(config) { +var normalizeConfig = function(config, configFilePath) { var basePathResolve = function(relativePath) { if (helper.isUrlAbsolute(relativePath)) { @@ -61,6 +61,16 @@ var normalizeConfig = function(config) { }; }; + if (helper.isString(configFilePath)) { + // resolve basePath + config.basePath = path.resolve(path.dirname(configFilePath), config.basePath); + + // always ignore the config file itself + config.exclude.push(configFilePath); + } else { + config.basePath = path.resolve(config.basePath || '.'); + } + config.files = config.files.map(createPatternObject).map(createPatternMapper(basePathResolve)); config.exclude = config.exclude.map(basePathResolve); config.junitReporter.outputFile = basePathResolve(config.junitReporter.outputFile); @@ -121,85 +131,64 @@ var normalizeConfig = function(config) { return config; }; - -var readConfigFile = function(filepath) { - var configEnv = { - // constants - LOG_DISABLE: constant.LOG_DISABLE, - LOG_ERROR: constant.LOG_ERROR, - LOG_WARN: constant.LOG_WARN, - LOG_INFO: constant.LOG_INFO, - LOG_DEBUG: constant.LOG_DEBUG, - // access to globals - console: console, - require: require, - process: process, - __filename: filepath, - __dirname: path.dirname(filepath) - }; - +var KarmaDsl = function(config) { + this.LOG_DISABLE = constant.LOG_DISABLE; + this.LOG_ERROR = constant.LOG_ERROR; + this.LOG_WARN = constant.LOG_WARN; + this.LOG_INFO = constant.LOG_INFO; + this.LOG_DEBUG = constant.LOG_DEBUG; // TODO(vojta): remove var CONST_ERR = '%s is not supported anymore.\n\tPlease use `frameworks = ["%s"];` instead.'; ['JASMINE', 'MOCHA', 'QUNIT'].forEach(function(framework) { [framework, framework + '_ADAPTER'].forEach(function(name) { - Object.defineProperty(configEnv, name, {get: function() { + Object.defineProperty(global, name, {get: function() { log.warn(CONST_ERR, name, framework.toLowerCase()); }}); }); }); ['REQUIRE', 'REQUIRE_ADAPTER'].forEach(function(name) { - Object.defineProperty(configEnv, name, {get: function() { + Object.defineProperty(global, name, {get: function() { log.warn(CONST_ERR, name, 'requirejs'); }}); }); ['ANGULAR_SCENARIO', 'ANGULAR_SCENARIO_ADAPTER'].forEach(function(name) { - Object.defineProperty(configEnv, name, {get: function() { + Object.defineProperty(global, name, {get: function() { log.warn(CONST_ERR, name, 'requirejs'); }}); }); - var configSrc; - try { - configSrc = fs.readFileSync(filepath); - } catch(e) { - if (e.code === 'ENOENT' || e.code === 'EISDIR') { - log.error('Config file does not exist!'); - } else { - log.error('Unexpected error opening config file!\n', e); - } - - process.exit(1); - } + this.configure = function(newConfig) { + Object.keys(newConfig).forEach(function(key) { + config[key] = newConfig[key]; + }); + }; +}; - try { - // if the configuration file is coffeescript compile it - if (path.extname(filepath) === '.coffee') { - configSrc = coffee.compile(configSrc.toString(), {bare: true}); +var parseConfig = function(configFilePath, cliOptions) { + var configModule; + if (configFilePath) { + try { + configModule = require(configFilePath); + } catch(e) { + if (e.code === 'MODULE_NOT_FOUND') { + log.error('Config file does not exist!'); + } else { + log.error('Invalid config file!\n', e); + } + return process.exit(1); } - - vm.runInNewContext(configSrc, configEnv); - } catch(e) { - if (e.name === 'SyntaxError') { - log.error('Syntax error in config file!\n' + e.message); - } else { - log.error('Invalid config file!\n', e); + if (!helper.isFunction(configModule)) { + log.error('Config file must export a function!'); + return process.exit(1); } - - process.exit(1); + } else { + // if no config file path is passed, we define a dummy config module. + configModule = function() {}; } - return configEnv; -}; - - -var parseConfig = function(configFilePath, cliOptions) { - - var configFromFile = helper.isString(configFilePath) ? readConfigFile(configFilePath) : {}; - - // default config var config = { frameworks: [], port: constant.DEFAULT_PORT, @@ -237,31 +226,20 @@ var parseConfig = function(configFilePath, cliOptions) { 'karma-coffee-preprocessor' ] }; + var dsl = new KarmaDsl(config); + try { + configModule(dsl); + } catch(e) { + log.error('Error in config file!\n', e); + return process.exit(1); + } // merge the config from config file and cliOptions (precendense) - Object.getOwnPropertyNames(config).forEach(function(key) { - if (cliOptions.hasOwnProperty(key)) { - config[key] = cliOptions[key]; - } else if (configFromFile.hasOwnProperty(key)) { - config[key] = configFromFile[key]; - } - }); - - if (helper.isString(configFilePath)) { - // resolve basePath - config.basePath = path.resolve(path.dirname(configFilePath), config.basePath); + dsl.configure(cliOptions); - // always ignore the config file itself - config.exclude.push(configFilePath); - } - else { - config.basePath = path.resolve(config.basePath); - } - - return normalizeConfig(config); + return normalizeConfig(config, configFilePath); }; - // PUBLIC API exports.parseConfig = parseConfig; exports.Pattern = Pattern; diff --git a/test/client/karma.conf.js b/test/client/karma.conf.js index 409069a7a..a71411151 100644 --- a/test/client/karma.conf.js +++ b/test/client/karma.conf.js @@ -1,88 +1,84 @@ -// Sample Karma configuration file, that contain pretty much all the available options -// It's used for running client tests on Travis (http://travis-ci.org/#!/karma-runner/karma) -// Most of the options can be overriden by cli arguments (see karma --help) -// -// For all available config options and default values, see: -// https://github.com/karma-runner/karma/blob/stable/lib/config.js#L54 - - -// base path, that will be used to resolve files and exclude -basePath = '../..'; - -frameworks = ['jasmine']; - -// list of files / patterns to load in the browser -files = [ - 'test/client/mocks.js', - 'static/karma.src.js', - 'test/client/*.spec.js' -]; - -// list of files to exclude -exclude = []; - -// use dots reporter, as travis terminal does not support escaping sequences -// possible values: 'dots', 'progress', 'junit', 'teamcity' -// CLI --reporters progress -reporters = ['progress', 'junit']; - -junitReporter = { - // will be resolved to basePath (in the same way as files/exclude patterns) - outputFile: 'test-results.xml' +module.exports = function(karma) { + karma.configure({ + // base path, that will be used to resolve files and exclude + basePath: '../..', + + frameworks: ['jasmine'], + + // list of files / patterns to load in the browser + files: [ + 'test/client/mocks.js', + 'static/karma.src.js', + 'test/client/*.spec.js' + ], + + // list of files to exclude + exclude: [], + + // use dolts reporter, as travis terminal does not support escaping sequences + // possible values: 'dots', 'progress', 'junit', 'teamcity' + // CLI --reporters progress + reporters: ['progress', 'junit'], + + junitReporter: { + // will be resolved to basePath (in the same way as files/exclude patterns) + outputFile: 'test-results.xml' + }, + + // web server port + // CLI --port 9876 + port: 9876, + + // cli runner port + // CLI --runner-port 9100 + runnerPort: 9100, + + // enable / disable colors in the output (reporters and logs) + // CLI --colors --no-colors + colors: true, + + // level of logging + // possible values: karma.LOG_DISABLE || karma.LOG_ERROR || karma.LOG_WARN || karma.LOG_INFO || karma.LOG_DEBUG + // CLI --log-level debug + logLevel: karma.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + // CLI --auto-watch --no-auto-watch + autoWatch: true, + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari (only Mac) + // - PhantomJS + // - IE (only Windows) + // CLI --browsers Chrome,Firefox,Safari + browsers: [], + + // If browser does not capture in given timeout [ms], kill it + // CLI --capture-timeout 5000 + captureTimeout: 5000, + + // Auto run tests on start (when browsers are captured) and exit + // CLI --single-run --no-single-run + singleRun: false, + + // report which specs are slower than 500ms + // CLI --report-slower-than 500 + reportSlowerThan: 500, + + // compile coffee scripts + preprocessors: { + '**/*.coffee': 'coffee' + }, + + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-junit-reporter' + ] + }); }; - -// web server port -// CLI --port 9876 -port = 9876; - -// cli runner port -// CLI --runner-port 9100 -runnerPort = 9100; - -// enable / disable colors in the output (reporters and logs) -// CLI --colors --no-colors -colors = true; - -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -// CLI --log-level debug -logLevel = LOG_INFO; - -// enable / disable watching file and executing tests whenever any file changes -// CLI --auto-watch --no-auto-watch -autoWatch = true; - -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -// CLI --browsers Chrome,Firefox,Safari -browsers = []; - -// If browser does not capture in given timeout [ms], kill it -// CLI --capture-timeout 5000 -captureTimeout = 5000; - -// Auto run tests on start (when browsers are captured) and exit -// CLI --single-run --no-single-run -singleRun = false; - -// report which specs are slower than 500ms -// CLI --report-slower-than 500 -reportSlowerThan = 500; - -// compile coffee scripts -preprocessors = { - '**/*.coffee': 'coffee' -}; - -plugins = [ - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher', - 'karma-junit-reporter' -] diff --git a/test/e2e/angular-scenario/karma.conf.js b/test/e2e/angular-scenario/karma.conf.js index b903b1f1e..299699102 100644 --- a/test/e2e/angular-scenario/karma.conf.js +++ b/test/e2e/angular-scenario/karma.conf.js @@ -1,24 +1,27 @@ -frameworks = ['ng-scenario']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['ng-scenario'], -files = [ - 'e2eSpec.js' -]; + files: [ + 'e2eSpec.js' + ], -urlRoot = '/__karma/'; + urlRoot: '/__karma/', -autoWatch = true; + autoWatch: true, -proxies = { - '/': 'http://localhost:8000/test/e2e/angular-scenario/' -}; - -browsers = ['Chrome']; + proxies: { + '/': 'http://localhost:8000/test/e2e/angular-scenario/' + }, -reporters = ['dots']; + browsers: ['Chrome'], -plugins = [ - 'karma-ng-scenario', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + reporters: ['dots'], + plugins: [ + 'karma-ng-scenario', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ] + }); +}; diff --git a/test/e2e/basic/karma.conf.js b/test/e2e/basic/karma.conf.js index 33bbb698d..d7216fbb5 100644 --- a/test/e2e/basic/karma.conf.js +++ b/test/e2e/basic/karma.conf.js @@ -1,17 +1,21 @@ -frameworks = ['jasmine']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['jasmine'], -files = [ - '*.js' -]; + files: [ + '*.js' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome']; + browsers: ['Chrome'], -reporters = ['dots']; + reporters: ['dots'], -plugins = [ - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/coffee-config/basic.js b/test/e2e/coffee-config/basic.js new file mode 100644 index 000000000..a4f319266 --- /dev/null +++ b/test/e2e/coffee-config/basic.js @@ -0,0 +1,5 @@ +describe('basic', function() { + it('should pass', function() { + expect(true).toBe(true); + }); +}); diff --git a/test/e2e/coffee-config/basic2.coffee b/test/e2e/coffee-config/basic2.coffee new file mode 100644 index 000000000..4b37f2b9a --- /dev/null +++ b/test/e2e/coffee-config/basic2.coffee @@ -0,0 +1,4 @@ +describe 'basic', -> + + it 'should pass', -> + expect(true).toBe true diff --git a/test/e2e/coffee-config/karma.conf.coffee b/test/e2e/coffee-config/karma.conf.coffee new file mode 100644 index 000000000..4a27d35ed --- /dev/null +++ b/test/e2e/coffee-config/karma.conf.coffee @@ -0,0 +1,26 @@ +module.exports = (karma) -> + karma.configure { + frameworks: ['jasmine'], + + files: [ + '*.js', + '*.coffee' + ], + + autoWatch: true, + + browsers: ['Chrome'], + + reporters: ['dots'], + + preprocessors: { + '**/*.coffee': 'coffee' + }, + + plugins: [ + 'karma-jasmine', + 'karma-coffee-preprocessor', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + } diff --git a/test/e2e/coffee/karma.conf.js b/test/e2e/coffee/karma.conf.js index 3fa7b21ab..b1ac1fb74 100644 --- a/test/e2e/coffee/karma.conf.js +++ b/test/e2e/coffee/karma.conf.js @@ -1,22 +1,26 @@ -frameworks = ['jasmine']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['jasmine'], -files = [ - '*.coffee' -]; + files: [ + '*.coffee' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome']; + browsers: ['Chrome'], -preprocessors = { - '**/*.coffee': 'coffee' -}; + preprocessors: { + '**/*.coffee': 'coffee' + }, -reporters = ['dots']; + reporters: ['dots'], -plugins = [ - 'karma-jasmine', - 'karma-coffee-preprocessor', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-jasmine', + 'karma-coffee-preprocessor', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/coverage/karma.conf.js b/test/e2e/coverage/karma.conf.js index 928aa2a03..2df95b6b8 100644 --- a/test/e2e/coverage/karma.conf.js +++ b/test/e2e/coverage/karma.conf.js @@ -1,36 +1,40 @@ -frameworks = ['jasmine']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['jasmine'], -files = [ - 'lib/*.js', - 'test/*.js' -]; + files: [ + 'lib/*.js', + 'test/*.js' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome'] + browsers: ['Chrome'], -reporters = ['progress', 'coverage']; + reporters: ['progress', 'coverage'], -preprocessors = { - 'lib/*.js': 'coverage' -}; + preprocessors: { + 'lib/*.js': 'coverage' + }, -//Code Coverage options. report type available: -//- html (default) -//- lcov (lcov and html) -//- lcovonly -//- text (standard output) -//- text-summary (standard output) -//- cobertura (xml format supported by Jenkins) -coverageReporter = { - // cf. http://gotwarlost.github.io/istanbul/public/apidocs/ - type : 'html', - dir : 'coverage/' -}; + //Code Coverage options. report type available: + //- html (default) + //- lcov (lcov and html) + //- lcovonly + //- text (standard output) + //- text-summary (standard output) + //- cobertura (xml format supported by Jenkins) + coverageReporter: { + // cf. http://gotwarlost.github.io/istanbul/public/apidocs/ + type : 'html', + dir : 'coverage/' + }, -plugins = [ - 'karma-jasmine', - 'karma-coverage', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-jasmine', + 'karma-coverage', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/coverageQunit/karma.conf.js b/test/e2e/coverageQunit/karma.conf.js index 3be230938..04256752c 100644 --- a/test/e2e/coverageQunit/karma.conf.js +++ b/test/e2e/coverageQunit/karma.conf.js @@ -1,36 +1,40 @@ -frameworks = ['qunit']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['qunit'], -files = [ - 'lib/*.js', - 'test/*.js' -]; + files: [ + 'lib/*.js', + 'test/*.js' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome']; + browsers: ['Chrome'], -reporters = ['progress', 'coverage']; + reporters: ['progress', 'coverage'], -preprocessors = { - 'lib/*.js': 'coverage' -}; + preprocessors: { + 'lib/*.js': 'coverage' + }, -//Code Coverage options. report type available: -//- html (default) -//- lcov (lcov and html) -//- lcovonly -//- text (standard output) -//- text-summary (standard output) -//- cobertura (xml format supported by Jenkins) -coverageReporter = { - // cf. http://gotwarlost.github.io/istanbul/public/apidocs/ - type : 'html', - dir : 'coverage/' -}; + //Code Coverage options. report type available: + //- html (default) + //- lcov (lcov and html) + //- lcovonly + //- text (standard output) + //- text-summary (standard output) + //- cobertura (xml format supported by Jenkins) + coverageReporter: { + // cf. http://gotwarlost.github.io/istanbul/public/apidocs/ + type : 'html', + dir : 'coverage/' + }, -plugins = [ - 'karma-qunit', - 'karma-coverage', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-qunit', + 'karma-coverage', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/coverageRequirejs/karma.conf.js b/test/e2e/coverageRequirejs/karma.conf.js index 34684f8f8..ed1784340 100644 --- a/test/e2e/coverageRequirejs/karma.conf.js +++ b/test/e2e/coverageRequirejs/karma.conf.js @@ -1,29 +1,33 @@ -frameworks = ['mocha', 'requirejs']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['mocha', 'requirejs'], -files = [ - 'main.js', - {pattern: '*.js', included: false}, -]; + files: [ + 'main.js', + {pattern: '*.js', included: false}, + ], -autoWatch = true; -browsers = ['Chrome']; -singleRun = false; + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, -reporters = ['progress', 'coverage']; + reporters: ['progress', 'coverage'], -preprocessors = { - 'dependency.js': 'coverage' -}; + preprocessors: { + 'dependency.js': 'coverage' + }, -coverageReporter = { - type : 'html', - dir : 'coverage/' -}; + coverageReporter: { + type : 'html', + dir : 'coverage/' + }, -plugins = [ - 'karma-mocha', - 'karma-requirejs', - 'karma-coverage', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-mocha', + 'karma-requirejs', + 'karma-coverage', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/junit/karma.conf.js b/test/e2e/junit/karma.conf.js index 0b9e9062f..73c9e9cb8 100644 --- a/test/e2e/junit/karma.conf.js +++ b/test/e2e/junit/karma.conf.js @@ -1,24 +1,28 @@ -frameworks = ['jasmine']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['jasmine'], -files = [ - '*.js' -]; + files: [ + '*.js' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome'] + browsers: ['Chrome'], -reporters = ['dots', 'junit']; + reporters: ['dots', 'junit'], -logLevel = LOG_DEBUG; + logLevel: karma.LOG_DEBUG, -junitReporter = { - outputFile: 'test-results.xml' -}; + junitReporter: { + outputFile: 'test-results.xml' + }, -plugins = [ - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher', - 'karma-junit-reporter' -]; + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-junit-reporter' + ], + }); +}; diff --git a/test/e2e/mocha/karma.conf.js b/test/e2e/mocha/karma.conf.js index 101d6246c..c5963071b 100644 --- a/test/e2e/mocha/karma.conf.js +++ b/test/e2e/mocha/karma.conf.js @@ -1,19 +1,23 @@ -frameworks = ['mocha']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['mocha'], -files = [ - '*.js' -]; + files: [ + '*.js' + ], -autoWatch = true; -browsers = ['Chrome']; -singleRun = false; + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, -browsers = ['Chrome']; + browsers: ['Chrome'], -reporters = ['dots']; + reporters: ['dots'], -plugins = [ - 'karma-mocha', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-mocha', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/qunit/karma.conf.js b/test/e2e/qunit/karma.conf.js index ebfb2c8e9..edb7cb5b1 100644 --- a/test/e2e/qunit/karma.conf.js +++ b/test/e2e/qunit/karma.conf.js @@ -1,17 +1,21 @@ -frameworks = ['qunit']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['qunit'], -files = [ - '*.js' -]; + files: [ + '*.js' + ], -autoWatch = true; + autoWatch: true, -browsers = ['Chrome']; + browsers: ['Chrome'], -reporters = ['dots']; + reporters: ['dots'], -plugins = [ - 'karma-qunit', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-qunit', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/requirejs/karma.conf.js b/test/e2e/requirejs/karma.conf.js index ea6e62020..676fd3601 100644 --- a/test/e2e/requirejs/karma.conf.js +++ b/test/e2e/requirejs/karma.conf.js @@ -1,64 +1,67 @@ // Karma configuration // Generated on Thu Jul 26 2012 14:35:23 GMT-0700 (PDT) +module.exports = function(karma) { + karma.configure({ + // base path, that will be used to resolve files and exclude + basePath: '', -// base path, that will be used to resolve files and exclude -basePath = ''; + frameworks: ['jasmine', 'requirejs'], -frameworks = ['jasmine', 'requirejs']; + // list of files / patterns to load in the browser + files: [ + 'main.js', -// list of files / patterns to load in the browser -files = [ - 'main.js', + // all the sources, tests + {pattern: '*.js', included: false} + ], - // all the sources, tests - {pattern: '*.js', included: false} -]; + // test results reporter to use + // possible values: dots || progress + reporter: 'dots', -// test results reporter to use -// possible values: dots || progress -reporter = 'dots'; + // web server port + port: 9876, -// web server port -port = 9876; + // cli runner port + runnerPort: 9100, -// cli runner port -runnerPort = 9100; + // enable / disable colors in the output (reporters and logs) + colors: true, -// enable / disable colors in the output (reporters and logs) -colors = true; + // level of logging + // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG + logLevel: karma.LOG_INFO, -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, -// enable / disable watching file and executing tests whenever any file changes -autoWatch = true; + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari + // - PhantomJS + browsers: ['Chrome'], -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari -// - PhantomJS -browsers = ['Chrome']; + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false, -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; - -plugins = [ - 'karma-requirejs', - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-requirejs', + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/syntax-error/karma.conf.ignore.js b/test/e2e/syntax-error/karma.conf.ignore.js index 8bb018408..d20e781e3 100644 --- a/test/e2e/syntax-error/karma.conf.ignore.js +++ b/test/e2e/syntax-error/karma.conf.ignore.js @@ -1,21 +1,25 @@ -frameworks = ['jasmine']; +module.exports = function(karma) { + karma.configure({ + frameworks: ['jasmine'], -// files to load -files = [ - '*.js' -]; + // files to load + files: [ + '*.js' + ], -autoWatch = true; -autoWatchInterval = 1; -logLevel = LOG_INFO; -logColors = true; + autoWatch: true, + autoWatchInterval: 1, + logLevel: karma.LOG_INFO, + logColors: true, -browsers = ['Chrome']; + browsers: ['Chrome'], -reporters = ['dots']; + reporters: ['dots'], -plugins = [ - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/e2e/timeout/karma.conf.ignore.js b/test/e2e/timeout/karma.conf.ignore.js index 2ad704da0..c3ef50e45 100644 --- a/test/e2e/timeout/karma.conf.ignore.js +++ b/test/e2e/timeout/karma.conf.ignore.js @@ -1,63 +1,67 @@ // Karma configuration // Generated on Sun Sep 30 2012 22:44:01 GMT-0700 (PDT) +module.exports = function(karma) { + karma.configure({ -// base path, that will be used to resolve files and exclude -basePath = ''; + // base path, that will be used to resolve files and exclude + basePath: '', -frameworks = ['jasmine']; + frameworks: ['jasmine'], -// list of files / patterns to load in the browser -files = [ - '*.js' -]; + // list of files / patterns to load in the browser + files: [ + '*.js' + ], -// test results reporter to use -// possible values: 'dots', 'progress', 'junit' -reporters = ['progress']; + // test results reporter to use + // possible values: 'dots', 'progress', 'junit' + reporters: ['progress'], -// web server port -port = 8080; + // web server port + port: 8080, -// cli runner port -runnerPort = 9100; + // cli runner port + runnerPort: 9100, -// enable / disable colors in the output (reporters and logs) -colors = true; + // enable / disable colors in the output (reporters and logs) + colors: true, -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; + // level of logging + // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG + logLevel: karma.LOG_INFO, -// enable / disable watching file and executing tests whenever any file changes -autoWatch = true; + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -browsers = [__dirname + '/fake-browser.sh']; + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari (only Mac) + // - PhantomJS + // - IE (only Windows) + browsers: [__dirname + '/fake-browser.sh'], -captureTimeout = 1000; + captureTimeout: 1000, -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false, -plugins = [ - 'karma-jasmine', - 'karma-chrome-launcher', - 'karma-firefox-launcher' -]; + plugins: [ + 'karma-jasmine', + 'karma-chrome-launcher', + 'karma-firefox-launcher' + ], + }); +}; diff --git a/test/unit/config.spec.coffee b/test/unit/config.spec.coffee index c28a77f92..3e4f234db 100644 --- a/test/unit/config.spec.coffee +++ b/test/unit/config.spec.coffee @@ -2,7 +2,6 @@ # lib/config.js module #============================================================================== describe 'config', -> - fsMock = require('mocks').fs loadFile = require('mocks').loadFile mocks = m = e = null path = require('path') @@ -22,41 +21,39 @@ describe 'config', -> patternsFrom = (list) -> list.map (pattern) -> pattern.pattern + wrapCfg = (cfg) -> + return (karma) -> + karma.configure cfg + beforeEach -> - # create instance of fs mock mocks = {} mocks.process = exit: sinon.spy() - mocks.fs = fsMock.create - bin: - sub: - 'one.js' : fsMock.file '2011-12-25' - 'two.js' : fsMock.file '2011-12-26' - 'log.txt' : 1 - mod: - 'one.js' : 1 - 'test.xml': 1 - 'file.js' : 1 - 'some.txt': 1 - 'more.js' : 1 - home: - '.vojta' : 1 - 'config1.js': fsMock.file 0, 'basePath = "base";reporter="dots"' - 'config2.js': fsMock.file 0, 'basePath = "/abs/base"' - 'config3.js': fsMock.file 0, 'files = ["one.js", "sub/two.js"];' - 'config4.js': fsMock.file 0, 'port = 123; autoWatch = true; basePath = "/abs/base"' - 'config5.js': fsMock.file 0, 'port = {f: __filename, d: __dirname}' # piggyback on port prop - 'config6.js': fsMock.file 0, 'reporters = "junit";' - 'config7.js': fsMock.file 0, 'browsers = ["Chrome", "Firefox"];' - 'config8.js': fsMock.file 0, 'require("fs").readFileSync("/not/a/real/file/path")' - conf: - 'invalid.js': fsMock.file 0, '={function' - 'exclude.js': fsMock.file 0, 'exclude = ["one.js", "sub/two.js"];' - 'absolute.js': fsMock.file 0, 'files = ["http://some.com", "https://more.org/file.js"];' - 'both.js': fsMock.file 0, 'files = ["one.js", "two.js"]; exclude = ["third.js"]' - 'coffee.coffee': fsMock.file 0, 'files = [ "one.js"\n "two.js"]' + mockConfigs = { + '/home/config1.js': wrapCfg({basePath: 'base', reporter: 'dots'}), + '/home/config2.js': wrapCfg({basePath: '/abs/base'}), + '/home/config3.js': wrapCfg({files: ['one.js', 'sub/two.js']}), + '/home/config4.js': wrapCfg({port: 123, autoWatch: true, basePath: '/abs/base'}), + '/home/config6.js': wrapCfg({reporters: 'junit'}), + '/home/config7.js': wrapCfg({browsers: ['Chrome', 'Firefox']}), + '/conf/invalid.js': () -> throw new SyntaxError('Unexpected token =') + '/conf/exclude.js': wrapCfg({exclude: ['one.js', 'sub/two.js']}), + '/conf/absolute.js': wrapCfg({files: ['http://some.com', 'https://more.org/file.js']}), + '/conf/both.js': wrapCfg({files: ['one.js', 'two.js'], exclude: ['third.js']}), + '/conf/coffee.coffee': wrapCfg({files: [ 'one.js', 'two.js']}), + } # load file under test - m = loadFile __dirname + '/../../lib/config.js', mocks, {process: mocks.process} + m = loadFile __dirname + '/../../lib/config.js', mocks, { + global: {}, + process: mocks.process, + require: (path) -> + if mockConfigs[path] + return mockConfigs[path] + if path.indexOf('./') is 0 + require '../../lib/' + path + else + require path + } e = m.exports @@ -119,15 +116,6 @@ describe 'config', -> expect(event.data).to.be.deep.equal ['Config file does not exist!'] expect(mocks.process.exit).to.have.been.calledWith 1 - it 'should not log config file does not exist if config file throws an ENOENT', -> - e.parseConfig '/home/config8.js', {} - - expect(logSpy).to.have.been.called - event = logSpy.lastCall.args[0] - expect(event.level.toString()).to.be.equal 'ERROR' - expect(event.data).to.be.not.deep.equal ['Config file does not exist!'] - expect(mocks.process.exit).to.have.been.calledWith 1 - it 'should log error and exit if it is a directory', -> e.parseConfig '/conf', {} @@ -145,7 +133,8 @@ describe 'config', -> expect(logSpy).to.have.been.called event = logSpy.lastCall.args[0] expect(event.level.toString()).to.be.equal 'ERROR' - expect(event.data).to.be.deep.equal ['Syntax error in config file!\nUnexpected token ='] + expect(event.data).to.be.deep.equal ["Error in config file!\n", + new SyntaxError('Unexpected token =')] expect(mocks.process.exit).to.have.been.calledWith 1 @@ -200,12 +189,6 @@ describe 'config', -> expect(config.require).to.not.exist - it 'should export __filename and __dirname of the config file in the config context', -> - config = e.parseConfig '/home/config5.js', {} - expect(config.port.f).to.equal '/home/config5.js' - expect(config.port.d).to.equal '/home' - - it 'should normalize urlRoot config', -> config = normalizeConfigWithDefaults {urlRoot: ''} expect(config.urlRoot).to.equal '/'