updated output format

This commit is contained in:
Geoff Doty 2018-12-02 03:43:35 -05:00
parent e72a99fec1
commit c4cf2ed933
5 changed files with 20 additions and 22 deletions

View File

@ -42,19 +42,20 @@ test.it({
by default, your test results are logged to the console by default, your test results are logged to the console
``` ```
+ my passing test +OK my passing test
- my failing test -ERR my failing test
- - Error: just wanted to fail fast ---
Error: just wanted to fail fast
...error stack... ...error stack...
---
# tests 2 pass 1 fail 1 # tests 2 pass 1 fail 1
``` ```
A `+` will proceed test lines that *pass* and a `-` for those that *fail*, the trace back `file:line` is included after the failing test proceeded by `- -` A `+OK` will proceed test lines that *pass* and a `-ERR` for those that *fail*, the error stack is included after the failing test wrapped in `---`
You can, however, write your own custom test runner... You can, however, write your own custom test runner...
> NOTE: API still in flux, and may change to closer match TAP
### Custom Test Runners ### Custom Test Runners
`test.it` `.run()` method provides an optional `next` function parameter that passes the results as an `object` for you to process *however* you like. `test.it` `.run()` method provides an optional `next` function parameter that passes the results as an `object` for you to process *however* you like.
@ -95,7 +96,7 @@ A sample test runner is provided for both **HTML** and **NODE** in the `test/` d
To stay minimal, `test.it` only has 3 core functions: To stay minimal, `test.it` only has 3 core functions:
- `it` to capture your tests - `it` to capture your tests
- `run` to execute yours tests - `run` to execute yours tests
- and `expects` to write your test assertions - and `expects` to write your assertions
While you can use your own assertion library, the included `expects` provides the following methods for writing your tests: While you can use your own assertion library, the included `expects` provides the following methods for writing your tests:
@ -136,7 +137,7 @@ Please open [an issue](https://github.com/n2geoff/testit/issues/new) for support
## Contributing ## Contributing
Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the [guidelines](CONTRIBUTING.md), there minimalistic;) Anyone is welcome to contribute, however, if you decide to get involved, please take a moment to review the [guidelines](CONTRIBUTING.md), they're minimalistic;)
## License ## License

7
dist/testit.js vendored
View File

@ -1,4 +1,4 @@
/*! Test.it v 0.7.1 | MIT | https://github.com/n2geoff/testit */ /*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
(function (root, factory) { (function (root, factory) {
"use strict"; "use strict";
if (typeof module === "object" && module.exports) { if (typeof module === "object" && module.exports) {
@ -22,10 +22,9 @@
try { try {
test(); test();
passed.push(`\n+ ${name}`); passed.push(`\n+OK ${name}`);
} catch (err) { } catch (err) {
failed.push(`\n- ${name}`); failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
console.error(err);
} }
}); });

3
dist/testit.min.js vendored
View File

@ -1,2 +1 @@
/*! Test.it v 0.7.1 | 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){let e=this._tests,r=[],o=[];return Object.keys(e).forEach(t=>{let n=e[t];try{n(),o.push(`\n+OK ${t}`)}catch(e){r.push(`\n-ERR ${t} \n --- \n ${e.stack} \n ---`)}}),"function"==typeof t?t({pass:o,fail:r}):(console.log(...o,...r),console.log(`\n# tests ${r.length+o.length} pass ${o.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:function(e){return{to:{be:{a:r=>t.expects(e).to.be.an(r),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}`)},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});
!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){let e=this._tests,r=[],o=[];return Object.keys(e).forEach(t=>{let n=e[t];try{n(),o.push(`\n+ ${t}`)}catch(e){r.push(`\n- ${t}`),console.error(e)}}),"function"==typeof t?t({pass:o,fail:r}):(console.log(...o,...r),console.log(`\n# tests ${r.length+o.length} pass ${o.length} fail ${r.length}`),!r.length)},it:function(t){return this._tests=t,this},expects:function(e){return{to:{be:{a:r=>t.expects(e).to.be.an(r),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}`)},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});

View File

@ -1,6 +1,6 @@
{ {
"name": "testit", "name": "testit",
"version": "0.7.1", "version": "0.8.0",
"description": "a minimalistic testing library", "description": "a minimalistic testing library",
"main": "src/testit.js", "main": "src/testit.js",
"directories": { "directories": {

View File

@ -1,4 +1,4 @@
/*! Test.it v 0.7.1 | MIT | https://github.com/n2geoff/testit */ /*! Test.it v 0.8.0 | MIT | https://github.com/n2geoff/testit */
(function (root, factory) { (function (root, factory) {
"use strict"; "use strict";
// support browser & commonjs // support browser & commonjs
@ -26,10 +26,9 @@
// execute // execute
try { try {
test(); test();
passed.push(`\n+ ${name}`); passed.push(`\n+OK ${name}`);
} catch (err) { } catch (err) {
failed.push(`\n- ${name}`); failed.push(`\n-ERR ${name} \n --- \n ${err.stack} \n ---`);
console.error(err);
} }
}); });