diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2015-09-01 18:20:08 +0300 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2015-09-01 18:20:08 +0300 |
commit | 97a0164445cb29ffa90f99e67049fabaa2cf9ac4 (patch) | |
tree | 364de85480b4e9b0e61c655125cceeff3b051469 | |
parent | b8009568265d3f5a2c5031151fe6e25fa6930b04 (diff) |
add sample js unit tests
-rw-r--r-- | .travis.yml | 4 | ||||
-rw-r--r-- | Gruntfile.js | 18 | ||||
-rw-r--r-- | js/tests/TestSpec.js | 9 | ||||
-rw-r--r-- | js/tests/mocks/OC.js | 17 | ||||
-rw-r--r-- | js/tests/test-main.js | 3 | ||||
-rw-r--r-- | karma.conf.js | 3 | ||||
-rw-r--r-- | package.json | 1 |
7 files changed, 45 insertions, 10 deletions
diff --git a/.travis.yml b/.travis.yml index 714a19d66..8d66d729d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,12 +33,14 @@ before_script: - cd apps/mail - npm install --deps - npm run-script bower_deps - - ./node_modules/.bin/grunt script: # Test lint - find . -name \*.php -not -path './vendor/*' -exec php -l "{}" \; + # Run js unit tests + - grunt + # Run phpunit tests - cd tests - phpunit --configuration phpunit.xml diff --git a/Gruntfile.js b/Gruntfile.js index 89497d9c2..37e30ac24 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,16 +24,28 @@ module.exports = function(grunt) { config: '.jscsrc', verbose: true } + }, + karma: { + unit: { + configFile: 'karma.conf.js', + autoWatch: true + }, + continuous: { + configFile: 'karma.conf.js', + browsers: ['PhantomJS'], + singleRun: true, + } } - }); - // jscs grunt.loadNpmTasks('grunt-jscs'); // jshint grunt.loadNpmTasks('grunt-contrib-jshint'); + // Karma unit tests + grunt.loadNpmTasks('grunt-karma'); + // Default task - grunt.registerTask('default', ['jscs', 'jshint']); + grunt.registerTask('default', ['jscs', 'jshint', 'karma:continuous']); }; diff --git a/js/tests/TestSpec.js b/js/tests/TestSpec.js index 5bcc0208b..b2e1d67a2 100644 --- a/js/tests/TestSpec.js +++ b/js/tests/TestSpec.js @@ -9,9 +9,12 @@ */ define(['models/account'], function(Account) { - describe("test nothing", function() { - it("should be able to initialize", function() { - expect(1).toEqual(10); + describe("test tests", function() { + it("should pass", function() { + expect(1).toEqual(1); + }); + it("should also pass", function() { + expect(2).toEqual(2); }); }); }); diff --git a/js/tests/mocks/OC.js b/js/tests/mocks/OC.js new file mode 100644 index 000000000..3544f200c --- /dev/null +++ b/js/tests/mocks/OC.js @@ -0,0 +1,17 @@ +/** + * ownCloud - Mail + * + * This file is licensed under the Affero General Public License version 3 or + * later. See the COPYING file. + * + * @author Christoph Wurst <christoph@winzerhof-wurst.at> + * @copyright Christoph Wurst 2015 + */ + +define(function() { + return { + generateUrl: function(url, params) { + return '/app/mail/' + url; + } + }; +}); diff --git a/js/tests/test-main.js b/js/tests/test-main.js index 49a4d734b..6b61dbb02 100644 --- a/js/tests/test-main.js +++ b/js/tests/test-main.js @@ -19,7 +19,8 @@ require.config({ backbone: 'vendor/backbone/backbone', domready: 'vendor/domready/ready.min', handlebars: 'vendor/handlebars/handlebars', - marionette: 'vendor/backbone.marionette/lib/backbone.marionette' + marionette: 'vendor/backbone.marionette/lib/backbone.marionette', + OC: 'tests/mocks/OC' }, shim: { handlebars: { diff --git a/karma.conf.js b/karma.conf.js index 62ad31fe9..f7c4cef63 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -9,13 +9,12 @@ module.exports = function(config) { // list of files / patterns to load in the browser files: [ - '../../core/js/js.js', - '../../core/js/oc-dialogs.js', '../../core/vendor/underscore/underscore.js', '../../core/vendor/jquery/jquery.min.js', '../../core/vendor/handlebars/handlebars.js', {pattern: 'js/*/*.js', included: false}, {pattern: 'js/vendor/backbone/backbone.js', included: false}, + {pattern: 'js/tests/mocks/*.js', included: false}, {pattern: 'js/tests/TestSpec.js', included: false}, 'js/tests/test-main.js', ], diff --git a/package.json b/package.json index 72f90a3c0..98c1bc561 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "requirejs": "^2.1.20" }, "dependencies": { + "grunt-karma": "^0.12.0", "karma-cli": "^0.1.0", "phantomjs": "^1.9.18" } |