diff --git a/.gitignore b/.gitignore index 5532bb95b..a560f21c9 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ build/artifacts nbproject/ translations.js + +# JS coverage +coverage/ diff --git a/js/tests/test-main.js b/js/tests/test-main.js index 6bd82bd35..1f7318aea 100644 --- a/js/tests/test-main.js +++ b/js/tests/test-main.js @@ -1,4 +1,5 @@ var allTestFiles = []; +var allModules = []; var TEST_REGEXP = /(spec|test)\.js$/i; // Get a list of all the test files to include @@ -8,10 +9,46 @@ Object.keys(window.__karma__.files).forEach(function(file) { // If you require sub-dependencies of test files to be loaded as-is (requiring file extension) // then do not normalize the paths var normalizedTestModule = file.replace(/^\/base\/js\/|\.js$/g, ''); - allTestFiles.push(normalizedTestModule); + if (normalizedTestModule.substring(0, 'tests'.length) === 'tests') { + allTestFiles.push(normalizedTestModule); + } + } else { + var excluded = ['OC', 'autoredirect', 'searchproxy', 'app']; + var normalizedModule = file.replace(/^\/base\/js\/|\.js$/g, ''); + if (normalizedModule.substring(0, '/base/js/'.length) === '/base/js/') { + normalizedModule = normalizedModule.substring('/base/js/'.length); + } + if (normalizedModule.substring(0, 'vendor'.length) === 'vendor') { + return; + } + if (normalizedModule.substring(0, 'templates'.length) === 'templates') { + return; + } + if (normalizedModule.substring(0, '/base/node_modules'.length) === '/base/node_modules') { + return; + } + if (excluded.indexOf(normalizedModule) !== -1) { + return; + } + allModules.push(normalizedModule); } }); + +OC = { + Notification: { + showTemporary: function() { + + } + }, + generateUrl: function(url) { + return url; + }, + linkToRemote: function() { + + } +}; + require.config({ // Karma serves files under /base, which is the basePath from your config file baseUrl: '/base/js', @@ -39,16 +76,7 @@ require.config({ } }, // dynamically load all test files - deps: allTestFiles, + deps: allTestFiles.concat(allModules), // we have to kickoff jasmine, as it is asynchronous callback: window.__karma__.start }); - -// Define Mock for modules that do not exist while testing -define('OC', [], function() { - return { - generateUrl: function(url) { - return url; - } - } -}); diff --git a/karma.conf.js b/karma.conf.js index 2aaf92c3a..dfca174e5 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -10,15 +10,10 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ 'js/vendor/jquery/dist/jquery.js', - {pattern: 'js/*/*.js', included: false}, + {pattern: 'js/**/*.js', included: false}, {pattern: 'js/*.js', included: false}, {pattern: 'js/templates/*.html', included: false}, - {pattern: 'js/vendor/backbone/backbone.js', included: false}, - {pattern: 'js/vendor/backbone.marionette/lib/backbone.marionette.js', included: false}, - {pattern: 'js/vendor/backbone.radio/build/backbone.radio.js', included: false}, - {pattern: 'js/vendor/handlebars/handlebars.js', included: false}, - {pattern: 'js/vendor/text/text.js', included: false}, - {pattern: 'js/vendor/underscore/underscore.js', included: false}, + {pattern: 'js/vendor/**/*.js', included: false}, {pattern: 'js/tests/*.js', included: false}, 'js/tests/test-main.js' ], @@ -31,11 +26,16 @@ module.exports = function(config) { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { + 'js/**[!vendor]/*[!spec].js': ['coverage'] }, // test results reporter to use // possible values: 'dots', 'progress' // available reporters: https://npmjs.org/browse/keyword/karma-reporter - reporters: ['progress'], + reporters: ['progress', 'coverage'], + coverageReporter: { + type: 'text-summary', + dir: 'coverage/' + }, // web server port port: 9876, // enable / disable colors in the output (reporters and logs) diff --git a/package.json b/package.json index 7a53d2729..2b4f0d29b 100644 --- a/package.json +++ b/package.json @@ -29,11 +29,13 @@ "grunt-contrib-jshint": "^0.11.3", "grunt-jscs": "^1.8.0", "grunt-karma": "^0.12.1", + "istanbul": "^0.4.5", "jasmine-core": "^2.5.2", "jscs-jsdoc": "^1.0.1", "jshint": "^2.7.0", "jsxhint": "^0.14.0", "karma": "^1.3.0", + "karma-coverage": "^1.1.1", "karma-jasmine": "^1.0.2", "karma-phantomjs-launcher": "^1.0.2", "karma-requirejs": "^1.1.0",