UNPKG

wishlist

Version:

Super natural testing framework.

649 lines (567 loc) 24.4 kB
// Generated by CoffeeScript 1.9.1 (function() { var Test, stepIndex, steps, stepsTimer, wishlist, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; wishlist = typeof npmWishlist !== "undefined" && npmWishlist !== null ? npmWishlist : require("../wishlist"); Test = wishlist.Test; steps = []; /* The output should look something like this: 2015-04-04T16:31:44.327Z OK: 13, Exception: 1, Pending: 5 2015-04-04T16:31:45.297Z OK: 13, Exception: 1, Pending: 5 2015-04-04T16:31:46.298Z OK: 16, Exception: 1, Pending: 2 2015-04-04T16:31:47.300Z OK: 17, Exception: 2, Pending: 0 ********** Exceptional Test ********** Test: error in async Function: function (v, t) { setTimeout(function() { return falseFunction(); }, 2200); return setTimeout(function() { return t.end(); }, 2700); } Error Name: ReferenceError Error Message: falseFunction is not defined Error Stack: ReferenceError: falseFunction is not defined ... ********** Exceptional Test ********** Test: Function: function () { return falseFunction(true); } Error Name: ReferenceError Error Message: falseFunction is not defined Error Stack: ReferenceError: falseFunction is not defined ... ********** Broken Wish ********** Test: root --> String.prototype test Wish: wrongStr.split(" ")=["hello","world"] Expected: = ["hello","world"] Actual: ["helloo","world"] ********** Broken Wish ********** Test: root --> String.prototype test Wish: wrongStr.split(" ")=["hello","world"] Expected: = ["hello","world"] Actual: ["helloo","world"] ********** Broken Wish ********** Test: root --> Wish: var1 equals var2 Expected: = 1234 Actual: 111 ********** Broken Wish ********** Test: root --> Wish: var2 <><><> a Expected: ≠ 1234 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: 1+2+3=7 Expected: = 7 Actual: 6 ********** Broken Wish ********** Test: root --> Wish: (obj.unit>1)=true Expected: = true Actual: false ********** Broken Wish ********** Test: root --> nested test --> test 2 in nested test Wish: simple boolean test Expected: = true Actual: false ********** Broken Wish ********** Test: root --> nested var Wish: var1 is var2 Expected: is 8888 Actual: 111 ********** Broken Wish ********** Test: root --> nested var Wish: var3=1 Expected: = 1 Actual: 222 ********** Broken Wish ********** Test: root --> nested var --> Wish: var1=var2 Expected: = 8888 Actual: 111 ********** Broken Wish ********** Test: root --> simple test 2 Wish: slowVar='iii' Expected: = "iii" Actual: "yyy" ********** Broken Wish ********** Test: root --> simple test 2 Wish: var2=true Expected: = true Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: ("1"===2)=true Expected: = true Actual: false ********** Broken Wish ********** Test: root --> Wish: inexistentVariable=inexistentVariable Expected: unknown Actual: unknown ********** Broken Wish ********** Test: root --> Wish: jiojaalgfj(lksfjeosjirg========; Expected: unknown Actual: unknown ********** Broken Wish ********** Test: root --> Wish: {} is {} Expected: is {} Actual: {} ********** Broken Wish ********** Test: root --> Wish: [] is [] Expected: is [] Actual: [] ********** Broken Wish ********** Test: root --> Wish: null<>null Expected: ≠ null Actual: null ********** Broken Wish ********** Test: root --> Wish: undefined<>undefined Expected: ≠ undefined Actual: undefined ********** Broken Wish ********** Test: root --> Wish: sampleNaN1=1 Expected: = 1 Actual: NaN ********** Broken Wish ********** Test: root --> Wish: NaN= 3 Expected: = 3 Actual: NaN ********** Broken Wish ********** Test: root --> Wish: '' =NaN Expected: = NaN Actual: "" ********** Broken Wish ********** Test: root --> Wish: 0=-0 Expected: = -0 Actual: 0 ********** Broken Wish ********** Test: root --> Wish: 0 is -0 Expected: is -0 Actual: 0 ********** Broken Wish ********** Test: root --> Wish: -0 is 0 Expected: is 0 Actual: -0 ********** Broken Wish ********** Test: root --> Wish: b throws Expected: exception Actual: no exception ********** Broken Wish ********** Test: root --> Wish: a throws /kkk/ Expected: an exception Actual: another exception ********** Broken Wish ********** Test: root --> Wish: a throws CustomError Expected: an exception Actual: another exception ********** Broken Wish ********** Test: root --> Wish: a Expected: no exception Actual: exception ********** Broken Wish ********** Test: root --> Wish: var2<1000 Expected: < 1000 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: var2<1234 Expected: < 1234 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: var2<=1000 Expected: <= 1000 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: var2 >2000 Expected: > 2000 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: var2 >= 2000 Expected: >= 2000 Actual: 1234 ********** Broken Wish ********** Test: root --> Wish: "a">"b" Expected: > "b" Actual: "a" ********** Broken Wish ********** Test: root --> Wish: /=/.test("=")=false Expected: = false Actual: true ********** Broken Wish ********** Test: root --> Wish: "\""="\"abc" Expected: = "\"abc" Actual: "\"" ********** Broken Wish ********** Test: root --> Wish: 123<>123 Expected: ≠ 123 Actual: 123 ********** Broken Wish ********** Test: root --> Wish: {a:1,b:2}<>{a:1,b:2} Expected: ≠ {"a":1,"b":2} Actual: {"a":1,"b":2} ********** Broken Wish ********** Test: root --> Wish: {a:1,b:2,c:function(){}}={a:1,b:2} Expected: = {"a":1,"b":2} Actual: {"a":1,"b":2,"c":[Function]} ********** Broken Wish ********** Test: root --> Wish: NaN isnt NaN Expected: isn't NaN Actual: NaN ********** Broken Wish ********** Test: root --> Wish: {a:1,b:2}={a:1,b:2,c:function(){}} Expected: = {"a":1,"b":2,"c":[Function]} Actual: {"a":1,"b":2} ********** Broken Wish ********** Test: root --> Wish: {a:{a:{a:{a:{}}}}}={a:{a:{a:{a:1}}}} Expected: = {"a":{"a":{"a":[Object]}}} Actual: {"a":{"a":{"a":[Object]}}} ********** Broken Wish ********** Test: root --> Wish: circularObj isnt circularObj Expected: isn't {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} Actual: {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} ********** Broken Wish ********** Test: root --> Wish: circularObj <> circularObj Expected: ≠ {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} Actual: {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} ********** Broken Wish ********** Test: root --> Wish: circularObj is circularObj2 Expected: is {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} Actual: {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} ********** Broken Wish ********** Test: root --> Wish: circularObj = circularObj2 Expected: = {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} Actual: {"a":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[3,4]} ********** Broken Wish ********** Test: root --> Wish: circularWrapper is circularWrapper2 Expected: is {"content":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[5,6]} Actual: {"content":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[5,6]} ********** Broken Wish ********** Test: root --> Wish: circularWrapper <> circularWrapper2 Expected: ≠ {"content":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[5,6]} Actual: {"content":{"a":{"a":[Object],"b":[Array]},"b":[3,4]},"b":[5,6]} ********** Broken Wish ********** Test: root --> Wish: veryLongCircularObj1=veryLongCircularObj2 Expected: = {"me":[Object],"secondMe":[Object],"thirdMe":[Object],"meArray":[Array],"a":"............................................................","b":"............................................................","c":"............................................................","d":"............................................................","e":"............................................................","f":"............................................................","g":"............................................................","h":"............................................................","i":"............................................................","j":"............................................................","k":"............................................................","l":"............................................................"} Actual: {"me":[Object],"secondMe":[Object],"thirdMe":[Object],"meArray":[Array],"a":"............................................................","b":"............................................................","c":"............................................................","d":"............................................................","e":"............................................................","f":"............................................................","g":"............................................................","h":"............................................................","i":"............................................................","j":"............................................................","k":"............................................................","l":"............................................................"} ********** Broken Wish ********** Test: root --> Wish: veryLongCircularObj1 is veryLongCircularObj2 Expected: is {"me":[Object],"secondMe":[Object],"thirdMe":[Object],"meArray":[Array],"a":"............................................................","b":"............................................................","c":"............................................................","d":"............................................................","e":"............................................................","f":"............................................................","g":"............................................................","h":"............................................................","i":"............................................................","j":"............................................................","k":"............................................................","l":"............................................................"} Actual: {"me":[Object],"secondMe":[Object],"thirdMe":[Object],"meArray":[Array],"a":"............................................................","b":"............................................................","c":"............................................................","d":"............................................................","e":"............................................................","f":"............................................................","g":"............................................................","h":"............................................................","i":"............................................................","j":"............................................................","k":"............................................................","l":"............................................................"} ********** Broken Wish ********** Test: root --> Wish: [ 1, 2, 3, "asdf", "jkl", { yyy: 4, iii: 5, jjj: NaN, kkk: null, "mmm e": -9, d: undefined } ] = [ 1, 2, 3, "asdf", "jkl", { yyy: 4, iii: 5, jjj: NaN, kkk: null, "mmm e": -10, d: undefined } ] Expected: = [1,2,3,"asdf","jkl",{"yyy":4,"iii":5,"jjj":NaN,"kkk":null,"mmm e":-10,"d":undefined}] Actual: [1,2,3,"asdf","jkl",{"yyy":4,"iii":5,"jjj":NaN,"kkk":null,"mmm e":-9,"d":undefined}] 2 tests of 19 exceptional. 52 wishes of 102 broken. Mark: 0332c */ steps.push(function() { console.log("----- General -----"); return new Test("root").set(function(v) { v.var1 = 111; return v.var2 = 1234; }).add("String.prototype test", function(v) { v.str = "hello world"; return v.wrongStr = "helloo world"; }, [' str.substr(4,1)="o" ', ' str.split(" ")=["hello","world"] ', ' str.split(" ")=["hello","world"] ', ' wrongStr.substr(4,1)="o" ', ' wrongStr.split(" ")=["hello","world"] ', ' wrongStr.split(" ")=["hello","world"] ']).add(function(v) { return v.a = v.var2; }, "Math.round(5.3)=5;\nvar1=var2:var1 equals var2;\nvar1<>var2;\nvar2=a : var1=========a;\nvar2<>a\n : var2 <><><> a\n;").add(function() { return void 0; }, ['1+2+3=7']).add(function(v) { v.obj = {}; v.obj.unit = function() { return Math.random(); }; return v.obj.unit(); }, [' (obj.unit>1)=true']).add(new Test("nested test").setAsync(function(v, t) { return setTimeout(function() { return t.end(); }, 1500); }).add("test 1 in nested test", function() { return void 0; }, ['false=false']).add("test 2 in nested test", function() { return void 0; }, ["false=true: simple boolean test"])).add(new Test("nested var").add(function() { return void 0; }, ['var1=var2']).add(function() { return void 0; }, ['var1<>var2']).set(function(env) { env.var2 = 8888; return env.var3 = env.var1 * 2; }, ['var1 is var2', 'var1 isnt var2', 'var3=1'])).addAsync("simple test 2", function(v, t) { return setTimeout(function() { v.slowVar = "yyy"; return t.end(); }, 2500); }, ["true=true :truthy unit", "slowVar='yyy'", "slowVar='iii'", "slowVar='yyy'", "var2=true"]).addAsync("error in async", function(v, t) { setTimeout(function() { return falseFunction(); }, 2200); return setTimeout(function() { return t.end(); }, 2700); }).add(function() { return void 0; }, ["(\"1\"===2)=true"]).add(function() { return void 0; }, "inexistentVariable=inexistentVariable;\njiojaalgfj(lksfjeosjirg========;").add(function() { return falseFunction(true); }, "true=true").add(function(v, t) { t.wish("{} is {}"); t.wish(" [] is [] "); t.wish("NaN is NaN"); t.wish("NaN = NaN"); t.wish("null<>null"); t.wish("undefined<>undefined"); v.sampleNaN1 = NaN; v.sampleNaN2 = NaN; t.wish('sampleNaN1=sampleNaN2'); t.wish('sampleNaN1=1'); t.wish("NaN= 3"); t.wish("'' =NaN"); t.wish("0=0"); t.wish("0=-0"); t.wish("0 is -0"); t.wish("-0 is 0"); v.CustomError = (function(superClass) { extend(CustomError, superClass); function CustomError(msg) { CustomError.__super__.constructor.call(this, msg); } return CustomError; })(Error); v.a = function() { throw new Error(); }; v.b = function() {}; v.c = function() { throw new v.CustomError(); }; t.wish('a throws'); t.wish('b throws'); t.wish('a throws /kkk/'); t.wish('a throws /^$/'); t.wish('a throws Error'); t.wish('a throws CustomError'); t.wish('c throws Error'); t.wish('c throws CustomError'); t.wish('b'); t.wish('a'); t.wish('var2<1000'); t.wish('var2< 2000'); t.wish('var2<1234'); t.wish('var2 <= 1234'); t.wish('var2<=2000'); t.wish('var2<=1000'); t.wish('var2>1000'); t.wish('var2 >2000'); t.wish('var2 >= 2000'); t.wish('var2 >= 1234'); t.wish('var2>=1000'); t.wish(' "a"<"b" '); t.wish(' "a">"b" '); t.wish(' /=/.test("=")=true '); t.wish(' /=/.test("=")=false '); t.wish('Object . is is Object.is'); t.wish('Object.is = Object. is'); t.wish(' "\\""="\\"abc" '); t.wish(' 123<>123 '); t.wish(' 123<>456 '); t.wish(' {a:1,b:2}<>{a:1,b:1} '); t.wish(' {a:1,b:2}<>{a:1,b:2} '); t.wish(' {a:1,b:2}<>{a:1,b:2,c:function(){}} '); t.wish(' {a:1,b:2,c:function(){}}={a:1,b:2} '); t.wish(' {a:1,b:2,c:function(){}}<>{a:1,b:2} '); t.wish(' 8 isnt 4 '); t.wish(' NaN isnt NaN '); t.wish(' {} isnt {} '); t.wish(' {a:1,b:2}={a:1,b:2,c:function(){}} '); t.wish(' {a:{a:{a:{a:{}}}}}={a:{a:{a:{a:{}}}}} '); t.wish(' {a:{a:{a:{a:{}}}}}={a:{a:{a:{a:1}}}} '); v.circularObj = {}; v.circularObj.a = v.circularObj; v.circularObj.b = [3, 4]; v.circularObj2 = {}; v.circularObj2.a = v.circularObj2; v.circularObj2.b = [3, 4]; t.wish(' circularObj isnt circularObj '); t.wish(' circularObj is circularObj '); t.wish(' circularObj = circularObj '); t.wish(' circularObj <> circularObj '); t.wish(' circularObj isnt circularObj2 '); t.wish(' circularObj is circularObj2 '); t.wish(' circularObj = circularObj2 '); t.wish(' circularObj <> circularObj2 '); v.circularWrapper = {}; v.circularWrapper.content = v.circularObj; v.circularWrapper.b = [5, 6]; v.circularWrapper2 = {}; v.circularWrapper2.content = v.circularObj; v.circularWrapper2.b = [5, 6]; t.wish(' circularWrapper isnt circularWrapper2 '); t.wish(' circularWrapper is circularWrapper2 '); t.wish(' circularWrapper = circularWrapper2 '); return t.wish(' circularWrapper <> circularWrapper2 '); }).add(function(v, t) { v.veryLongCircularObj1 = {}; v.veryLongCircularObj1.me = v.veryLongCircularObj1; v.veryLongCircularObj1.secondMe = v.veryLongCircularObj1; v.veryLongCircularObj1.thirdMe = v.veryLongCircularObj1; v.veryLongCircularObj1.meArray = [v.veryLongCircularObj1, v.veryLongCircularObj1]; v.veryLongCircularObj1.a = "............................................................"; v.veryLongCircularObj1.b = "............................................................"; v.veryLongCircularObj1.c = "............................................................"; v.veryLongCircularObj1.d = "............................................................"; v.veryLongCircularObj1.e = "............................................................"; v.veryLongCircularObj1.f = "............................................................"; v.veryLongCircularObj1.g = "............................................................"; v.veryLongCircularObj1.h = "............................................................"; v.veryLongCircularObj1.i = "............................................................"; v.veryLongCircularObj1.j = "............................................................"; v.veryLongCircularObj1.k = "............................................................"; v.veryLongCircularObj1.l = "............................................................"; v.veryLongCircularObj2 = {}; v.veryLongCircularObj2.me = v.veryLongCircularObj2; v.veryLongCircularObj2.secondMe = v.veryLongCircularObj2; v.veryLongCircularObj2.thirdMe = v.veryLongCircularObj2; v.veryLongCircularObj2.meArray = [v.veryLongCircularObj2, v.veryLongCircularObj2]; v.veryLongCircularObj2.a = "............................................................"; v.veryLongCircularObj2.b = "............................................................"; v.veryLongCircularObj2.c = "............................................................"; v.veryLongCircularObj2.d = "............................................................"; v.veryLongCircularObj2.e = "............................................................"; v.veryLongCircularObj2.f = "............................................................"; v.veryLongCircularObj2.g = "............................................................"; v.veryLongCircularObj2.h = "............................................................"; v.veryLongCircularObj2.i = "............................................................"; v.veryLongCircularObj2.j = "............................................................"; v.veryLongCircularObj2.k = "............................................................"; v.veryLongCircularObj2.l = "............................................................"; t.wish('veryLongCircularObj1=veryLongCircularObj2'); t.wish('veryLongCircularObj1<>veryLongCircularObj2'); t.wish('veryLongCircularObj1 is veryLongCircularObj2'); return t.wish('veryLongCircularObj1 isnt veryLongCircularObj2'); }).add(function(v, t) { t.wish("[\n 1, 2, 3,\n \"asdf\", \"jkl\",\n {\n yyy: 4,\n iii: 5,\n jjj: NaN,\n kkk: null,\n \"mmm e\": -9,\n d: undefined\n }\n]\n=\n[\n 1, 2, 3,\n \"asdf\", \"jkl\",\n {\n yyy: 4,\n iii: 5,\n jjj: NaN,\n kkk: null,\n \"mmm e\": -10,\n d: undefined\n }\n]"); return t.wish("[\n 1, 2, 3,\n \"asdf\", \"jkl\",\n {\n yyy: 4,\n iii: 5,\n jjj: NaN,\n kkk: null,\n \"mmm e\": -9,\n d: undefined\n }\n]\n=\n[\n 1, 2, 3,\n \"asdf\", \"jkl\",\n {\n yyy: 4,\n iii: 5,\n jjj: NaN,\n kkk: null,\n \"mmm e\": -9,\n d: undefined\n }\n]"); }).run(); }); /* The output should look something like this: 2014-07-13T15:13:23.707Z OK: 1, Exception: 0, Pending: 0 Tests OK. Wishes fulfilled. Mark: e3b0c */ steps.push(function() { console.log("----- Tiny -----"); return new Test().run(); }); /* The output should look something like this: after 1 ReferenceError: jkjk is not defined ... 2014-08-20T07:22:06.198Z OK: 2, Exception: 0, Pending: 1 2014-08-20T07:22:07.187Z OK: 2, Exception: 0, Pending: 1 2014-08-20T07:22:08.188Z OK: 2, Exception: 0, Pending: 1 1 2 after 2 2014-08-20T07:22:09.189Z OK: 3, Exception: 0, Pending: 0 Tests OK. Wishes fulfilled. Mark: e3b0c */ steps.push(function() { console.log("----- Flow -----"); return new Test().set(function(v, t) { return v.a = 1; }).add(new Test().after(function(v) { console.log("after 1"); return jkjk(); })).addAsync(function(v, t) { return setTimeout(function() { return t.end(); }, 2500); }).after(function(v) { console.log(v.a); v.a = 2; console.log(v.a); return console.log("after 2"); }).run(); }); stepIndex = -1; stepsTimer = setInterval(function() { if (wishlist.currentRootTest === null) { if (stepIndex === steps.length - 1) { return clearInterval(stepsTimer); } else { stepIndex++; return steps[stepIndex](); } } }, 10); }).call(this);