Skip to content

Commit

Permalink
GH-665 Add Unit Tests
Browse files Browse the repository at this point in the history
Add unitTesting using mocha, chai and phantomjs.

Fixes GH-665

Signed-off-by: Anmol Jagetia <anmoljagetia@gmail.com>
  • Loading branch information
anmoljagetia committed Aug 9, 2015
1 parent 9f7fbf3 commit 550d10f
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 17 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -5,4 +5,5 @@ before_script:
- npm install -g bower
- npm install -g gulp
- bower install
after_script:
- gulp
22 changes: 12 additions & 10 deletions gulpfile.js
Expand Up @@ -16,14 +16,15 @@ const bump = require('gulp-bump');
const argv = require('yargs').argv;
const filter = require('gulp-filter');
const tag_version = require('gulp-tag-version');
const jscs = require('gulp-jscs');
const jshint = require('gulp-jshint');
const mochaPhantomJS = require('gulp-mocha-phantomjs');

// Consts
const cfg = {
src: 'src',
dist: 'dist',
distamd: 'dist-amd',
test: 'test',
prefix: "hpcc-viz"
};

Expand Down Expand Up @@ -85,14 +86,6 @@ gulp.task('build-css', css.bind(null, false));

gulp.task('optimize-css', css.bind(null, true));

gulp.task('jscs', function() {
gutil.log("JSCS the files...." + '\n');
var lintFilter = filter(["**", "!config.js", "!map/us-counties.js", "!map/us-states.js", "!map/countries.js"]);
return gulp.src(cfg.src + '/**/*.js')
.pipe(jscs())
;
});

gulp.task('lint', function () {
var lintFilter = filter(["**", "!config.js", "!map/us-counties.js", "!map/us-states.js", "!map/countries.js"]);
return gulp.src(cfg.src + '/**/*.js')
Expand All @@ -103,6 +96,15 @@ gulp.task('lint', function () {
;
});

gulp.task('unitTest', function () {
return gulp
.src(cfg.test + '/runner.html') // This will fail if any HTML file has a BOM.
.pipe(mochaPhantomJS({ reporter: 'spec' }))
;
});

gulp.task("test", ["lint", "unitTest"]);

gulp.task('build-nonamd', ['build-css', 'optimize-css'], function (cb) {
async.each(bundles, buildModule, cb);
});
Expand Down Expand Up @@ -223,4 +225,4 @@ gulp.task("tag-release", ["tag"], function (cb) {
var version = require("./package.json").version;
var target = argv.upstream ? "upstream" : "origin"
git.push(target, 'v' + version, cb);
});
});
13 changes: 7 additions & 6 deletions package.json
Expand Up @@ -3,7 +3,6 @@
"version": "1.3.0",
"description": "HPCC Visualization Framework",
"devDependencies": {
"fs": "^0.0.2",
"async": "^0.9.0",
"gulp": "^3.8.11",
"gulp-concat-css": "^2.2.0",
Expand All @@ -21,18 +20,20 @@
"gulp-filter": "^2.0.2",
"gulp-tag-version": "^1.2.1",
"yargs": "^3.8.0",
"jshint-stylish": "~1.0.2",
"gulp-jshint": "~1.10.0",
"gulp-jscs": "~1.6.0"
"jshint-stylish": "^2.0.1",
"gulp-jshint": "^1.11.2",
"gulp-mocha-phantomjs": "^0.8.1",
"mocha": "^2.2.5",
"chai": "^3.2.0"
},
"repository": {
"type": "git",
"url": "https://github.com/hpcc-systems/Visualization"
},
"scripts": {
"test": "gulp lint"
"test": "gulp test"
},
"author": "HPCC Systems",
"license": "Apache",
"homepage": "https://github.com/hpcc-systems/Visualization"
}
}
2 changes: 1 addition & 1 deletion src/common/Menu.js
Expand Up @@ -122,4 +122,4 @@
};

