From 05451e3e59ed647625dd1d1e9a433e6d42f43049 Mon Sep 17 00:00:00 2001 From: Paul Karikh Date: Tue, 7 Apr 2015 14:57:40 +0300 Subject: [PATCH] Add karma testing This patch adds configuration for Karma. Change-Id: Ibb65060836f967ac81a57ea279d7fa494e238d49 Implements blueprint: merlin-unittests --- Gruntfile.js | 63 +++++++++++++++++++++++++++++++++++++ bin/nodeenv.sh | 22 +++++++++++++ bower.json | 25 +++++++++++++++ karma-unit.conf.js | 54 +++++++++++++++++++++++++++++++ merlin/test/js/utilsSpec.js | 33 +++++++++++++++++++ nodeenv.sh | 22 +++++++++++++ package.json | 35 +++++++++++++++++++++ tox.ini | 19 +++++++++++ 8 files changed, 273 insertions(+) create mode 100644 Gruntfile.js create mode 100644 bin/nodeenv.sh create mode 100644 bower.json create mode 100644 karma-unit.conf.js create mode 100644 merlin/test/js/utilsSpec.js create mode 100644 nodeenv.sh create mode 100644 package.json create mode 100644 tox.ini diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000..9112234 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2013 Hewlett-Packard Development Company, L.P. +* +* Licensed 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. +*/ + +module.exports = function(grunt){ + + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + /** + * grunt concat + * + * Creates a single file out of our javascript source in accordance + * with the concatenation priority. First the application module, then + * any dependent module declarations, and finally everything else. + */ + concat: { + dist: { + src: [ + './merlin/static/merlin/js/**/*.js' + ], + dest: './merlin/dist/merlin.js' + } + }, + uglify: { + options: { + mangle: false + }, + my_target: { + files: { + '/merlindist/merlin.min.js': ['dist/merlin.js'] + } + } + }, + karma: { + options: { + // point all tasks to karma config file + configFile: 'karma-unit.conf.js' + }, + unit: { + // run tests once instead of continuously + singleRun: true + } + } + }); + grunt.loadNpmTasks('grunt-karma'); + grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.registerTask('test:unit', [ + 'karma:unit' + ]); +}; diff --git a/bin/nodeenv.sh b/bin/nodeenv.sh new file mode 100644 index 0000000..b82f13c --- /dev/null +++ b/bin/nodeenv.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# This script checks if node is installed in the current path, +# and if not, will install the version specified. using nodeenv -p +# +#command -v node && echo "ok" + +ENVDIR="$1" +VERSION="$2" + +if [[ $(command -v node) ]] +then + exit +fi + +if [[ -n "$VERSION" ]] +then + nodeenv -p "$ENVDIR" --node="$VERSION" +else + nodeenv -p "$ENVDIR" +fi diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..5d4c2fa --- /dev/null +++ b/bower.json @@ -0,0 +1,25 @@ +{ + "name": "merlin", + "version": "0.0.1", + "dependencies": { + "font-awesome": "4.3.0", + "angular": "1.3.10", + "angular-resource": "1.3.10", + "angular-sanitize": "1.3.10", + "bootstrap": "3.3.2", + "angular-ui-router": "0.2.13", + "angular-bootstrap": "0.12.0", + "angular-local-storage": "0.1.5", + "angular-elastic": "2.4.2", + "angular-moment": "0.9.0", + "angular-cache": "3.2.5" + }, + "devDependencies": { + "angular-mocks": "1.3.10", + "angular-scenario": "1.3.10" + }, + "resolutions": { + "angular": "1.3.10", + "font-awesome": "4.3.0" + } +} diff --git a/karma-unit.conf.js b/karma-unit.conf.js new file mode 100644 index 0000000..36b93a3 --- /dev/null +++ b/karma-unit.conf.js @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2013 Hewlett-Packard Development Company, L.P. + * + * Licensed 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. + */ + +module.exports = function (config) { + 'use strict'; + + config.set({ + + port: 9876, + + basePath: '', + + frameworks: ['jasmine'], + + browsers: [ 'PhantomJS'], + + plugins: [ + 'karma-jasmine', + 'karma-phantomjs-launcher', + ], + + files: [ + './bower_components/angular/angular.js', + './bower_components/angular-mocks/angular-mocks.js', + './merlin/static/merlin/js/merlin.init.js', + './merlin/static/merlin/js/merlin.directives.js', + './merlin/static/merlin/js/merlin.field.models.js', + './merlin/static/merlin/js/merlin.panel.models.js', + './merlin/static/merlin/js/merlin.utils.js', + './merlin/static/merlin/js/lib/angular-filter.js', + './merlin/static/merlin/js/lib/barricade.js', + './merlin/static/merlin/js/lib/js-yaml.js', + 'merlin/test/js/utilsSpec.js' + ], + + exclude: [ + ], + + singleRun: true + }); +}; diff --git a/merlin/test/js/utilsSpec.js b/merlin/test/js/utilsSpec.js new file mode 100644 index 0000000..28280da --- /dev/null +++ b/merlin/test/js/utilsSpec.js @@ -0,0 +1,33 @@ +describe('merlin.utils', function() { + 'use strict'; + + var utils; + + beforeEach(function() { + angular.mock.module('merlin'); + angular.mock.inject(function($injector) { + utils = $injector.get('merlin.utils'); + }); + }); + + describe('makeTitle function', function() { + it('should capitalize the first letter of a string', function() { + expect(utils.makeTitle('some string')).toBe('Some string'); + }); + }); + + describe('condense Array method', function() { + it('Array prototype should have condense()', function() { + var array = []; + expect(array.condense).toBeDefined(); + }); + + it('condense() should throw away undefined and null values', function() { + var array = [1, 0, 15, undefined, 7, null, null, 8]; + expect(array.condense()).toEqual([1, 0, 15, 7, 8]); + }); + }); + + + +}); diff --git a/nodeenv.sh b/nodeenv.sh new file mode 100644 index 0000000..b82f13c --- /dev/null +++ b/nodeenv.sh @@ -0,0 +1,22 @@ +#!/bin/bash +set -e + +# This script checks if node is installed in the current path, +# and if not, will install the version specified. using nodeenv -p +# +#command -v node && echo "ok" + +ENVDIR="$1" +VERSION="$2" + +if [[ $(command -v node) ]] +then + exit +fi + +if [[ -n "$VERSION" ]] +then + nodeenv -p "$ENVDIR" --node="$VERSION" +else + nodeenv -p "$ENVDIR" +fi diff --git a/package.json b/package.json new file mode 100644 index 0000000..d6ce4bf --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "name": "SampleGrunt", + "version": "0.1.0", + "private": true, + "devDependencies": { + "bower": "1.3.12", + "grunt": "^0.4.5", + "grunt-bower-task": "^0.4.0", + "grunt-cli": "0.1.13", + "grunt-connect-proxy": "0.1.11", + "grunt-contrib-clean": "0.6.0", + "grunt-contrib-watch": "0.6.1", + "grunt-env": "0.4.1", + "grunt-eslint": "7.0.1", + "grunt-html2js": "0.2.9", + "grunt-karma": "0.9.0", + "grunt-open": "0.2.3", + "grunt-protractor-runner": "1.1.4", + "grunt-shell": "1.1.1", + "grunt-usemin": "2.4.0", + "grunt-webfont": "0.4.8", + "grunt-contrib-concat": "^0.5.1", + "grunt-contrib-uglify": "^0.8.1", + "grunt-karma": "^0.10.1", + "jasmine-core": "^2.2.0", + "karma": "^0.12.31", + "karma-chrome-launcher": "^0.1.7", + "karma-jasmine": "^0.3.5", + "karma-phantomjs-launcher": "^0.1.4" + }, + "main": "Gruntfile.js", + "dependencies": { + "grunt": "^0.4.5" + } +} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..0b77ea5 --- /dev/null +++ b/tox.ini @@ -0,0 +1,19 @@ +[tox] +minversion = 1.6 +skipsdist = True + +[testenv] +whitelist_externals = bash + npm + node + nodejs + bower + grunt + +[testenv:grunt] +deps = nodeenv +commands = + bash ./bin/nodeenv.sh {envdir} 0.10.29 + npm install + {toxinidir}/node_modules/.bin/bower install --config.interactive=false + {toxinidir}/node_modules/.bin/grunt {posargs}