Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
QUnit and Browserscope boilerplate code.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="qunit/jquery.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
<script type="text/javascript">
// To save data in Browserscope do something like the following.
// The syntax is 'test_key': 'value' where test_key is some unique
// identifier for a piece of data you want to store (no = or , allowed)
// and value is a numeric value from 0 through 1000000000000.
// Note: You can only send a maximum of 200 results in a beacon.
var _bTestResults = {}
// Add URL option in QUnit to toggle publishing results to BrowserScope.org
QUnit.config.urlConfig.push("publishresults")
// Timeout for async tests
QUnit.config.testTimeout = 1000
// Build-up the test results beacon for BrowserScope.org
QUnit.testDone = function(test){
// make sure all assertions passed successfully
if (!test.failed && test.total === test.passed){
_bTestResults[test.name] = 1
}
else{
_bTestResults[test.name] = 0
}
}
// If the user agreed to publish results to BrowserScope.org, go for it!
QUnit.done = function(){
if (QUnit.config.publishresults){
var testKey = 'CHANGE-THIS-TO-YOUR-TEST-KEY',
newScript = document.createElement('script'),
firstScript = document.getElementsByTagName('script')[0]
newScript.src = 'http://www.browserscope.org/user/beacon/' + testKey + "?callback=showResults"
firstScript.parentNode.insertBefore(newScript, firstScript)
}
}
// Load the results widget from browserscope.org
function showResults(){
var script = document.createElement('script')
script.src = "http://www.browserscope.org/user/tests/table/CHANGE-THIS-TO-YOUR-TEST-KEY?o=js"
document.body.appendChild(script)
}
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment