-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.it.min.js
1 lines (1 loc) · 10.8 KB
/
test.it.min.js
1
!function(e){"use strict";function r(e){this.print=e.print,this.group=e.group,this.test=e.test,this.error=e.error}function t(){function e(e){S=new r(e)}function t(){this.type="group",this.name=void 0,this.status=void 0,this.comment=void 0,this.error=void 0,this.time=0,this.result={pass:0,fail:0,error:0,total:0},this.stack=[]}function c(){this.type="test",this.status=void 0,this.comment=void 0,this.description=void 0,this.error=void 0,this.argument=[]}function f(){return D}function m(e,r,n){var s,i=(new Date).getTime(),o=!1;for(var u in this.stack)if("group"===this.stack[u].type&&this.stack[u].name===e){s=this.stack[u],o=!0;break}o||(s=new t),s.name=e,s.linkBack=this;var c;o&&(c=s.status),s.status="pass";var f=D;D=s;try{r()}catch(m){s.status="error",s.error=a(m)}return D=f,s.time+=(new Date).getTime()-i,o||n||this.stack.push(s),N(s),s}function g(e){var r=this.stack;for(var t in r)if("group"===r[t].type&&r[t].name===e)return r[t];throw new ReferenceError("there is no group with name: "+e)}function h(e,r){var t,n=this.link?this.link:D;switch(arguments.length){case 0:throw new RangeError("test.group expect at least 1 argument");case 1:t=g.call(n,e);break;case 2:t=m.call(n,e,r,this.excluded);break;default:throw new RangeError("test.group expect no more than 2 arguments")}var a=s();return Object.create(this,{link:{value:t},trace:{value:a}})}function l(e,r){var t=new c;for(var n in r)t.argument.push(r[n]);switch(e){case"it":p(t);break;case"them":d(t);break;case"type":w(t);break;case"types":k(t);break;case"is":y(t);break;case"are":b(t)}this.timestamp&&(t.time=(new Date).getTime()-this.timestamp),this.excluded||D.stack.push(t),N(D);var a=s();return Object.create(this,{link:{value:t},trace:{value:a}})}function p(e){switch(e.argument.length){case 0:e.status="error",e.error=a(new RangeError("at least one argument expected"));break;case 1:e.argument[0]?(e.description="argument is true-like",e.status="pass"):(e.description="argument is false-like",e.status="fail");break;case 2:n(e.argument[0])!==n(e.argument[1])?(e.description="argument hase different types",e.status="fail"):o(e.argument[0],e.argument[1])?(e.description="arguments are equal",e.status="pass"):(e.description="argument are not equal",e.status="fail");break;default:e.status="error",e.error=a(new RangeError("maximum of 2 arguments expected"))}}function d(e){switch(e.argument.length){case 0:e.status="error",e.error=a(new RangeError("at least one argument expected"));break;case 1:if("Array"!==n(e.argument[0]))e.status="error",e.error=a(new TypeError("argument should be an array"));else{for(var r in e.argument[0])e.argument[0][r]||(e.status="fail",e.description="there are at least one false-like element");"fail"!==e.status&&(e.status="pass",e.description="arguments are true-like")}break;default:e.status="error",e.error=a(new RangeError("maximum of 1 arguments expected"))}}function w(e){2!==e.argument.length?(e.status="error",e.error=a(new RangeError("expect two arguments"))):"String"!==n(e.argument[1])?(e.status="error",e.error=a(new TypeError("second argument should be a String"))):i(u,e.argument[1].toLowerCase())?(e.description="type of argument is ",n(e.argument[0]).toLowerCase()!==e.argument[1].toLowerCase()?(e.description+="not "+e.argument[1],e.status="fail"):(e.description+=n(e.argument[0]),e.status="pass")):(e.status="error",e.error=a(new TypeError("second argument should be a standart type")))}function k(e){if(0==e.argument.length)e.status="error",e.error=a(new RangeError("at least one argument expected"));else if(e.argument.length>2)e.status="error",e.error=a(new RangeError("maximum of two arguments expected"));else if("Array"!==n(e.argument[0]))e.status="error",e.error=a(new TypeError("first argument should be an array"));else{var r,t;if("undefined"===n(e.argument[1])?(r=n(e.argument[0][0]),t="same"):"String"!==n(e.argument[1])?(e.status="error",e.error=a(new TypeError("second argument should be a String"))):i(u,e.argument[1].toLowerCase())?(r=e.argument[1],t="right"):(e.status="error",e.error=a(new TypeError("second argument should be a standart type"))),"error"!==e.status){r=r.toLowerCase();for(var s in e.argument[0])n(e.argument[0][s]).toLowerCase()!==r&&(e.status="fail",e.description="There are at least one element with different type");"fail"!==e.status&&(e.status="pass",e.description="arguments are "+t+" type")}}}function y(e){2!==e.argument.length?(e.status="error",e.error=a(new RangeError("expect two arguments"))):"Function"!==n(e.argument[1])?(e.status="error",e.error=a(new TypeError("second argument should be a constructor (function)"))):""==e.argument[1].name?(e.description="argument has ",e.argument[0].constructor!==e.argument[1]?(e.description+="wrong",e.status="fail"):(e.description+="right",e.status="pass"),e.description+=" constructor"):(e.description="argument is ",e.argument[0].constructor!==e.argument[1]?(e.description+="not "+e.argument[1].name,e.status="fail"):(e.description+=e.argument[1].name,e.status="pass"))}function b(e){if(0==e.argument.length)e.status="error",e.error=a(new RangeError("at least one argument expected"));else if(e.argument.length>2)e.status="error",e.error=a(new RangeError("maximum of two arguments expected"));else if("Array"!==n(e.argument[0]))e.status="error",e.error=a(new TypeError("first argument should be an array"));else{var r,t;if("undefined"===n(e.argument[1])?(r=e.argument[0][0].constructor,t="same"):"Function"!==n(e.argument[1])?(e.status="error",e.error=a(new TypeError("second argument should be a constructor (function)"))):(r=e.argument[1],t="right"),"error"!==e.status){for(var s in e.argument[0])if(e.argument[0][s].constructor!==r){e.status="fail";var i=1+parseInt(s);e.description="There are at least one ("+i+") element with different constructor"}"fail"!==e.status&&(e.status="pass","undefined"!=typeof e.argument[1]?e.description="are "+e.argument[1].name:e.description="arguments has same constructor")}}}function v(){return Object.create(this,{timestamp:{value:(new Date).getTime()}})}function E(e){if(!this.link)throw new ReferenceError("comment can only be used in testit chain");return this.link.comment=e,this}function x(e,r,t){if(!this.link)throw new ReferenceError("callback can only be used in testit chain");if("pass"===this.link.status&&"Function"===n(e))try{e()}catch(a){throw a}if("fail"===this.link.status&&"Function"===n(r))try{r()}catch(a){throw a}if("error"===this.link.status&&"Function"===n(t))try{t()}catch(a){throw a}return this}function T(e){if(!this.link)throw new ReferenceError("addTrace can only be used in testit chain");if(this.trace){var r=this.trace;"Number"===n(e)&&(r=r.split("\n").slice(0,e+1).join("\n")),this.link.trace=r}return this}function R(){return this.link?"pass"==this.link.status?!0:!1:"pass"==D.status?!0:!1}function O(){if(this.link){if("test"!==this.link.type)return TypeError("groups don't return arguments");switch(this.link.argument.length){case 0:return void 0;case 1:return this.link.argument[0];default:return this.link.argument}}return void 0}function j(e){var t=this.link?this.link:D;if(e)new r(e).print(t);else{if(!S)return!1;S.print(t)}return!0}function N(e){e.result={pass:0,fail:0,error:0,total:0};for(var r in e.stack)switch(e.result.total++,e.stack[r].status){case"pass":e.result.pass++;break;case"fail":e.result.fail++;break;case"error":e.result.error++}e.result.error||e.error?e.status="error":e.result.fail?e.status="fail":e.status="pass",e.root&&(e.time=(new Date).getTime()-e.timestamp),e.linkBack&&N(e.linkBack)}var S;this.printer=function(r){return r&&e(r),S};var D=new t;return D.root=!0,D.name="root",D.timestamp=(new Date).getTime(),this.getRoot=this.r=f,this.root=D,this.group=h,this.it=function(){return l.call(this,"it",arguments)},this.them=function(){return l.call(this,"them",arguments)},this.is=function(){return l.call(this,"is",arguments)},this.are=function(){return l.call(this,"are",arguments)},this.type=function(){return l.call(this,"type",arguments)},this.types=function(){return l.call(this,"types",arguments)},this.addTime=v,this.time=Object.create(this,{timestamp:{value:(new Date).getTime()}}),this.exclude=this.x=Object.create(this,{excluded:{value:!0}}),this.comment=E,this.callback=x,this.addTrace=T,this.result=R,this.arguments=O,this.print=j,this.done=j,this["typeof"]=n,this.trace=s,this}function n(e){var r;try{switch(e.constructor){case Array:r="Array";break;case Boolean:r="Boolean";break;case Date:r="Date";break;case Error:r="Error";break;case EvalError:r="EvalError";break;case Function:r="Function";break;case Number:r=isNaN(e)?"NaN":"Number";break;case Object:r="Object";break;case RangeError:r="RangeError";break;case ReferenceError:r="ReferenceError";break;case RegExp:r="RegExp";break;case String:r="String";break;case SyntaxError:r="SyntaxError";break;case TypeError:r="TypeError";break;case URIError:r="URIError";break;case Window:r="Window";break;case HTMLDocument:r="HTML";break;case NodeList:r="NodeList";break;default:r="object"==typeof e&&-1!==e.toString().indexOf("HTML")?"HTML":void 0}}catch(t){r=null===e?"null":typeof e}return r}function a(e){var r={error:e,type:n(e),message:e.message};return s(e)&&(r.stack=s(e)),r}function s(e){if(e||(e=new Error),e.stack){var r="";return e.stack.split(/[\n]/).forEach(function(t,a){var s=!0;""===t&&(s=!1),-1!==t.indexOf(n(e))&&(s=!1),(-1!==t.indexOf("test.it.js")||-1!==t.indexOf("test.it.min.js"))&&(s=!1),-1!==t.indexOf("getTrace")&&(s=!1),s&&(r+=r?"\n":"",r+=t.replace(/((\s+at\s+)|(^@))/,""))}),r}}function i(e,r){for(var t in e)if(e[t]===r)return!0;return!1}function o(){function e(n,a){var s;if(isNaN(n)&&isNaN(a)&&"number"==typeof n&&"number"==typeof a)return!0;if(n===a)return!0;if("function"==typeof n&&"function"==typeof a||n instanceof Date&&a instanceof Date||n instanceof RegExp&&a instanceof RegExp||n instanceof String&&a instanceof String||n instanceof Number&&a instanceof Number)return n.toString()===a.toString();if("undefined"!=typeof window&&window.jQuery&&n instanceof jQuery&&a instanceof jQuery)return n.is(a);if(!(n instanceof Object&&a instanceof Object))return!1;if(n.isPrototypeOf(a)||a.isPrototypeOf(n))return!1;if(n.constructor!==a.constructor)return!1;if(n.prototype!==a.prototype)return!1;if(r.indexOf(n)>-1||t.indexOf(a)>-1)return!1;for(s in a){if(a.hasOwnProperty(s)!==n.hasOwnProperty(s))return!1;if(typeof a[s]!=typeof n[s])return!1}for(s in n){if(a.hasOwnProperty(s)!==n.hasOwnProperty(s))return!1;if(typeof a[s]!=typeof n[s])return!1;switch(typeof n[s]){case"object":case"function":if(r.push(n),t.push(a),!e(n[s],a[s]))return!1;r.pop(),t.pop();break;default:if(n[s]!==a[s])return!1}}return!0}var r,t;if(arguments.length<1)return!0;for(var n=1,a=arguments.length;a>n;n++)if(r=[],t=[],!e(arguments[0],arguments[n]))return!1;return!0}var u=["array","boolean","date","error","evalerror","function","html","nan","nodelist","null","number","object","rangeerror","referenceerror","regexp","string","syntaxerror","typeerror","urierror","window"];"undefined"!=typeof module&&module.exports?module.exports=new t:e.test=new t}(this);