Created
September 8, 2012 22:53
-
-
Save brentkirby/3680646 to your computer and use it in GitHub Desktop.
Run raw coffeescript specs in browser with jasmine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Make sure coffeescript.js, jasmine, and all other dependencies are loaded, | |
* then assign a global "specs" variable which is an array of file names in | |
* your spec/ folder. | |
* | |
* window.specs = ['index']; | |
* | |
*/ | |
(function() { | |
var jasmineEnv, htmlReporter, loaded, ran = false; | |
loaded = []; | |
jasmineEnv = jasmine.getEnv(); | |
jasmineEnv.updateInterval = 1000; | |
htmlReporter = new jasmine.HtmlReporter(); | |
jasmineEnv.addReporter(htmlReporter); | |
jasmineEnv.specFilter = function(spec) { | |
return htmlReporter.specFilter(spec); | |
}; | |
window.onload = loadSpecs; | |
function loadSpecs(){ | |
jQuery.each(specs, function(ind, file){ | |
var toload = "spec/" + file + "_spec.coffee"; | |
if( loaded.indexOf(toload) == -1 ){ | |
loaded.push(toload); | |
CoffeeScript.load(toload, finish); | |
} | |
}); | |
} | |
function finish(){ | |
if( loaded.length == specs.length ) | |
runem(); | |
} | |
function runem(){ | |
if( ran == true ) return; | |
ran = true; | |
// without a slight delay, jasmine will error for some reason. | |
setTimeout(function(){ | |
jasmineEnv.execute(); | |
}, 200); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment