update dist

This commit is contained in:
Geoff Doty 2020-09-08 17:37:54 -05:00
parent 85a491ce98
commit 0aa72d399b
5 changed files with 178 additions and 96 deletions

View File

@ -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*)

167
dist/testit.js vendored
View File

@ -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;

3
dist/testit.min.js vendored
View File

@ -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});
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;

97
dist/testit.umd.js vendored Normal file
View File

@ -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;
})));

1
dist/testit.umd.min.js vendored Normal file
View File

@ -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});