Add karma testing
This patch adds configuration for Karma. Change-Id: Ibb65060836f967ac81a57ea279d7fa494e238d49 Implements blueprint: merlin-unittests
This commit is contained in:
parent
1454a2792d
commit
05451e3e59
63
Gruntfile.js
Normal file
63
Gruntfile.js
Normal file
@ -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'
|
||||
]);
|
||||
};
|
22
bin/nodeenv.sh
Normal file
22
bin/nodeenv.sh
Normal file
@ -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
|
25
bower.json
Normal file
25
bower.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
54
karma-unit.conf.js
Normal file
54
karma-unit.conf.js
Normal file
@ -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
|
||||
});
|
||||
};
|
33
merlin/test/js/utilsSpec.js
Normal file
33
merlin/test/js/utilsSpec.js
Normal file
@ -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]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
22
nodeenv.sh
Normal file
22
nodeenv.sh
Normal file
@ -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
|
35
package.json
Normal file
35
package.json
Normal file
@ -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"
|
||||
}
|
||||
}
|
19
tox.ini
Normal file
19
tox.ini
Normal file
@ -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}
|
Loading…
Reference in New Issue
Block a user