Skip to content
Browse files

jshinting and fixing tests so they run

  • Loading branch information...
1 parent e52b2ee commit 7eb57a6eef8c613280cecdde1ee560628fc3d3eb @jacobtoye jacobtoye committed Dec 3, 2013
Showing with 149 additions and 124 deletions.
  1. +20 −7 build/build.js
  2. +5 −1 package.json
  3. +13 −11 spec/index.html
  4. +57 −54 spec/karma.conf.js
  5. +5 −6 spec/suites/DrawControlSpec.js
  6. +18 −18 spec/suites/GeometryUtilSpec.js
  7. +9 −7 spec/suites/LatLngUtilSpec.js
  8. +22 −20 spec/suites/SpecHelper.js
View
27 build/build.js
@@ -142,22 +142,32 @@ exports.build = function (callback, compsBase32, buildName) {
});
};
-exports.test = function() {
- var karma = require('karma'),
+exports.test = function(callback) {
+ var karma = require('karma'),
testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
testConfig.browsers = ['PhantomJS'];
+ function isArgv(optName) {
+ return process.argv.indexOf(optName) !== -1;
+ }
+
if (isArgv('--chrome')) {
testConfig.browsers.push('Chrome');
}
+ if (isArgv('--safari')) {
+ testConfig.browsers.push('Safari');
+ }
if (isArgv('--ff')) {
testConfig.browsers.push('Firefox');
}
+ if (isArgv('--ie')) {
+ testConfig.browsers.push('IE');
+ }
if (isArgv('--cov')) {
testConfig.preprocessors = {
- '../src/**/*.js': 'coverage'
+ 'src/**/*.js': 'coverage'
};
testConfig.coverageReporter = {
type : 'html',
@@ -166,9 +176,12 @@ exports.test = function() {
testConfig.reporters = ['coverage'];
}
- karma.server.start(testConfig);
+ console.log('Running tests...');
- function isArgv(optName) {
- return process.argv.indexOf(optName) !== -1;
- }
+ karma.server.start(testConfig, function(exitCode) {
+ if (!exitCode) {
+ console.log('\tTests ran successfully.\n');
+ }
+ callback();
+ });
};
View
6 package.json
@@ -3,11 +3,15 @@
"version": "0.2.2",
"description": "Vector drawing plugin for Leaflet",
"devDependencies": {
+ "leaflet": "~0.7.0",
"jshint": "~2.3.0",
"uglify-js": "~2.4.3",
"jake": "~0.7.4",
"mocha": "~1.14.0",
- "karma": "~0.10.4"
+ "happen": "~0.1.3",
+ "karma": "~0.10.4",
+ "karma-mocha": "~0.1.0",
+ "karma-coverage": "~0.1.3",
},
"main": "dist/leaflet.draw.js",
"directories": {
View
24 spec/index.html
@@ -1,14 +1,14 @@
<!DOCTYPE html>
<html>
<head>
- <meta charset="utf-8">
+ <meta charset="utf-8">
<title>Spec Runner</title>
<link rel="stylesheet" type="text/css" href="../node_modules/mocha/mocha.css">
</head>
<body>
- <div id="mocha"></div>
- <script src="expect.js"></script>
- <script type="text/javascript" src="../node_modules/mocha/mocha.js"></script>
+ <div id="mocha"></div>
+ <script src="expect.js"></script>
+ <script type="text/javascript" src="../node_modules/mocha/mocha.js"></script>
<script type="text/javascript" src="happen.js"></script>
<script type="text/javascript" src="sinon.js"></script>
@@ -19,18 +19,20 @@
<script type="text/javascript" src="../build/deps.js"></script>
<script type="text/javascript" src="../build/leaflet.draw-include.js"></script>
- <script>
- mocha.setup('bdd');
- mocha.ignoreLeaks();
- </script>
+ <script>
+ mocha.setip({
+ ui: 'bdd',
+ ignoreLeaks: true
+ });
+ </script>
<!-- spec files -->
<script type="text/javascript" src="suites/DrawControlSpec.js"></script>
- <script>
- (window.mochaPhantomJS || window.mocha).run();
- </script>
+ <script>
+ (window.mochaPhantomJS || window.mocha).run();
+ </script>
</body>
</html>
View
111 spec/karma.conf.js
@@ -1,69 +1,72 @@
// Karma configuration
-var libSources = require(__dirname+'/../build/build.js').getFiles();
-var leafletSources = require(__dirname+'/../node_modules/Leaflet/build/build.js').getFiles();
+module.exports = function (config) {
-// base path, that will be used to resolve files and exclude
-basePath = '';
+ var libSources = require(__dirname+'/../build/build.js').getFiles();
+ var leafletSources = require(__dirname+'/../node_modules/Leaflet/build/build.js').getFiles();
-for (var i=0; i < libSources.length; i++) {
- libSources[i] = "../" + libSources[i];
-}
+ for (var i=0; i < leafletSources.length; i++) {
+ leafletSources[i] = __dirname+"/../node_modules/Leaflet/" + leafletSources[i];
+ }
-for (var i=0; i < leafletSources.length; i++) {
- leafletSources[i] = "../node_modules/Leaflet/" + leafletSources[i]
-}
+ var files = [
+ "spec/before.js",
+ "spec/sinon.js",
+ "spec/expect.js"
+ ].concat(leafletSources, libSources, [
+ "spec/after.js",
+ "node_modules/happen/happen.js",
+ "spec/suites/SpecHelper.js",
+ "spec/suites/**/*.js",
+ {pattern: "dist/images/*.png", included: false}
+ ]);
-// list of files / patterns to load in the browser
-files = [].concat([
- "../node_modules/mocha/mocha.js",
- MOCHA_ADAPTER,
- "before.js",
- "sinon.js",
- "expect.js"
-], leafletSources, libSources, [
- "after.js",
- "happen.js",
- "suites/SpecHelper.js",
- "suites/**/*.js"
-]);
+ config.set({
+ // base path, that will be used to resolve files and exclude
+ basePath: '../',
-// list of files to exclude
-exclude = [
-];
+ plugins: [
+ 'karma-mocha',
+ 'karma-phantomjs-launcher'],
-// test results reporter to use
-// possible values: 'dots', 'progress', 'junit'
-reporters = ['dots'];
+ // frameworks to use
+ frameworks: ['mocha'],
-// web server port
-port = 8080;
+ // list of files / patterns to load in the browser
+ files: files,
+ exclude: [],
-// cli runner port
-runnerPort = 9100;
+ // test results reporter to use
+ // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
+ reporters: ['dots'],
-// enable / disable colors in the output (reporters and logs)
-colors = true;
+ // web server port
+ port: 9876,
-// level of logging
-// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
-logLevel = LOG_WARN;
+ // level of logging
+ // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
+ logLevel: config.LOG_WARN,
-// enable / disable watching file and executing tests whenever any file changes
-autoWatch = false;
+ // enable / disable colors in the output (reporters and logs)
+ colors: true,
-// Start these browsers, currently available:
-// - Chrome
-// - ChromeCanary
-// - Firefox
-// - Opera
-// - Safari (only Mac)
-// - PhantomJS
-// - IE (only Windows)
-browsers = ['PhantomJS'];
+ // enable / disable watching file and executing tests whenever any file changes
+ autoWatch: false,
-// If browser does not capture in given timeout [ms], kill it
-captureTimeout = 5000;
+ // Start these browsers, currently available:
+ // - Chrome
+ // - ChromeCanary
+ // - Firefox
+ // - Opera
+ // - Safari (only Mac)
+ // - PhantomJS
+ // - IE (only Windows)
+ browsers: ['PhantomJS'],
-// Continuous Integration mode
-// if true, it capture browsers, run tests and exit
-singleRun = true;
+ // If browser does not capture in given timeout [ms], kill it
+ captureTimeout: 5000,
+
+ // Continuous Integration mode
+ // if true, it capture browsers, run tests and exit
+ singleRun: true
+ });
+};
View
11 spec/suites/DrawControlSpec.js
@@ -1,15 +1,14 @@
-describe("Control.Draw", function(){
+describe("Control.Draw", function () {
var map, control, container;
- beforeEach(function(){
+ beforeEach(function () {
map = L.map(document.createElement('div'));
- control = new L.Control.Draw({
-
- }).addTo(map);
+ control = new L.Control.Draw({});
+ map.addControl(control);
container = control.getContainer();
});
- it("exists", function() {
+ it("exists", function () {
expect(container.innerHTML).to.be.ok();
});
});
View
36 spec/suites/GeometryUtilSpec.js
@@ -1,25 +1,25 @@
-describe("L.GeometryUtil", function(){
+describe("L.GeometryUtil", function () {
var map, control, container;
- it("geodesicArea", function() {
+ it("geodesicArea", function () {
expect(L.GeometryUtil.geodesicArea([
- { lat: 0, lng: 0 },
- { lat: 0, lng: 10 },
- { lat: 10, lng: 10 },
- { lat: 10, lng: 0 },
- { lat: 0, lng: 0 }
- ])).to.eql(1232921098571.292);
+ { lat: 0, lng: 0 },
+ { lat: 0, lng: 10 },
+ { lat: 10, lng: 10 },
+ { lat: 10, lng: 0 },
+ { lat: 0, lng: 0 }
+ ])).to.eql(1232921098571.292);
});
- describe("readableDistance", function() {
- it("metric", function() {
- expect(L.GeometryUtil.readableDistance(1000, true)).to.eql('1000 m');
- expect(L.GeometryUtil.readableDistance(1500, true)).to.eql('1.50 km');
- });
+ describe("readableDistance", function () {
+ it("metric", function () {
+ expect(L.GeometryUtil.readableDistance(1000, true)).to.eql('1000 m');
+ expect(L.GeometryUtil.readableDistance(1500, true)).to.eql('1.50 km');
+ });
- it("imperial", function() {
- expect(L.GeometryUtil.readableDistance(1609.3488537961)).to.eql('1760 yd');
- expect(L.GeometryUtil.readableDistance(1610.3488537961)).to.eql('1.00 miles');
- });
- });
+ it("imperial", function () {
+ expect(L.GeometryUtil.readableDistance(1609.3488537961)).to.eql('1760 yd');
+ expect(L.GeometryUtil.readableDistance(1610.3488537961)).to.eql('1.00 miles');
+ });
+ });
});
View
16 spec/suites/LatLngUtilSpec.js
@@ -1,9 +1,11 @@
-describe("L.LatLngUtil", function(){
- it("cloneLatLngs", function() {
- var latLngs = [{ lat: 0, lng: 0 }];
- var clone = L.LatLngUtil.cloneLatLngs(latLngs);
- expect(clone[0].lat).to.eql(latLngs[0].lat);
- clone[0].lat = 10;
- expect(latLngs[0].lat).to.eql(0);
+describe("L.LatLngUtil", function () {
+ it("cloneLatLngs", function () {
+ var latLngs = [{ lat: 0, lng: 0 }],
+ clone = L.LatLngUtil.cloneLatLngs(latLngs);
+
+ expect(clone[0].lat).to.eql(latLngs[0].lat);
+
+ clone[0].lat = 10;
+ expect(latLngs[0].lat).to.eql(0);
});
});
View
42 spec/suites/SpecHelper.js
@@ -1,26 +1,28 @@
-function noSpecs() {
- xit('has no specs');
-}
-
if (!Array.prototype.map) {
- Array.prototype.map = function(fun /*, thisp */) {
- "use strict";
+ Array.prototype.map = function (fun /*, thisp */) {
+ "use strict";
+
+ if (this === void 0 || this === null) {
+ throw new TypeError();
+ }
+
+ var t = Object(this),
+ // jshint bitwise: false
+ len = t.length >>> 0;
- if (this === void 0 || this === null)
- throw new TypeError();
+ if (typeof fun !== 'function') {
+ throw new TypeError();
+ }
- var t = Object(this);
- var len = t.length >>> 0;
- if (typeof fun !== "function")
- throw new TypeError();
+ var res = new Array(len),
+ thisp = arguments[1];
- var res = new Array(len);
- var thisp = arguments[1];
- for (var i = 0; i < len; i++) {
- if (i in t)
- res[i] = fun.call(thisp, t[i], i, t);
- }
+ for (var i = 0; i < len; i++) {
+ if (i in t) {
+ res[i] = fun.call(thisp, t[i], i, t);
+ }
+ }
- return res;
- };
+ return res;
+ };
}

0 comments on commit 7eb57a6

Please sign in to comment.
Something went wrong with that request. Please try again.