UNPKG

thrill

Version:

Exciting testing

3 lines 4.15 kB
/*! 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){var t={},n={},r;return t.reportRunnerStarting=function(t){r=+(new Date),e.start({type:"jasmine"})},t.reportSuiteStarting=function(t){e.suite({name:t.getFullName()})},t.reportSpecStarting=function(t){testStartTime=(new Date).getTime(),e.test({name:t.description,suiteName:t.suite.getFullName()})},t.reportSpecResults=function(r){var i=(new Date).getTime()-testStartTime,o=r.results(),u=r.suite.getFullName();u in n||(n[u]=!0,t.reportSuiteStarting(r.suite)),data={name:r.description,suiteName:u,runtime:o.skipped?0:i,passCount:o.passedCount,failCount:o.failedCount,log:""},o.failedCount>0&&s.each(o.getItems(),function(e){e.passed()||(data.log+=h(e))}),e.testEnd(data)},t.reportSuiteResults=function(t){var n=t.results();e.suiteEnd({name:t.getFullName(),passCount:n.passCount,failCount:n.failedCount})},t.reportRunnerResults=function(t){var i=t.results(),s=+(new Date)-r;e.end({passed:i.passed(),passCount:i.passedCount,failCount:i.failedCount,runtime:s}),n={}},t}function h(e){var t=e.trace.stack,n=e.message;return t?(n&&~n.indexOf(t.substring(0,t.indexOf("\n")-1))&&(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}e.exports=r;var i=t,s=n,o=e.exports=function(e){e=e||{};var t=e.jasmine||window.jasmine,n,r=e.thrill||i();n=t.getEnv(),n.addReporter(u(r))},a=/.*jasmine.*\.js/i,f=/\(.*\/g\/.*?\//i,l=/\?queenSocketId=([\w\-])*/i,c=/\n/g;return(typeof THRILL_MANUAL=="undefined"||!THRILL_MANUAL)&&o(),e.exports}({},{});return r}();