diff --git a/karma.conf.js b/karma.conf.js index 479a4e69107..34abd4f20a8 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,5 +1,4 @@ var fs = require("fs"); -var karmaFiles = []; var webpackFileExists = false; var webpackFilePath = __dirname + "/config/WEBPACK"; @@ -16,7 +15,8 @@ var usingWebpack = (process.env.USE_WEBPACK == 'True' || webpackFileExists); // If we're using webpack, we don't want to load all the requirejs stuff; -if(usingWebpack){ +var karmaFiles; +if (usingWebpack) { karmaFiles = [ 'spec/javascripts/support/sinon/sinon-1.17.2.js', 'spec/javascripts/support/axe.js', diff --git a/lib/tasks/js.rake b/lib/tasks/js.rake index b1103c7e79c..0ac8d026d33 100644 --- a/lib/tasks/js.rake +++ b/lib/tasks/js.rake @@ -129,7 +129,10 @@ namespace :js do end puts "--> executing browser tests with Karma" build_runner - system "./node_modules/karma/bin/karma start --browsers Chrome --single-run --reporters progress,#{reporter}" + reporters = ['progress', reporter].reject(&:blank?).join(',') + command = %Q{./node_modules/karma/bin/karma start --browsers Chrome --single-run --reporters #{reporters}} + puts "running karma with command: #{command} on node #{`node -v`}" + system command if $?.exitstatus != 0 puts 'some specs failed' diff --git a/package.json b/package.json index b4a0407d7e2..559a461c01b 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,12 @@ "js-yaml": "^3.4.3", "json-loader": "^0.5.3", "jsx-loader": "0.11.2", - "karma": "~0.13.0", - "karma-chrome-launcher": "^0.2.0", + "karma": "1.1.1", + "karma-chrome-launcher": "^1.0.1", "karma-firework-reporter": "~0.2.4", "karma-phantomjs-launcher": "^1.0.0", - "karma-qunit": "~0.1.1", - "karma-requirejs": "^0.2.2", + "karma-qunit": "~1.1.0", + "karma-requirejs": "^1.0.0", "karma-webpack": "^1.7.0", "lodash": "^3.10.1", "on-build-webpack": "^0.1.0", diff --git a/spec/javascripts/load_tests.js b/spec/javascripts/load_tests.js index 76ba247b387..46b7da08de8 100644 --- a/spec/javascripts/load_tests.js +++ b/spec/javascripts/load_tests.js @@ -1,41 +1,37 @@ -tests = __TESTS__; -// tests = tests.slice(0,50); -// console.log(tests); +var thingsToLoadWithRequireJS = [] +var TEST_REGEXP = /^\/base\/spec\/.*Spec\.js$/i -tests = tests.map(function(test) { - return test.indexOf('spec/javascripts') === 0 ? '../../' + test : test; -}); +// Get a list of all the test files to include +Object.keys(window.__karma__.files).forEach(function (file) { + if (TEST_REGEXP.test(file)) { + // Normalize paths to RequireJS module names so it works with our `baseUrl` below + // eg: converts '/base/spec/javascripts/fooSpec.js' to '../../spec/javascripts/fooSpec' + var normalizedTestModule = file + .replace(/^\/base\//, '../../') + .replace(/\.js$/, '') + thingsToLoadWithRequireJS.push(normalizedTestModule) + } +}) // include the english translations by default, same as would happen in // production via common.js. this saves the test writer from having to stub // translations anytime they need to use code that uses a no-default // translation call (e.g. I18n.t('#date.formats.medium')) with the default // locale -tests.push('translations/_core_en'); +thingsToLoadWithRequireJS.push('translations/_core_en') -window.addEventListener("DOMContentLoaded",function() { - if(!document.getElementById('fixtures')) { - var fixturesDiv = document.createElement('div'); - fixturesDiv.id = 'fixtures'; - document.body.appendChild(fixturesDiv); +window.addEventListener("DOMContentLoaded", function() { + if (!document.getElementById('fixtures')) { + var fixturesDiv = document.createElement('div') + fixturesDiv.id = 'fixtures' + document.body.appendChild(fixturesDiv) } -},false); +}, false) -if(!window.ENV) window.ENV = {}; +if(!window.ENV) window.ENV = {} -if(window.__karma__) { - requirejs.config({ - baseUrl: '/base/public/javascripts', - deps: tests, - callback: window.__karma__.start - }); -} else { - QUnit.config.autostart = false; - requirejs.config({ - baseUrl: '/public/javascripts', - deps: tests, - callback: function() { - QUnit.start(); - } - }); -} +requirejs.config({ + baseUrl: '/base/public/javascripts', + deps: thingsToLoadWithRequireJS, // dynamically load all test files + callback: window.__karma__.start +});