diff --git a/.travis.yml b/.travis.yml index 20fd86b6..da8ace68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,7 @@ language: node_js node_js: - - 0.10 + - "0.10" + - "0.8" + - "0.6" +before_script: + - npm install -g grunt-cli diff --git a/Gruntfile.js b/Gruntfile.js index 6aff8a46..9c48124d 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -26,6 +26,12 @@ module.exports = function(grunt) { all: ['Gruntfile.js', '<%= mifosx.app %>/scripts/**/*.js'] }, + karma: { + unit: { + configFile: 'karma.conf.js' + } + }, + //uglify the js files uglify: { options: { @@ -194,6 +200,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-requirejs'); grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-karma'); // Default task(s). @@ -201,5 +208,6 @@ module.exports = function(grunt) { grunt.registerTask('prod', ['clean', 'copy:prod', 'concat', 'uglify:prod']); grunt.registerTask('dev', ['clean', 'copy:dev']); grunt.registerTask('compile', ['jshint']); + grunt.registerTask('test', ['karma']); }; \ No newline at end of file diff --git a/README.md b/README.md index 1ec0856d..b6aba7fe 100644 --- a/README.md +++ b/README.md @@ -77,3 +77,6 @@ Just open test/SpecRunner.html in the browser. ## Contribution guidelines Please read the contribution guidelines + + +Testing diff --git a/karma.conf.js b/karma.conf.js index 2d6194bf..a861e48b 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,56 +1,60 @@ // Karma configuration -// base path, that will be used to resolve files and exclude -basePath = ''; +module.exports = function (config) { + config.set({ + basePath : '', -// list of files / patterns to load in the browser -files = [ - JASMINE, - JASMINE_ADAPTER, - 'app/bower_components/angular/angular.js', - 'app/bower_components/angular-mocks/angular-mocks.js', - 'app/scripts/*.js', - 'app/scripts/**/*.js', - 'test/mock/**/*.js', - 'test/spec/**/*.js' -]; + frameworks : ["jasmine"], -// list of files to exclude -exclude = []; + files : [ + './app/bower_components/angular/angular.js', + './app/bower_components/angular-mocks/angular-mocks.js', + './app/bower_components/underscore/underscore-min.js', + './app/bower_components/requirejs/require.js', + './app/scripts/mifosX.js', + './app/scripts/models/*.js', + './app/scripts/services/*.js', + './app/scripts/directives/*.js', + './app/scripts/controllers/**/*.js', + './test/spec/**/*.js' + ], -// test results reporter to use -// possible values: dots || progress || growl -reporters = ['progress']; + // list of files to exclude + exclude : [], -// web server port -port = 8080; + // test results reporter to use + // possible values: dots || progress || growl + reporters : ['progress'], -// cli runner port -runnerPort = 9100; + // web server port + port : 8080, + + + // cli runner port + runnerPort : 9100, + + // 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, + + autoWatch : false, + + browsers : ['PhantomJS'], + + // If browser does not capture in given timeout [ms], kill it + captureTimeout : 5000, + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun : 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; -// enable / disable watching file and executing tests whenever any file changes -autoWatch = false; -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -browsers = ['Chrome']; -// If browser does not capture in given timeout [ms], kill it -captureTimeout = 5000; -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; diff --git a/package.json b/package.json index 31d683b8..d3e738a2 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,21 @@ "grunt-contrib-clean": "~0.5.0", "grunt-contrib-copy": "~0.4.1", "grunt-contrib-concat": "~0.3.0", - "grunt-contrib-requirejs": "~0.3.1" + "grunt-contrib-requirejs": "~0.3.1", + "karma-script-launcher": "~0.1.0", + "karma-chrome-launcher": "~0.1.1", + "karma-html2js-preprocessor": "~0.1.0", + "karma-firefox-launcher": "~0.1.2", + "karma-jasmine": "~0.1.4", + "requirejs": "~2.1.9", + "karma-requirejs": "~0.2.0", + "karma-coffee-preprocessor": "~0.1.1", + "karma-phantomjs-launcher": "~0.1.1", + "karma": "~0.10.8", + "grunt-karma": "~0.6.2" + }, + "scripts": { + "test": "grunt test --verbose" }, "engines": { "node": ">=0.8.0" diff --git a/test/spec/controllers/LoginFormControllerSpec.js b/test/spec/controllers/LoginFormControllerSpec.js index be6bd273..3beba008 100644 --- a/test/spec/controllers/LoginFormControllerSpec.js +++ b/test/spec/controllers/LoginFormControllerSpec.js @@ -13,7 +13,7 @@ describe("LoginFormController", function() { it("should initialise the login credentials", function() { expect(this.scope.loginCredentials).toEqual({}); }); - + it("should initialise the authenticationFailed flag", function() { expect(this.scope.authenticationFailed).toBeFalsy(); }); diff --git a/test/spec/controllers/MainControllerSpec.js b/test/spec/controllers/MainControllerSpec.js index 80d51fb4..a866cce5 100644 --- a/test/spec/controllers/MainControllerSpec.js +++ b/test/spec/controllers/MainControllerSpec.js @@ -10,7 +10,7 @@ describe("MainController", function() { sessionCallback = callback; }); - this.translate = jasmine.createSpy(); + this.translate = jasmine.createSpyObj("translate", ["uses"]); this.rootScope = jasmine.createSpy(); this.localStorageService = jasmine.createSpyObj("localStorageService", ["get"]); @@ -36,7 +36,7 @@ describe("MainController", function() { describe("on receving 'UserAuthenticationSuccessEvent'", function() { beforeEach(function() { this.sessionManager.get.andReturn("test_session"); - + eventListener({}, "test_data"); }); @@ -52,7 +52,7 @@ describe("MainController", function() { describe("User logout", function() { beforeEach(function() { this.sessionManager.clear.andReturn("test_session"); - + this.scope.logout(); });