UNPKG

chext

Version:

CHrome EXtension Tester

54 lines (41 loc) 1.6 kB
onload = function(){ location.hash = "main_begin" mocha.checkLeaks(); mocha.globals(['mochaResults', "__InspectorOverlayPage_html","reporter_websocket","background", "testWorker","finishTests"]); 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 += (window.background) ? "background:" : ""; if (location.protocol === "chrome-extension:" && !window.background) chrome.runtime.getBackgroundPage(function(win){ console.log("got background in extensi") win.finishTests(msg) }) else if (location.protocol === "http:"){ location.hash = JSON.stringify(msg); } else { window.relayTestResults([msg]) } }); 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) }); }; };