Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test environment #123

Merged
merged 4 commits into from
Apr 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ For a custom build, open build/build.html in the browser and follow the instruct

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

desc('Check Leaflet source for errors with JSHint');
desc('Check Leaflet.Draw source for errors with JSHint');
task('lint', build.lint);

desc('Combine and compress Leaflet source files');
desc('Combine and compress Leaflet.Draw source files');
task('build', ['lint'], build.build);

desc('Run PhantomJS tests');
task('test', ['lint'], build.test);

task('default', ['build']);
34 changes: 34 additions & 0 deletions build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function getFiles(compsBase32) {
return files;
}

exports.getFiles = getFiles;

exports.lint = function () {

var files = getFiles();
Expand Down Expand Up @@ -152,4 +154,36 @@ exports.build = function (compsBase32, buildName) {
fs.writeFileSync(path, newCompressed);
console.log('\tSaved to ' + path);
}

};

exports.test = function() {
var karma = require('karma'),
testConfig = {configFile : __dirname + '/../spec/karma.conf.js'};

testConfig.browsers = ['PhantomJS'];

if (isArgv('--chrome')) {
testConfig.browsers.push('Chrome');
}
if (isArgv('--ff')) {
testConfig.browsers.push('Firefox');
}

if (isArgv('--cov')) {
testConfig.preprocessors = {
'../src/**/*.js': 'coverage'
};
testConfig.coverageReporter = {
type : 'html',
dir : 'coverage/'
};
testConfig.reporters = ['coverage'];
}

karma.server.start(testConfig);

function isArgv(optName) {
return process.argv.indexOf(optName) !== -1;
}
};
42 changes: 42 additions & 0 deletions build/leaflet.draw-include.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(function() {
function getFiles() {
var memo = {},
files = [],
i, src;

function addFiles(srcs) {
for (var j = 0, len = srcs.length; j < len; j++) {
memo[srcs[j]] = true;
}
}

for (i in deps) {
addFiles(deps[i].src);
}

for (src in memo) {
files.push(src);
}

return files;
}
var scripts = getFiles();

function getSrcUrl() {
var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) {
var src = scripts[i].src;
if (src) {
var res = src.match(/^(.*)leaflet.draw-include\.js$/);
if (res) {
return res[1] + '../src/';
}
}
}
}

var path = getSrcUrl();
for (var i = 0; i < scripts.length; i++) {
document.writeln("<script src='" + path + scripts[i] + "'></script>");
}
})();
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
"name": "leaflet-draw",
"version": "0.2.0",
"description": "Vector drawing plugin for Leaflet",
"devDependencies": {
"leaflet:": "git://github.com/Leaflet/Leaflet.git",
"jshint": "~1.1.0",
"uglify-js": "~2.2.5",
"jake": "~0.5.10",
"mocha": "~1.9.0",
"karma": "~0.8.0"
},
"main": "dist/leaflet.draw.js",
"directories": {
"example": "examples"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"build": "jake",
"test": "jake test"
},
"repository": {
"type": "git",
Expand Down
2 changes: 2 additions & 0 deletions spec/after.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// put after Leaflet files as imagePath can't be detected in a PhantomJS env
L.Icon.Default.imagePath = "../dist/images";
3 changes: 3 additions & 0 deletions spec/before.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// set up before Leaflet files to test L#noConflict later
L = 'test';

Loading