Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
render coloured error messages to the terminal.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed Jul 27, 2011
0 parents commit 05bb559
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
node_modules
node_modules/*
npm_debug.log
40 changes: 40 additions & 0 deletions errors.node.js
@@ -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+)?\]/')
}
})
11 changes: 11 additions & 0 deletions package.json
@@ -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 added readme.markdown
Empty file.
40 changes: 40 additions & 0 deletions simple.node.js
@@ -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)
})()

0 comments on commit 05bb559

Please sign in to comment.