From 0aa72d399bc94d2c756fb7ac5b24e435e5507bbd Mon Sep 17 00:00:00 2001 From: Geoff Doty Date: Tue, 8 Sep 2020 17:37:54 -0500 Subject: [PATCH] update dist --- README.md | 6 +- dist/testit.js | 167 +++++++++++++++++++---------------------- dist/testit.min.js | 3 +- dist/testit.umd.js | 97 ++++++++++++++++++++++++ dist/testit.umd.min.js | 1 + 5 files changed, 178 insertions(+), 96 deletions(-) create mode 100644 dist/testit.umd.js create mode 100644 dist/testit.umd.min.js diff --git a/README.md b/README.md index e04e75e..b13791a 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ This is probally not a *cure-all* testing solution, if you want something more r ### Features -- Works in the Browser -- Works with CommonJS (aka NodeJS) -- *Barely* over a 100 lines +- Designed for the Browser +- Works with NodeJS +- *Under* a 100 lines - Single File - No Dependicies - 2kb footprint (*before gzip*) diff --git a/dist/testit.js b/dist/testit.js index 0781940..69e0c46 100644 --- a/dist/testit.js +++ b/dist/testit.js @@ -1,104 +1,89 @@ -/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */ -;(function (root, factory) { - "use strict"; - if (typeof module === "object" && module.exports) { - module.exports = factory(root.test); - } else { - root.test = factory(root.test); - } -}(this, function () { - "use strict"; +/*! Test.it v 0.9.0 | MIT | https://github.com/n2geoff/testit */ +const test = { + "log": console.log, + "_tests": {}, + "run": function run(errors, next) { + if(typeof errors !== "boolean") { + next = errors; + errors = true; + } - const test = { - "_tests": {}, - "run": function run(errors, next) { - if(typeof errors !== "boolean") { - next = errors; - errors = true; - } + let tests = this._tests || []; + let failed = []; + let passed = []; - let tests = this._tests; - let failed = []; - let passed = []; + Object.keys(tests).forEach((name) => { + let test = tests[name]; - Object.keys(tests).forEach((name) => { - let test = tests[name]; - - try { - test(); - passed.push(`\n+OK ${name}`); - } catch (err) { - if (errors) { - failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`); - } else { - failed.push(`\n-ERR ${name}`); - } + try { + test(); + passed.push(`\n+OK ${name}`); + } catch (err) { + if (errors) { + failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`); + } else { + failed.push(`\n-ERR ${name}`); } - }); - - if(typeof next === "function") { - return next({ - pass: passed, - fail: failed - }); - } else { - console.log(...passed, ...failed); - console.log(`\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`); - - return failed.length ? false : true; } - }, - "it": function it(tests) { - this._tests = tests; - return this; - }, - "expects": function expects(val) { - return { - "to": { - "be": { - "a": (type) => { - return test.expects(val).to.be.an(type); - }, - "an": (type) => { + }); - if(['array'].indexOf(type) !== -1) { - if(val.constructor.name.toLowerCase() !== 'array') { - throw new Error(`expected ${typeof val} to be an ${type}`); - } + if(typeof next === "function") { + return next({ + pass: passed, + fail: failed + }); + } else { + test.log(...passed, ...failed); + test.log(`\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`); - return true; - } + return failed.length ? false : true; + } + }, + "it": function it(tests) { + this._tests = tests; + return this; + }, + "expects": function expects(val) { + return { + "to": { + "be": { + "a": (type) => { return test.expects(val).to.be.an(type); }, + "an": (type) => { - if(typeof val !== type) { + if(["array"].indexOf(type) !== -1) { + if(val.constructor.name.toLowerCase() !== "array") { throw new Error(`expected ${typeof val} to be an ${type}`); } - }, - "ok": () => { - return test.expects(val).to.exist(); - }, - "like": (comp) => { - if(val != comp) { - throw new Error(`expected ${val} == ${comp}`); - } - } - }, - "equal": (comp) => { - if(val !== comp) { - throw new Error(`expected ${val} === ${comp}`); + return true; } - }, - "exist": () => { - if(!val) { - throw new Error(`expected ${val} to be truthy`); - } - }, - "pass": () => { return true; }, - "fail": (msg) => { throw new Error(msg); } - } - }; - } - }; - return test; -})); + if(typeof val !== type) { + throw new Error(`expected ${typeof val} to be an ${type}`); + } + }, + "ok": () => { return test.expects(val).to.exist(); }, + "like": (comp) => { + if(val != comp) { + throw new Error(`expected ${val} == ${comp}`); + } + } + }, + "equal": (comp) => { + if(val !== comp) { + throw new Error(`expected ${val} === ${comp}`); + } + }, + "exist": () => { + if(!val) { + throw new Error(`expected ${val} to be truthy`); + } + }, + "pass": () => { return true; }, + "fail": (msg) => { throw new Error(msg); } + } + }; + } +}; + +export default test; diff --git a/dist/testit.min.js b/dist/testit.min.js index 72456f0..d329b2e 100644 --- a/dist/testit.min.js +++ b/dist/testit.min.js @@ -1,2 +1 @@ -/*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */ -!function(t,e){"use strict";"object"==typeof module&&module.exports?module.exports=e(t.test):t.test=e(t.test)}(this,function(){"use strict";const t={_tests:{},run:function(t,e){"boolean"!=typeof t&&(e=t,t=!0);let o=this._tests,r=[],n=[];return Object.keys(o).forEach(e=>{let s=o[e];try{s(),n.push(`\n+OK ${e}`)}catch(o){t?r.push(`\n-ERR ${e} \n --- \n ${o.stack} \n ---`):r.push(`\n-ERR ${e}`)}}),"function"==typeof e?e({pass:n,fail:r}):(console.log(...n,...r),console.log(`\n# tests ${r.length+n.length} pass ${n.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:function(e){return{to:{be:{a:o=>t.expects(e).to.be.an(o),an:t=>{if(-1!==["array"].indexOf(t)){if("array"!==e.constructor.name.toLowerCase())throw new Error(`expected ${typeof e} to be an ${t}`);return!0}if(typeof e!==t)throw new Error(`expected ${typeof e} to be an ${t}`)},ok:()=>t.expects(e).to.exist(),like:t=>{if(e!=t)throw new Error(`expected ${e} == ${t}`)}},equal:t=>{if(e!==t)throw new Error(`expected ${e} === ${t}`)},exist:()=>{if(!e)throw new Error(`expected ${e} to be truthy`)},pass:()=>!0,fail:t=>{throw new Error(t)}}}}};return t}); \ No newline at end of file +const test={log:console.log,_tests:{},run:function(t,e){"boolean"!=typeof t&&(e=t,t=!0);let r=this._tests||[],o=[],n=[];return Object.keys(r).forEach(e=>{let s=r[e];try{s(),n.push(`\n+OK ${e}`)}catch(r){t?o.push(`\n-ERR ${e} \n --- \n ${r.stack} \n ---`):o.push(`\n-ERR ${e}`)}}),"function"==typeof e?e({pass:n,fail:o}):(test.log(...n,...o),test.log(`\n# tests ${o.length+n.length} pass ${n.length} fail ${o.length}`),!o.length)},it:function(t){return this._tests=t,this},expects:function(t){return{to:{be:{a:e=>test.expects(t).to.be.an(e),an:e=>{if(-1!==["array"].indexOf(e)){if("array"!==t.constructor.name.toLowerCase())throw new Error(`expected ${typeof t} to be an ${e}`);return!0}if(typeof t!==e)throw new Error(`expected ${typeof t} to be an ${e}`)},ok:()=>test.expects(t).to.exist(),like:e=>{if(t!=e)throw new Error(`expected ${t} == ${e}`)}},equal:e=>{if(t!==e)throw new Error(`expected ${t} === ${e}`)},exist:()=>{if(!t)throw new Error(`expected ${t} to be truthy`)},pass:()=>!0,fail:t=>{throw new Error(t)}}}}};export default test; \ No newline at end of file diff --git a/dist/testit.umd.js b/dist/testit.umd.js new file mode 100644 index 0000000..dbb6a19 --- /dev/null +++ b/dist/testit.umd.js @@ -0,0 +1,97 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define('umd', factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.umd = factory()); +}(this, (function () { 'use strict'; + +/*! Test.it v 0.9.0 | MIT | https://github.com/n2geoff/testit */ + const test = { + "log": console.log, + "_tests": {}, + "run": function run(errors, next) { + if(typeof errors !== "boolean") { + next = errors; + errors = true; + } + + let tests = this._tests || []; + let failed = []; + let passed = []; + + Object.keys(tests).forEach((name) => { + let test = tests[name]; + + try { + test(); + passed.push(`\n+OK ${name}`); + } catch (err) { + if (errors) { + failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`); + } else { + failed.push(`\n-ERR ${name}`); + } + } + }); + + if(typeof next === "function") { + return next({ + pass: passed, + fail: failed + }); + } else { + test.log(...passed, ...failed); + test.log(`\n# tests ${failed.length + passed.length} pass ${passed.length} fail ${failed.length}`); + + return failed.length ? false : true; + } + }, + "it": function it(tests) { + this._tests = tests; + return this; + }, + "expects": function expects(val) { + return { + "to": { + "be": { + "a": (type) => { return test.expects(val).to.be.an(type); }, + "an": (type) => { + + if(["array"].indexOf(type) !== -1) { + if(val.constructor.name.toLowerCase() !== "array") { + throw new Error(`expected ${typeof val} to be an ${type}`); + } + + return true; + } + + if(typeof val !== type) { + throw new Error(`expected ${typeof val} to be an ${type}`); + } + }, + "ok": () => { return test.expects(val).to.exist(); }, + "like": (comp) => { + if(val != comp) { + throw new Error(`expected ${val} == ${comp}`); + } + } + }, + "equal": (comp) => { + if(val !== comp) { + throw new Error(`expected ${val} === ${comp}`); + } + }, + "exist": () => { + if(!val) { + throw new Error(`expected ${val} to be truthy`); + } + }, + "pass": () => { return true; }, + "fail": (msg) => { throw new Error(msg); } + } + }; + } + }; + + return test; + +}))); diff --git a/dist/testit.umd.min.js b/dist/testit.umd.min.js new file mode 100644 index 0000000..7fa3ade --- /dev/null +++ b/dist/testit.umd.min.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define("umd",t):(e="undefined"!=typeof globalThis?globalThis:e||self).umd=t()}(this,function(){"use strict";const e={log:console.log,_tests:{},run:function(t,o){"boolean"!=typeof t&&(o=t,t=!0);let n=this._tests||[],r=[],s=[];return Object.keys(n).forEach(e=>{let o=n[e];try{o(),s.push(`\n+OK ${e}`)}catch(o){t?r.push(`\n-ERR ${e} \n --- \n ${o.stack} \n ---`):r.push(`\n-ERR ${e}`)}}),"function"==typeof o?o({pass:s,fail:r}):(e.log(...s,...r),e.log(`\n# tests ${r.length+s.length} pass ${s.length} fail ${r.length}`),!r.length)},it:function(e){return this._tests=e,this},expects:function(t){return{to:{be:{a:o=>e.expects(t).to.be.an(o),an:e=>{if(-1!==["array"].indexOf(e)){if("array"!==t.constructor.name.toLowerCase())throw new Error(`expected ${typeof t} to be an ${e}`);return!0}if(typeof t!==e)throw new Error(`expected ${typeof t} to be an ${e}`)},ok:()=>e.expects(t).to.exist(),like:e=>{if(t!=e)throw new Error(`expected ${t} == ${e}`)}},equal:e=>{if(t!==e)throw new Error(`expected ${t} === ${e}`)},exist:()=>{if(!t)throw new Error(`expected ${t} to be truthy`)},pass:()=>!0,fail:e=>{throw new Error(e)}}}}};return e}); \ No newline at end of file