Report Tiny Validator tv4 results in usable formats
This module is used by various dependants to render
tv4 validation result objects in a compact but highly readable (and possibly colourful) format. Functionality is tuned for both CLI output as well as plain-text or pre-formatted HTML/CSS.
Note: at this point this is not a 'validator' or 'test runner', nor is it a finished application. It is a library to use as dependency in
tv4 based testers. Use plain
tv4 and pass the result(s) to one of
tv4-reporters helpers. If you are looking for a validator see one of the implementing tv4 wrappers for convenience (some linked below).
- Indented, tree-like display.
- Single and multiple errors.
- Optionally display summaries.
- Recursive sub-errors (as generated by
- Missing sub-schemas (optionally report as fail or pass reason).
- Various output writer/coloriser modes using ministyle and miniwrite.
- Examples of many different kind of errors in this Travis-Ci build.
- Bulk reporter with single error:
$ npm install tv4-reporter --save-dev
Still very-much in flux so possibly outdated examples.
Minimal use case (likely this is spread over the implementing application):
// assemble the componentsvar tv4 = require'tv4';var out = require'miniwrite'console;var style = require'ministyle'ansi;var reporter = require'tv4-reporter'getReporterout style;// now validatevar result = tv4validateMultiplemyValue mySchema;if !resultvalid || resultmissinglength > 0// get data object (might get these in bulk/async from somewhere)var res = reportercreateTestmySchema myValue 'my special test' true;// report errorreporterreportResultres;// if you have a many results you can use bulk to print nicely with summariesreporterreportBulkres res2 res3 pass1 pass2;// only totalsreporterreportTotals3 4;
// if you have a many results you can use bulk to print nicely with summariesreporterreportBulkres res2 res3 pass1 pass2;// only totalsreporterreportTotals3 4;
For more API surface like (partial) reporter and various helpers see the exports in the main module. Also see the 'known dependants' for more examples.
Report output and styling done via extensible mini-api's:
- ministyle (bundled with plain, ansi, html/css etc + utils)
- miniwrite (bundled with streaming console.log, line buffer, node-streams etc + utils)
- grunt-tv4 (bulk validator with http lookup for grunt)
- chai-json-schema (assertion wrappers) (update in progress)
- (planned) a commandline validator (cued for extraction from
- (planned) a json-schema assert()-ion (chai-json-schema without chai)
- Output will likely be tuned over time.
- Current version is very functional but doesn't yet do anything specific for each validation rule type.
- <= 0.0.4 - Many fixes and tweaks.
- 0.0.1 - Extracted formatting code from grunt-tv4 and chai-json-schema.
Nothing much here as the code is still being extracted from the original projects.
Install development dependencies in your git checkout:
$ npm install
Build and run tests:
Gruntfile.js for additional commands.
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Note: this is an opinionated module: please create a ticket to discuss any big ideas. Pull requests for bug fixes are of course always welcome.
Copyright (c) 2013 Bart van der Schoor
Licensed under the MIT license.