This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render coloured error messages to the terminal.
- Loading branch information
0 parents
commit 05bb559
Showing
5 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
node_modules/* | ||
npm_debug.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
var it = require ('it-is') | ||
, trv = require ('test-report-view') | ||
, errors = [ | ||
null | ||
, 7 | ||
, Math.random() | ||
, true | ||
, false | ||
, NaN | ||
, undefined | ||
, {} | ||
, function(){} | ||
, catchError(function () { | ||
(null).x = 7 //type error | ||
}) | ||
, catchError(function () { | ||
'onehu'() //type error | ||
}) | ||
, catchError(function stackOverFlow() { | ||
stackOverFlow() | ||
}) | ||
, {error: 'not_found', reason: 'this is a couch error'} | ||
, new Error('EXAMPLE ERROR') | ||
] | ||
|
||
function catchError(funx) { | ||
try { funx() } catch (err) { return err } | ||
throw new Error( 'expected funx to throw' ) | ||
} | ||
|
||
errors.forEach(function (e){ | ||
var str = trv.viewError(e) | ||
console.log('example error output:', str) | ||
it(str).ok().typeof('string') | ||
if('string' !== typeof e) { | ||
if(/\[object( \w+)?\]/(str)) | ||
throw Error(str + ' should not match: /\[object( \w+)?\]/') | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ "name": "test-report-view_tests" | ||
, "version": "0.0.0" | ||
, "description": "tests for test-report-view" | ||
, "homepage": "http://github.com/dominictarr/test-report-view_tests" | ||
, "repository": | ||
{ "type": "git" | ||
, "url": "https://github.com/dominictarr/test-report-view_tests.git" } | ||
, "dependencies": {} | ||
, "devDependencies": {} | ||
, "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://bit.ly/dominictarr)" | ||
, "scripts": { "test": "meta-test test/*.js" } } |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
var trv = require('test-report-view') | ||
, it = require('it-is') | ||
, Reporter = require('test-report') | ||
|
||
;(function simple() { | ||
var reporter = new Reporter ('example') | ||
|
||
reporter.test('test1').test('test2') | ||
console.log(reporter) | ||
var str = trv.view(reporter.report) | ||
console.log(str) | ||
|
||
it(str).matches(/example/).matches(/test1/).matches(/test2/) | ||
|
||
})() | ||
|
||
;(function nested() { | ||
var reporter = new Reporter ('example') | ||
|
||
reporter.test('test1').test('test2').subreport('nested').test('inner') | ||
var str = trv.view(reporter.report) | ||
console.log(str) | ||
|
||
it(str).matches(/example/).matches(/test1/).matches(/test2/).matches(/nested/).matches(/inner/) | ||
|
||
})() | ||
|
||
;(function errors() { | ||
var reporter = new Reporter ('example') | ||
, err = new Error('EXAMPLE ERROR') | ||
reporter.test('fail', err) | ||
var str = trv.view(reporter.report) | ||
console.log(str) | ||
|
||
it(str).matches(/example/).matches(/fail/) | ||
it(str.indexOf('Error: EXAMPLE ERROR\n')).notEqual(-1) | ||
// str contains at least the first line of the error. | ||
it(str.indexOf(trv.viewError(err).split('\n')[0])).notEqual(-1) | ||
})() |