Created
August 26, 2013 09:54
-
-
Save jpvincent/6339863 to your computer and use it in GitHub Desktop.
This file contains 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
function makeMochaToBrowserScopeCallback ( testKey, sandboxid) { | |
'use strict'; | |
return function mochaToBrowserScopeCallback () { | |
var sendToBenchmark = {}; | |
console.log( mocha.globals('runner').suite ); | |
function applatir (suite) { | |
// extraction des résultats des tests | |
var title; | |
for (var i = 0; i < suite.tests.length; i++) { | |
title = suite.tests[i].title; | |
title = title.replace(/[^a-zA-Z ]/, ''); | |
sendToBenchmark[ title ] = (suite.tests[i].state === 'passed')?0:1; | |
} | |
// on descend encore d'un niveau, recursivité FTW | |
if (suite.suites.length > 0) { | |
for (i = 0; i < suite.suites.length; i++) { | |
applatir(suite.suites[i]); | |
} | |
} | |
} | |
applatir(mocha.globals('runner').suite); | |
console.log( sendToBenchmark ); | |
window._bTestResults = sendToBenchmark; | |
// Beacon the results to Browserscope. | |
(function(document) { | |
var newScript = document.createElement('script'), | |
firstScript = document.getElementsByTagName('script')[0]; | |
newScript.src = 'http://www.browserscope.org/user/beacon/' + testKey; | |
// + (sandboxid)?'?sandboxid='+sandboxid:''; | |
firstScript.parentNode.insertBefore(newScript, firstScript); | |
}(document)); | |
}; | |
} | |
// USAGE | |
mocha.run( | |
makeMochaToBrowserScopeCallback( | |
'mykey', // JPV key | |
'mysandboxId' | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is a snippet of code I wrote to make the bridge between mocha tests and browserscope.
It simply flatten the tests results and convert "passed" to 0 or 1. The method has to be given to mocha.run()