Skip to content

Instantly share code, notes, and snippets.

@jpvincent
Created August 26, 2013 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpvincent/6339863 to your computer and use it in GitHub Desktop.
Save jpvincent/6339863 to your computer and use it in GitHub Desktop.
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'
)
);
@jpvincent
Copy link
Author

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment