beast-test
Version:
A package that allow for JUnit like TestCases. Very Robust Test Driven Development Framework
1 lines • 7.88 kB
JavaScript
(function(){var e,t,s,r,n={}.hasOwnProperty,a=function(e,t){function s(){this.constructor=e}for(var r in t)n.call(t,r)&&(e[r]=t[r]);return s.prototype=t.prototype,e.prototype=new s,e.__super__=t.prototype,e};e=function(){function e(e,t){this.passed=e,this.message=t}return e}(),r=function(){function e(e,t,s,r,n){this.testClass=e,this.name=t,this.message=s,this.result=r,this.position=n,this["class"]=this.testClass}return e.prototype.testClass=null,e.prototype.name=null,e.prototype.message=null,e.prototype.result=null,e.prototype.position=null,e}(),"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports.TestResult=r),s=function(){function s(){}return s.prototype._trueTest=function(t){return t!==!0?new e(!1,"failed to assert that "+this.stringObject(t)+" is true"):new e(!0,""+this.stringObject(t)+" is equal to true")},s.prototype._same=function(t,s){return t===s?new e(!0,"asserted that "+this.stringObject(t)+" is "+this.stringObject(s)):new e(!1,"failed to assert that "+this.stringObject(t)+" is "+this.stringObject(s))},s.prototype._equals=function(e,t){return e instanceof Array&&t instanceof Array?this._arrayEquals(e,t):this._same(e,t)},s.prototype._arrayEquals=function(t,s){var r,n,a;if(t.length===s.length)for(r in t)if(a=t[r],!(n=this._equals(a,s[r]))||!n.passed)return new e(!1,"failed to assert ["+this.stringObject(t)+"] is equal to ["+this.stringObject(s)+"] because property["+this.stringObject(r)+"] is not equal");return new e(!0,"asserted that ["+this.stringObject(t)+"] is equal to ["+this.stringObject(s)+"]")},s.prototype._isFunction=function(t){return"function"==typeof t?new e(!0,"assert that "+this.stringObject(t)+" is a function"):new e(!1,"failed to assert that "+this.stringObject(t)+" is a function")},s.prototype.assertTrue=function(e){var s;return s=this._trueTest(e),t.result.push(s.passed?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,s.message,t.failed,t.testAssert++))},s.prototype.assertNull=function(e){return t.result.push(null===e?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,"failed to assert "+e+" as null",t.failed,t.testAssert++))},s.prototype.assertNotNull=function(e){return t.result.push(null!==e?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,"failed to assert "+e+" as not null",t.failed,t.testAssert++))},s.prototype.assertEquals=function(e,s){return e instanceof Array&&s instanceof Array?this.assertArrayEquals(e,s):e instanceof Object&&s instanceof Object?this.assertObjectEquals(e,s):t.result.push(e===s?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,'failed to assert "'+e+'" equal to "'+s+'"',t.failed,t.testAssert++))},s.prototype.assertArrayEquals=function(e,s){var n;return n=this._arrayEquals(e,s),t.result.push(n.passed?new r(t.currentClassName,t.currentName,n.message,t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,n.message,t.failed,t.testAssert++))},s.prototype.assertFunction=function(e){var s;return s=this._isFunction(e),t.result.push(s.passed?new r(t.currentClassName,t.currentName,s.message,t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,s.message,t.failed,t.testAssert++))},s.prototype.assertObjectEquals=function(e,s){var n,a;try{a=this.deepObjectCompare(e,s)}catch(o){return n=o,n instanceof RangeError?void t.result.push(new r(t.currentClassName,t.currentName,"Warning - Object may have circular reference, may or may not be equal",t.warning,t.testAssert++)):void t.result.push(new r(t.currentClassName,t.currentName,n.message,t.failed,t.testAssert++))}t.result.push(a.passed?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,"failed to assert property["+a.key+'] is equal, "'+a.value.test+'" not "'+a.value.value+'"',t.failed,t.testAssert++))},s.prototype.deepObjectCompare=function(e,t){var s,r,n;n={},s=[];for(r in e)s[r]=r;for(r in t)s[r]=r;for(r in s)if(n.key=r,n.value={test:e[r],value:t[r]},"object"==typeof e[r]&&"object"==typeof t[r]){if(!this.deepObjectCompare(e[r],t[r]).passed)return n.passed=!1,n}else if("object"==typeof e[r]&&"object"==typeof t[r]){if(!this.deepObjectCompare(e[r],t[r]).passed)return n.passed=!1,n}else if(e[r]!==t[r])return n.passed=!1,n;return n.passed=!0,n},s.prototype.assertSimilar=function(e,s){return"string"==typeof e&&"string"==typeof s?void t.result.push(e.toLowerCase()===s.toLowerCase()?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,'failed to assert "'+e+'" of type ['+typeof e+'] is similar to "'+s+'" of type ['+typeof s+"]",t.failed,t.testAssert++)):t.result.push(e==s?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,'failed to assert "'+e+'" of type ['+typeof e+'] is similar to "'+s+'" of type ['+typeof s+"]",t.failed,t.testAssert++))},s.prototype.assertSame=function(e,s){return t.result.push(e===s?new r(t.currentClassName,t.currentName,"passed",t.passed,t.testAssert++):new r(t.currentClassName,t.currentName,'failed to assert "'+e+'" is the exact same "'+s+'"',t.failed,t.testAssert++))},s.prototype.stringObject=function(e){var t,s,r,n,a;if(s="",r=[],e instanceof Array){if(e.length<10){for(n=0,a=e.length;a>n;n++)t=e[n],r.push(""+this.stringObject(t));s=r.join(", ")}else s="Array0..."+e.length;s="["+s+"]"}else s=e instanceof Object?"["+e.constructor.name+": properties:"+e.length+"]":"string"==typeof e?'"'+e+'"':"number"==typeof e?""+e:"function"==typeof e?"["+f.name+": arguments "+f.length+"]":""+e.toString();return s},s}(),t=function(e){function t(e){this.auto=null!=e?e:!0,t.count++,this.auto&&this.run()}var s;return a(t,e),s=!1,t.count=0,t.result=[],t.prototype.prepare=function(){var e,t;for(e in this)"base"===e&&(s=!0);t=[];for(e in this)t.push("reset"===e&&"function"==typeof this[reset]?s=s&&!0:void 0);return t},t.prototype.run=function(){var e,n;if(t.start_t="undefined"==typeof t.start_t?Date.now():Math.min(Date.now(),t.start_t),this.prepare(),s){for(n in this)if("_test"===n.slice(0,5).toLowerCase()||"test"===n.slice(0,4).toLowerCase()){t.testAssert=1,t.currentClassName=this.constructor.name,t.currentName=n;try{this.base()}catch(a){e=a,t.result.push(new r(t.currentClassName,"base","Exception "+e.constructor.name+": "+e.message,t.failed,0));break}try{this.base()instanceof Array?this[n].apply(this,this.base()):this[n].call(this,this.base())}catch(a){if(e=a,!(e instanceof RangeError))throw e;t.result.push(new r(t.currentClassName,t.currentName,"Exception "+e.constructor.name+": "+e.message,t.failed,t.testAssert));continue}}return t.end_t=Date.now()}},t.passed=1,t.warning=0,t.failed=-1,t.getHTMLResult=function(){return t.nl="<br/>",t.tab=" ",t.print()},t.getResult=function(){return t.nl="\n",t.tab=" ",t.print()},t.nl="\n",t.tab=" ",t.result=[],t.print=function(){var e,s,r,n,a,o,u,i;for(e=0,a=0,s=0,n="",i=t.result,o=0,u=i.length;u>o;o++)r=i[o],r.result===t.passed?s++:r.result===t.warning?(a++,n+=t.format(r)):r.result===t.failed&&(e++,n+=t.format(r));return t.total_t=t.end_t-t.start_t,t.seconds=parseInt(t.total_t/1e3),t.ms=t.total_t%1e3,n+="Test Complete "+s+"/"+t.result.length+" passed, "+a+"/"+t.result.length+" warnings, "+e+"/"+t.result.length+" failed"+t.nl+"Total time "+t.seconds+"s "+t.ms+"ms"},t.format=function(e){var s,r;return s=t.nl,r=t.tab,e.result===t.passed?"":e.result===t.warning?""+e["class"]+"@"+e.name+s+r+e.message+", on assert # "+e.position+s+s:e.result===t.failed?""+e["class"]+"@"+e.name+s+r+e.message+", on assert # "+e.position+s+s:void 0},t}(s),"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports.TestCase=t)}).call(this);