thrill
Version:
Exciting testing
3 lines • 4.15 kB
JavaScript
/*! thrill - v0.4.0 - 2013-01-21
* Copyright (c) 2013 Ozan Turgut; Licensed Apache License 2.0 */
thrill=function(){var e=function(e,t){return e.exports=t,t.TESTER_MESSAGE_TYPE={start:1,end:2,"suite start":3,"suite end":4,"test start":5,"test end":6,batch:7},e.exports}({},{}),t=function(t,n){function s(e){this.isStreaming=!/(?:\?|\&)disableStream=true(.*)(?:\&|$)/.test(window.location.search)&&!window.THRILL_STREAM_DISABLE,this.batch=[],this.socket=e}t.exports=n;var r=e.TESTER_MESSAGE_TYPE,i=t.exports=function(e){e=e||window.queenSocket||function(){var e=window.location.search.match(/(?:\?|\&)queenSocketId=(.*)(?:\&|$)/);if(!e)throw new ReferenceError("Unable to find queen socket id in the url.");return window.parent.iframeSockets[e[1]]}();var t=new s(e);return t};return s.prototype.sendToSocket=function(e){this.isStreaming?this.socket(e):(this.batch.push(e),e[0]===r.end&&this.socket([r.batch,this.batch]))},s.prototype.start=function(e){this.sendToSocket([r.start,e])},s.prototype.suite=function(e){this.sendToSocket([r["suite start"],e])},s.prototype.test=function(e){this.sendToSocket([r["test start"],e])},s.prototype.testEnd=function(e){this.sendToSocket([r["test end"],e])},s.prototype.suiteEnd=function(e){this.sendToSocket([r["suite end"],e])},s.prototype.end=function(e){if(!e||e.passed===void 0)throw new TypeError('A "passed" variable is required to end the test');this.sendToSocket([r.end,e])},t.exports}({},{}),n=function(e,t){function r(e,t,n){var r=0,i=e.length;for(;r<i;r++)t.call(n,e[r],r,e)}function i(e,t,n){var r;for(r in e)e.hasOwnProperty(r)&&t.call(n,e[r],r,e)}function o(e,t,n){var r=0,i=e.length,s=[];for(;r<i;r++)s.push(t.call(n,e[r],r,e));return s}function u(e,t,n){var r,i={};for(r in e)e.hasOwnProperty(r)&&(i[r]=t.call(n,e[r],r,e));return i}function f(e,t,n){var r=0,i=e.length,s=[];for(;r<i;r++)t.call(n,e[r],r,e)&&s.push(e[r]);return s}function l(e,t,n){var r,i={};for(r in e)e.hasOwnProperty(r)&&t.call(n,e[r],r,e)&&(i[r]=e[r]);return i}e.exports=t;var n=t.noop=function(){},s=t.each=function(e,t,n){return e instanceof Array?r.apply(void 0,arguments):i.apply(void 0,arguments)},a=t.map=function(e,t,n){return e instanceof Array?o.apply(void 0,arguments):u.apply(void 0,arguments)},c=t.filter=function(e,t,n){return e instanceof Array?f.apply(void 0,arguments):l.apply(void 0,arguments)},h=t.values=function(e){var t=[];return i(e,function(e){t.push(e)}),t},p=t.keys=function(e){var t=[];return i(e,function(e,n){t.push(n)}),t},d=t.once=function(e){var t=!1,n;return function(){return t?n:(t=!0,n=e.apply(this,arguments),e=null,n)}};return e.exports}({},{}),r=function(e,r){function u(e){return function(t){var n=!0,r,i=0,s=0;t.on("start",function(){r=+(new Date),e.start({type:"mocha"})}),t.on("suite",function(t){e.suite({name:p(t)})}),t.on("test",function(t){t.__thrill_errors=[],e.test({name:t.title,suiteName:p(t.parent)})}),t.on("fail",function(e,t){e.type==="hook"||t.uncaught?e.__thrill_errors=[h(t)]:e.__thrill_errors.push(h(t))}),t.on("test end",function(t){var r=t.state==="passed";r||(n=!1),e.testEnd({name:t.title,suiteName:p(t.parent),passCount:r?1:0,failCount:r?0:1,runtime:t.timer,log:t.__thrill_errors.join("\n")}),delete t.__thrill_errors}),t.on("suite end",function(t){var n=d("failed",t).length,r=d("passed",t).length;i+=n,s+=r,e.suiteEnd({name:p(t),passCount:r,failCount:n})}),t.on("end",function(){var t=+(new Date)-r;e.end({passed:n,passCount:s,failCount:i,runtime:t})})}}function h(e){var t=e.stack,n=e.message;return t?(n&&!~t.substring(0,t.indexOf("\n")).indexOf(n)&&(t=n+"\n"+t),t=t.split(c),t=s.filter(t,function(e,t,n){return a.test(e)?!1:(n[t]=e.replace(f,"(").replace(l,""),!0)}),t.join("\n")):n}function p(e){var t=e.title;while(e.parent){e=e.parent;if(!e.title)continue;t=e.title+" "+t}return t}function d(e,t){return s.filter(t.tests,function(t){return t.state===e})}e.exports=r;var i=t,s=n,o=e.exports=function(e){e=e||{};var t=e.mocha||window.mocha,n=e.thrill||i();t.setup({reporter:u(n),ui:"bdd"})},a=/.*mocha.*\.js/i,f=/\(.*\/g\/.*?\//i,l=/\?queenSocketId=([\w\-])*/i,c=/\n/g;return(typeof THRILL_MANUAL=="undefined"||!THRILL_MANUAL)&&o(),e.exports}({},{});return r}();