return Menu;
}));
}));
96 changes: 96 additions & 0 deletions test/runner.html
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html>
<head>
<title>HPCC Visualization Unit Tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
<body>
<div id="mocha"></div>
<script src="../node_modules/mocha/mocha.js"></script>
<script src="../node_modules/chai/chai.js"></script>

<script src="../bower_components/requirejs/require.js"></script>
<script src="../src/config.js"></script>
<script>
mocha.setup('bdd');
var assert = chai.assert;
var allWidgets = [
{ path: "src/common/FAChar" },
{ path: "src/common/Icon" },
{ path: "src/common/List" },
{ path: "src/common/Menu" },
{ path: "src/common/ResizeSurface" },
{ path: "src/common/Shape" },
{ path: "src/common/Surface" },
{ path: "src/common/Text" },
{ path: "src/common/TextBox" },
{ path: "src/chart/Area" },
{ path: "src/chart/Bubble" },
{ path: "src/chart/Column" },
{ path: "src/chart/Line" },
{ path: "src/chart/MultiChart" },
{ path: "src/chart/MultiChartSurface" },
{ path: "src/chart/Pie" },
{ path: "src/chart/Scatter" },
{ path: "src/chart/Step" },
{ path: "src/chart/Summary" },
{ path: "src/form/Form" },
{ path: "src/form/Input" },
{ path: "src/form/Slider" },
{ path: "src/map/ChoroplethCounties" },
{ path: "src/map/ChoroplethCountries" },
{ path: "src/map/ChoroplethStates" },
{ path: "src/map/GMap" },
{ path: "src/tree/CirclePacking" },
{ path: "src/tree/Dendrogram" },
{ path: "src/tree/SunburstPartition" },
{ path: "src/graph/Edge" },
{ path: "src/graph/Graph" },
{ path: "src/graph/Vertex" },
{ path: "src/other/MorphText" },
{ path: "src/other/Table" },
{ path: "src/other/WordCloud" },
{ path: "src/marshaller/HTML" },
{ path: "src/marshaller/Graph" },
{ path: "src/layout/Surface" },
{ path: "src/layout/Cell" },
{ path: "src/layout/Grid" },
{ path: "src/layout/Border" },
{ path: "src/c3chart/Area" },
{ path: "src/c3chart/Bar" },
{ path: "src/c3chart/Column" },
{ path: "src/c3chart/Donut" },
{ path: "src/c3chart/Gauge" },
{ path: "src/c3chart/Line" },
{ path: "src/c3chart/Pie" },
{ path: "src/c3chart/Scatter" },
{ path: "src/c3chart/Step" },
{ path: "src/google/Area" },
{ path: "src/google/Bar" },
{ path: "src/google/Column" },
{ path: "src/google/Line" },
{ path: "src/google/Pie" },
{ path: "src/google/Scatter" },
{ path: "src/google/Timeline" },
{ path: "src/google/TreeMap" },
{ path: "src/amchart/Area" },
{ path: "src/amchart/Bar" },
{ path: "src/amchart/Bubble" },
{ path: "src/amchart/Candle" },
{ path: "src/amchart/FloatingColumn" },
{ path: "src/amchart/Funnel" },
{ path: "src/amchart/Gauge" },
{ path: "src/amchart/Line" },
{ path: "src/amchart/Pie" },
{ path: "src/amchart/Polar" },
{ path: "src/amchart/Pyramid" },
{ path: "src/amchart/Scatter" }
]
require(["./widgets"], function () {
mocha.run();
});
</script>
</body>
</html>
23 changes: 23 additions & 0 deletions test/widgets.js
@@ -0,0 +1,23 @@
"use strict";
define(["require"], function (require) {
describe("widgets", function () {
allWidgets.forEach(function (widget) {
var path = widget.path;
describe(path, function () {
it("require load", function (done) {
require([path], function (Widget) {
done();
});
});

it("features", function (done) {
require([path], function (Widget) {
assert.isFunction(Widget);
assert.isFunction(Widget.prototype.constructor, "constructor");
done();
});
});
});
});
});
});

0 comments on commit 550d10f

Please sign in to comment.