chext
Version:
CHrome EXtension Tester
46 lines (35 loc) • 1.26 kB
JavaScript
mocha.checkLeaks();
mocha.globals(['mochaResults', "__InspectorOverlayPage_html"]);
var runner = mocha.run();
var failedTests = [];
runner.on('end', function(){
window.mochaResults = runner.stats;
window.mochaResults.reports = failedTests;
var msg = {
passed : (failedTests.length === 0) ? true : false
, environment : navigator.userAgent.indexOf("Firefox") !== -1 ? "firefox:"
: navigator.userAgent.indexOf("Chrome") !== -1 ? "chrome:" : null
, results : mochaResults
};
msg.environment += location.hostname === "localhost" ? "https:" : location.protocol;
msg.environment += "content_script:" ;
function finish (){
chrome.runtime.sendMessage([msg, JSON.parse(location.hash.substr(1))]);
}
if (location.hash === "#main_begin")
onhashchange = finish
else
finish();
});
runner.on('fail', logFailure);
function logFailure(test, err){
var flattenTitles = function(test){
var titles = [];
while (test.parent.title){
titles.push(test.parent.title);
test = test.parent;
}
return titles.reverse();
};
failedTests.push({name: test.title, result: false, message: err.message, stack: err.stack, titles: flattenTitles(test) });
};