Add unit test stuff. Current test is just stolen from leaflet, but we'll fix that soon :)

This commit is contained in:
danzel
2013-06-14 10:58:48 +12:00
parent b11665eb83
commit fc39349b3f
8 changed files with 5708 additions and 0 deletions

2
spec/after.js Normal file
View File

@ -0,0 +1,2 @@
// put after Leaflet files as imagePath can't be detected in a PhantomJS env
L.Icon.Default.imagePath = "../dist/images";

1253
spec/expect.js Normal file

File diff suppressed because it is too large Load Diff

93
spec/happen.js Normal file
View File

@ -0,0 +1,93 @@
// https://github.com/tmcw/happen
!(function(context) {
var h = {};
// Make inheritance bearable: clone one level of properties
function extend(child, parent) {
for (var property in parent) {
if (typeof child[property] == 'undefined') {
child[property] = parent[property];
}
}
return child;
}
h.once = function(x, o) {
var evt;
if (o.type.slice(0, 3) === 'key') {
if (typeof Event === 'function') {
evt = new Event(o.type);
evt.keyCode = o.keyCode || 0;
evt.charCode = o.charCode || 0;
evt.shift = o.shift || false;
evt.meta = o.meta || false;
evt.ctrl = o.ctrl || false;
evt.alt = o.alt || false;
} else {
evt = document.createEvent('KeyboardEvent');
// https://developer.mozilla.org/en/DOM/event.initKeyEvent
// https://developer.mozilla.org/en/DOM/KeyboardEvent
evt[(evt.initKeyEvent) ? 'initKeyEvent'
: 'initKeyboardEvent'](
o.type, // in DOMString typeArg,
true, // in boolean canBubbleArg,
true, // in boolean cancelableArg,
null, // in nsIDOMAbstractView viewArg, Specifies UIEvent.view. This value may be null.
o.ctrl || false, // in boolean ctrlKeyArg,
o.alt || false, // in boolean altKeyArg,
o.shift || false, // in boolean shiftKeyArg,
o.meta || false, // in boolean metaKeyArg,
o.keyCode || 0, // in unsigned long keyCodeArg,
o.charCode || 0 // in unsigned long charCodeArg);
);
}
} else {
evt = document.createEvent('MouseEvents');
// https://developer.mozilla.org/en/DOM/event.initMouseEvent
evt.initMouseEvent(o.type,
true, // canBubble
true, // cancelable
window, // 'AbstractView'
o.clicks || 0, // click count
o.screenX || 0, // screenX
o.screenY || 0, // screenY
o.clientX || 0, // clientX
o.clientY || 0, // clientY
o.ctrl || 0, // ctrl
o.alt || false, // alt
o.shift || false, // shift
o.meta || false, // meta
o.button || false, // mouse button
null // relatedTarget
);
}
x.dispatchEvent(evt);
};
var shortcuts = ['click', 'mousedown', 'mouseup', 'mousemove', 'keydown', 'keyup', 'keypress'],
s, i = 0;
while (s = shortcuts[i++]) {
h[s] = (function(s) {
return function(x, o) {
h.once(x, extend(o || {}, { type: s }));
};
})(s);
}
h.dblclick = function(x, o) {
h.once(x, extend(o || {}, {
type: 'dblclick',
clicks: 2
}));
};
this.happen = h;
if (typeof module !== 'undefined') {
module.exports = this.happen;
}
})(this);

38
spec/index.html Normal file
View File

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>
<head>
<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>
<script type="text/javascript" src="happen.js"></script>
<script type="text/javascript" src="sinon.js"></script>
<script type="text/javascript" src="../node_modules/leaflet/dist/leaflet-src.js"></script>
<!-- source files -->
<script type="text/javascript" src="../src/DistanceGrid.js"></script>
<script type="text/javascript" src="../src/MarkerCluster.js"></script>
<script type="text/javascript" src="../src/MarkerClusterGroup.js"></script>
<script type="text/javascript" src="../src/MarkerCluster.QuickHull.js"></script>
<script type="text/javascript" src="../src/MarkerCluster.Spiderfier.js"></script>
<script>
mocha.setup('bdd');
mocha.ignoreLeaks();
</script>
<!-- spec files -->
<script type="text/javascript" src="suites/SpecHelper.js"></script>
<script type="text/javascript" src="suites/LeafletSpec.js"></script>
<script>
(window.mochaPhantomJS || window.mocha).run();
</script>
</body>
</html>

67
spec/karma.conf.js Normal file
View File

@ -0,0 +1,67 @@
// Karma configuration
var libSources = require(__dirname+'/../build/build.js').getFiles();
var leafletSources = require(__dirname+'/../node_modules/leaflet/build/build.js').getFiles();
// base path, that will be used to resolve files and exclude
basePath = '';
for (var i=0; i < libSources.length; i++) {
libSources[i] = "../" + libSources[i];
}
for (var i=0; i < leafletSources.length; i++) {
leafletSources[i] = "../node_modules/leaflet/" + leafletSources[i];
}
// list of files / patterns to load in the browser
files = [].concat([
"../node_modules/mocha/mocha.js",
MOCHA_ADAPTER,
"sinon.js",
"expect.js"
], leafletSources, libSources, [
"after.js",
"happen.js",
"suites/SpecHelper.js",
"suites/**/*.js"
]);
// list of files to exclude
exclude = [
];
// test results reporter to use
// possible values: 'dots', 'progress', 'junit'
reporters = ['dots'];
// web server port
port = 8080;
// cli runner port
runnerPort = 9100;
// enable / disable colors in the output (reporters and logs)
colors = true;
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel = LOG_WARN;
// enable / disable watching file and executing tests whenever any file changes
autoWatch = false;
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers = ['PhantomJS'];
// 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;

4223
spec/sinon.js Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,6 @@
describe('L#noConflict', function() {
it('restores the previous L value and returns Leaflet namespace', function(){
expect(L.version).to.be.ok();
});
});

26
spec/suites/SpecHelper.js Normal file
View File

@ -0,0 +1,26 @@
function noSpecs() {
xit('has no specs');
}
if (!Array.prototype.map) {
Array.prototype.map = function(fun /*, thisp */) {
"use strict";
if (this === void 0 || this === null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function")
throw new TypeError();
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);
}
return res;
};
}