Skip to content

Commit 4bdc212

Browse files
committed
Setting up test environment (Karma + Mocha) for Leaflet.Draw.
-added Leaflet and testing dependencies to package.json -added spec folder + test libraries -added 'test' task to build.js and package.json -added karma config file (spec/karma.conf.js) and some miscellaneous spec helpers (leaflet-draw-include.js, leaflet-include.js, leaflet-deps.js)
1 parent 19a1490 commit 4bdc212

15 files changed

+6111
-5
lines changed

Jakefile.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ For a custom build, open build/build.html in the browser and follow the instruct
1414

1515
var build = require('./build/build.js');
1616

17-
desc('Check Leaflet source for errors with JSHint');
17+
desc('Check Leaflet.Draw source for errors with JSHint');
1818
task('lint', build.lint);
1919

20-
desc('Combine and compress Leaflet source files');
20+
desc('Combine and compress Leaflet.Draw source files');
2121
task('build', ['lint'], build.build);
2222

23+
desc('Run PhantomJS tests');
24+
task('test', ['lint'], build.test);
25+
2326
task('default', ['build']);

build/build.js

+34
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ function getFiles(compsBase32) {
6464
return files;
6565
}
6666

67+
exports.getFiles = getFiles;
68+
6769
exports.lint = function () {
6870

6971
var files = getFiles();
@@ -152,4 +154,36 @@ exports.build = function (compsBase32, buildName) {
152154
fs.writeFileSync(path, newCompressed);
153155
console.log('\tSaved to ' + path);
154156
}
157+
155158
};
159+
160+
exports.test = function() {
161+
var karma = require('karma'),
162+
testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};
163+
164+
testConfig.browsers = ['PhantomJS'];
165+
166+
if (isArgv('--chrome')) {
167+
testConfig.browsers.push('Chrome');
168+
}
169+
if (isArgv('--ff')) {
170+
testConfig.browsers.push('Firefox');
171+
}
172+
173+
if (isArgv('--cov')) {
174+
testConfig.preprocessors = {
175+
'../src/**/*.js': 'coverage'
176+
};
177+
testConfig.coverageReporter = {
178+
type : 'html',
179+
dir : 'coverage/'
180+
};
181+
testConfig.reporters = ['coverage'];
182+
}
183+
184+
karma.server.start(testConfig);
185+
186+
function isArgv(optName) {
187+
return process.argv.indexOf(optName) !== -1;
188+
}
189+
};

build/leaflet.draw-include.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(function() {
2+
function getFiles() {
3+
var memo = {},
4+
files = [],
5+
i, src;
6+
7+
function addFiles(srcs) {
8+
for (var j = 0, len = srcs.length; j < len; j++) {
9+
memo[srcs[j]] = true;
10+
}
11+
}
12+
13+
for (i in deps) {
14+
addFiles(deps[i].src);
15+
}
16+
17+
for (src in memo) {
18+
files.push(src);
19+
}
20+
21+
return files;
22+
}
23+
var scripts = getFiles();
24+
25+
function getSrcUrl() {
26+
var scripts = document.getElementsByTagName('script');
27+
for (var i = 0; i < scripts.length; i++) {
28+
var src = scripts[i].src;
29+
if (src) {
30+
var res = src.match(/^(.*)leaflet-include\.js$/);
31+
if (res) {
32+
return res[1] + '../src/';
33+
}
34+
}
35+
}
36+
}
37+
38+
var path = getSrcUrl();
39+
for (var i = 0; i < scripts.length; i++) {
40+
document.writeln("<script src='" + path + scripts[i] + "'></script>");
41+
}
42+
})();

package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
"version": "0.2.0",
44
"description": "Vector drawing plugin for Leaflet",
55
"devDependencies": {
6+
"leaflet:": "git://github.com/Leaflet/Leaflet.git",
67
"jshint": "~1.1.0",
78
"uglify-js": "~2.2.5",
8-
"jake": "~0.5.10"
9+
"jake": "~0.5.10",
10+
"mocha": "~1.9.0",
11+
"karma": "~0.8.0"
912
},
1013
"main": "dist/leaflet.draw.js",
1114
"directories": {
1215
"example": "examples"
1316
},
1417
"scripts": {
15-
"test": "echo \"Error: no test specified\" && exit 1",
16-
"build": "jake"
18+
"build": "jake",
19+
"test": "jake test"
1720
},
1821
"repository": {
1922
"type": "git",

spec/after.js

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

spec/before.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// set up before Leaflet files to test L#noConflict later
2+
L = 'test';
3+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy