jasmine_rsvp
Version:
Jasmine helpers for testing RSVP-Promise driven code.
1 lines • 7.54 kB
JavaScript
function has(e){var t=featureMap[e];return isFunction(proto[t])}var isFunction=function(e){return"function"==typeof e},bind,slice=[].slice,proto=Function.prototype,featureMap;featureMap={"function-bind":"bind"},has("function-bind")||(bind=function(e){var t=slice.call(arguments,1),n=this,u=function(){},r=function(){return n.apply(this instanceof u?this:e||{},t.concat(slice.call(arguments)))};return u.prototype=this.prototype||{},r.prototype=new u,r},proto.bind=bind),define("jasmine_rsvp/phantomjs_polyfills",function(){}),define("backburner/queue",["exports"],function(e){function t(e,t,n){this.daq=e,this.name=t,this.options=n,this._queue=[]}t.prototype={daq:null,name:null,options:null,_queue:null,push:function(e,t,n,u){var r=this._queue;return r.push(e,t,n,u),{queue:this,target:e,method:t}},pushUnique:function(e,t,n,u){var r,i,s,o,c=this._queue;for(s=0,o=c.length;o>s;s+=4)if(r=c[s],i=c[s+1],r===e&&i===t)return c[s+2]=n,c[s+3]=u,{queue:this,target:e,method:t};return this._queue.push(e,t,n,u),{queue:this,target:e,method:t}},flush:function(){var e,t,n,u,r,i=this._queue,s=this.options,o=s&&s.before,c=s&&s.after,l=i.length;for(l&&o&&o(),r=0;l>r;r+=4)e=i[r],t=i[r+1],n=i[r+2],u=i[r+3],n&&n.length>0?t.apply(e,n):t.call(e);l&&c&&c(),i.length>l?(this._queue=i.slice(l),this.flush()):this._queue.length=0},cancel:function(e){var t,n,u,r,i=this._queue;for(u=0,r=i.length;r>u;u+=4)if(t=i[u],n=i[u+1],t===e.target&&n===e.method)return i.splice(u,4),!0;if(i=this._queueBeingFlushed)for(u=0,r=i.length;r>u;u+=4)if(t=i[u],n=i[u+1],t===e.target&&n===e.method)return i[u+1]=null,!0}},e.Queue=t}),define("backburner/deferred_action_queues",["backburner/queue","exports"],function(e,t){function n(e,t){var n=this.queues={};this.queueNames=e=e||[];for(var u,i=0,s=e.length;s>i;i++)u=e[i],n[u]=new r(this,u,t[u])}function u(e,t){for(var n,u,r=0,i=t;i>=r;r++)if(n=e.queueNames[r],u=e.queues[n],u._queue.length)return r;return-1}var r=e.Queue;n.prototype={queueNames:null,queues:null,schedule:function(e,t,n,u,r,i){var s=this.queues,o=s[e];if(!o)throw new Error("You attempted to schedule an action in a queue ("+e+") that doesn't exist");return r?o.pushUnique(t,n,u,i):o.push(t,n,u,i)},flush:function(){for(var e,t,n,r,i=this.queues,s=this.queueNames,o=0,c=s.length;c>o;){e=s[o],t=i[e],n=t._queueBeingFlushed=t._queue.slice(),t._queue=[];var l,a,f,h,p=t.options,g=p&&p.before,m=p&&p.after,d=0,v=n.length;for(v&&g&&g();v>d;)l=n[d],a=n[d+1],f=n[d+2],h=n[d+3],"string"==typeof a&&(a=l[a]),a&&(f&&f.length>0?a.apply(l,f):a.call(l)),d+=4;t._queueBeingFlushed=null,v&&m&&m(),-1===(r=u(this,o))?o++:o=r}}},t.DeferredActionQueues=n}),define("backburner",["backburner/deferred_action_queues","exports"],function(e,t){function n(e){return"number"==typeof e||v.test(e)}function u(e,t){this.queueNames=e,this.options=t||{},this.options.defaultQueue||(this.options.defaultQueue=e[0]),this.instanceStack=[]}function r(e){e.begin(),o=d.setTimeout(function(){o=null,e.end()})}function i(e){var t,n,u,r,s=+new Date;e.run(function(){for(u=0,r=m.length;r>u&&(t=m[u],!(t>s));u+=2);for(n=m.splice(0,u),u=1,r=n.length;r>u;u+=2)e.schedule(e.options.defaultQueue,null,n[u])}),m.length&&(c=d.setTimeout(function(){i(e),c=null,l=null},m[0]-s),l=m[0])}function s(e,t){for(var n,u=-1,r=0,i=g.length;i>r;r++)if(n=g[r],n[0]===e&&n[1]===t){u=r;break}return u}var o,c,l,a=e.DeferredActionQueues,f=[].slice,h=[].pop,p=[],g=[],m=[],d=this,v=/\d+/;u.prototype={queueNames:null,options:null,currentInstance:null,instanceStack:null,begin:function(){var e=this.options&&this.options.onBegin,t=this.currentInstance;t&&this.instanceStack.push(t),this.currentInstance=new a(this.queueNames,this.options),e&&e(this.currentInstance,t)},end:function(){var e=this.options&&this.options.onEnd,t=this.currentInstance,n=null;try{t.flush()}finally{this.currentInstance=null,this.instanceStack.length&&(n=this.instanceStack.pop(),this.currentInstance=n),e&&e(t,n)}},run:function(e,t){var n;this.begin(),t||(t=e,e=null),"string"==typeof t&&(t=e[t]);var u=!1;try{n=arguments.length>2?t.apply(e,f.call(arguments,2)):t.call(e)}finally{u||(u=!0,this.end())}return n},defer:function(e,t,n){n||(n=t,t=null),"string"==typeof n&&(n=t[n]);var u=this.DEBUG?(new Error).stack:void 0,i=arguments.length>3?f.call(arguments,3):void 0;return this.currentInstance||r(this),this.currentInstance.schedule(e,t,n,i,!1,u)},deferOnce:function(e,t,n){n||(n=t,t=null),"string"==typeof n&&(n=t[n]);var u=this.DEBUG?(new Error).stack:void 0,i=arguments.length>3?f.call(arguments,3):void 0;return this.currentInstance||r(this),this.currentInstance.schedule(e,t,n,i,!0,u)},setTimeout:function(){function e(){t.apply(r,h)}var t,u,r,s,o,a,h=f.call(arguments),p=h.length,g=this;if(0!==p){if(1===p)t=h.shift(),u=0;else if(2===p)s=h[0],o=h[1],"function"==typeof o||"function"==typeof s[o]?(r=h.shift(),t=h.shift(),u=0):n(o)?(t=h.shift(),u=h.shift()):(t=h.shift(),u=0);else{var v=h[h.length-1];n(v)&&(u=h.pop()),s=h[0],a=h[1],"function"==typeof a||"string"==typeof a&&null!==s&&a in s?(r=h.shift(),t=h.shift()):t=h.shift()}var y=+new Date+parseInt(u,10);"string"==typeof t&&(t=r[t]);var q,b;for(q=0,b=m.length;b>q&&!(y<m[q]);q+=2);return m.splice(q,0,y,e),c&&y>l?e:(c&&(clearTimeout(c),c=null),c=d.setTimeout(function(){i(g),c=null,l=null},u),l=y,e)}},throttle:function(e,t){for(var n,u=this,r=arguments,i=parseInt(h.call(r),10),s=0,o=p.length;o>s;s++)if(n=p[s],n[0]===e&&n[1]===t)return;var c=d.setTimeout(function(){u.run.apply(u,r);for(var i=-1,s=0,o=p.length;o>s;s++)if(n=p[s],n[0]===e&&n[1]===t){i=s;break}i>-1&&p.splice(i,1)},i);p.push([e,t,c])},debounce:function(e,t){var n,u,r,i=this,o=arguments,c=h.call(o);"number"==typeof c||"string"==typeof c?(n=c,c=!1):n=h.call(o),n=parseInt(n,10),u=s(e,t),-1!==u&&(r=g[u],g.splice(u,1),clearTimeout(r[2]));var l=d.setTimeout(function(){c||i.run.apply(i,o),u=s(e,t),u&&g.splice(u,1)},n);c&&-1===u&&i.run.apply(i,o),g.push([e,t,l])},cancelTimers:function(){var e,t;for(e=0,t=p.length;t>e;e++)clearTimeout(p[e][2]);for(p=[],e=0,t=g.length;t>e;e++)clearTimeout(g[e][2]);g=[],c&&(clearTimeout(c),c=null),m=[],o&&(clearTimeout(o),o=null)},hasTimers:function(){return!!m.length||o},cancel:function(e){if(e&&"object"==typeof e&&e.queue&&e.method)return e.queue.cancel(e);if("function"==typeof e)for(var t=0,n=m.length;n>t;t+=2)if(m[t+1]===e)return m.splice(t,2),!0}},u.prototype.schedule=u.prototype.defer,u.prototype.scheduleOnce=u.prototype.deferOnce,u.prototype.later=u.prototype.setTimeout,t.Backburner=u}),define("jasmine_rsvp/promise_suite",["require","rsvp","backburner"],function(e){function t(e,t){l.defer("promises",t,e,t)}function n(){l.end(),l.begin()}function u(){s=o.configure("async"),o.configure("async",t),l.begin(),r(this)}function r(e){e.flush=function(){n()}}function i(){o.configure("async",s)}var s,o=e("rsvp"),c=e("backburner"),l=new c.Backburner(["promises"]),a=function(e){return e.__promiseSuiteSetup=!0,e.beforeEach(function(){u.call(this)}),e.afterEach(i),this};return function(){this.__promiseSuiteSetup||a(this)}}),define("jasmine_rsvp/main",["require","rsvp","./phantomjs_polyfills","./promise_suite"],function(e){var t=e("rsvp"),n=(e("./phantomjs_polyfills"),e("./promise_suite")),u=jasmine.Suite,r=jasmine.RSVP={enabled:!0,logRSVPErrors:!0};return t.configure("onerror",function(e){r.logRSVPErrors&&(console.error("RSVP error:",e),e&&e.message&&console.error(e.message),e&&e.stack&&console.error(e.stack))}),Object.defineProperty(u.prototype,"promiseSuite",{set:function(){n.call(this)}}),r}),define("jasmine_rsvp",["jasmine_rsvp/main"],function(e){return e});