Got JS tests working
Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/3e9431a4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/3e9431a4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/3e9431a4 Branch: refs/heads/apache-blur-0.2 Commit: 3e9431a4a57c0a68acbea5cb3f405edd7528a592 Parents: 1f49c46 Author: Chris Rohr <[email protected]> Authored: Sun Jun 22 20:30:04 2014 -0400 Committer: Chris Rohr <[email protected]> Committed: Sun Jun 22 20:30:04 2014 -0400 ---------------------------------------------------------------------- blur-console/src/main/webapp/Gruntfile.js | 3 +- .../src/main/webapp/js/blurconsole.utils.js | 2 +- blur-console/src/main/webapp/karma.conf.js | 159 +++++++++---------- blur-console/src/main/webapp/package.json | 8 +- .../src/main/webapp/test/unit/spec/test.js | 32 ---- .../src/main/webapp/test/unit/spec/utils.js | 32 ---- .../src/main/webapp/test/unit/utilsTest.js | 34 ++++ 7 files changed, 122 insertions(+), 148 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/Gruntfile.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/Gruntfile.js b/blur-console/src/main/webapp/Gruntfile.js index f3802b3..5a23d4d 100644 --- a/blur-console/src/main/webapp/Gruntfile.js +++ b/blur-console/src/main/webapp/Gruntfile.js @@ -190,7 +190,8 @@ module.exports = function (grunt) { unit: { configFile: 'karma.conf.js', runnerPort: 9999, - singleRun: true + singleRun: true, + autoWatch: false } }, http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/js/blurconsole.utils.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/js/blurconsole.utils.js b/blur-console/src/main/webapp/js/blurconsole.utils.js index b2eeff8..d7b290c 100644 --- a/blur-console/src/main/webapp/js/blurconsole.utils.js +++ b/blur-console/src/main/webapp/js/blurconsole.utils.js @@ -27,7 +27,7 @@ blurconsole.utils = (function(){ return initial; } - var accumulator = initial || collection[0]; + var accumulator = initial == null ? collection[0] : initial; $.each(collection, function(idx, item) { accumulator = block(accumulator, item); }); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/karma.conf.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/karma.conf.js b/blur-console/src/main/webapp/karma.conf.js index 8d5d69b..e0c9b4f 100644 --- a/blur-console/src/main/webapp/karma.conf.js +++ b/blur-console/src/main/webapp/karma.conf.js @@ -1,85 +1,82 @@ -/* - -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ +// Karma configuration +// Generated on Sat Jun 21 2014 07:42:42 GMT-0400 (EDT) module.exports = function(config) { - // karma start --coverage [coverageType] - // http://karma-runner.github.io/0.8/config/converage.html - - var karmaConfig = { - basePath: '', - frameworks: ['mocha'], - files: [ - // Source - {pattern: 'js/**/*.js', included: false}, - - // Images - {pattern: 'img/**/*.*', included: false}, - - // Included libs - 'libs/jquery/jquery.js', - - // Libraries - {pattern: 'libs/**/*.js', included: false}, - - // Test Files - {pattern: 'test/unit/spec/**/*.js', included: false}, - - // Test Mocks - {pattern: 'test/unit/mocks/**/*.js', included: false}, - {pattern: 'test/unit/utils/**/*.js', included: false}, - - // Test Runner - 'test/unit/runner/testRunner.js' - ], - exclude: [], - reporters: ['dots'], - port: 9876, - colors: true, - logLevel: config.LOG_WARN, - autoWatch: true, - browsers: ['Chrome', 'Firefox'], - captureTimeout: 60000, - singleRun: false + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha', 'chai', 'sinon'], + + + // list of files / patterns to load in the browser + files: [ + 'libs/jquery/dist/jquery.js', + 'js/utils/*\.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/tooltip.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/modal.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/transition.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/popover.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/collapse.js', + 'libs/twbs-bootstrap-sass/vendor/assets/javascripts/bootstrap/tab.js', + 'libs/flot/jquery.flot.js', + 'libs/flot/jquery.flot.pie.js', + 'libs/flot/jquery.flot.categories.js', + 'libs/flot/jquery.flot.stack.js', + 'libs/typeahead.js/dist/typeahead.jquery.js', + 'js/blurconsole.js', + 'js/*\.js', + 'test/**/*Test.js' + ], + + + // list of files to exclude + exclude: [ + + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + 'js/*.js': ['coverage'] }, - coverageType = 'html', - coverage = process.argv.filter(function(a, index) { - if (a == '--coverage') { - if ((index + 1) < process.argv.length) { - coverageType = process.argv[index + 1]; - } - return true; - } - return false; - }).length; - - if (coverage) { - karmaConfig.preprocessors = { - 'js/*.js': 'coverage', - 'js/**/*.js': 'coverage' - }; - karmaConfig.reporters.push('coverage'); - karmaConfig.coverageReporter = { - type: coverageType, - dir: 'build/coverage/' - }; - } - - config.set(karmaConfig); + + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['progress', 'coverage'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG + logLevel: config.LOG_INFO, + + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false + }); }; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/package.json ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/package.json b/blur-console/src/main/webapp/package.json index f534dfa..651fb36 100644 --- a/blur-console/src/main/webapp/package.json +++ b/blur-console/src/main/webapp/package.json @@ -35,7 +35,13 @@ "time-grunt": "~0.2.0", "grunt-contrib-connect": "~0.5.0", "node-version-assets": "~0.2.0", - "grunt-contrib-copy": "~0.5.0" + "grunt-contrib-copy": "~0.5.0", + "karma-html2js-preprocessor": "~0.1.0", + "karma-jasmine": "~0.1.4", + "mocha": "~1.15.1", + "karma-chai": "0.0.2", + "karma-sinon": "~1.0.0", + "karma-coverage": "~0.1.0" }, "scripts": { "test": "karma start --single-run" http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/test/unit/spec/test.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/test/unit/spec/test.js b/blur-console/src/main/webapp/test/unit/spec/test.js deleted file mode 100644 index 9ac8df8..0000000 --- a/blur-console/src/main/webapp/test/unit/spec/test.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ -/* global describe, it */ - -(function () { - 'use strict'; - - describe('Give it some context', function () { - describe('maybe a bit more context here', function () { - it('should run here few assertions', function () { - - }); - }); - }); -})(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/test/unit/spec/utils.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/test/unit/spec/utils.js b/blur-console/src/main/webapp/test/unit/spec/utils.js deleted file mode 100644 index 927567d..0000000 --- a/blur-console/src/main/webapp/test/unit/spec/utils.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. -*/ -/* global describe, it, assert, blurconsole */ - -(function () { - 'use strict'; - - describe('Test blurconsole.utils', function () { - describe('inject', function () { - it('[1,2,3,4,5] should be 15 with simple summing', function () { - assert(blurconsole.utils.inject([1,2,3,4,5], 0, function(sum, item){ return sum + item; })); - }); - }); - }); -})(); http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/3e9431a4/blur-console/src/main/webapp/test/unit/utilsTest.js ---------------------------------------------------------------------- diff --git a/blur-console/src/main/webapp/test/unit/utilsTest.js b/blur-console/src/main/webapp/test/unit/utilsTest.js new file mode 100644 index 0000000..6544f65 --- /dev/null +++ b/blur-console/src/main/webapp/test/unit/utilsTest.js @@ -0,0 +1,34 @@ +/* + +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ +/* global describe, it, expect, blurconsole */ + +'use strict'; + +describe('Test blurconsole.utils', function () { + describe('inject', function () { + it('[1,2,3,4,5] should be 15 with simple summing', function () { + expect(blurconsole.utils.inject([1,2,3,4,5], 0, function(sum, item){ return sum + item; })).to.equal(15); + }); + + it('null collection should return initial value', function() { + expect(blurconsole.utils.inject(null, 0, function(sum, item){ return item; })).to.equal(0); + }); + }); +}); \ No newline at end of file
