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

Commit

Permalink
refactoring reports to be more consistant.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictarr committed May 27, 2011
1 parent 63b9e4a commit 59f7581
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 223 deletions.
9 changes: 4 additions & 5 deletions report.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ function getStatus (array){

Report.prototype = {
test: function (name,error){



if(!this.tests[name]) {
var test =
{ name: name
Expand All @@ -57,7 +56,7 @@ Report.prototype = {
return this
}
, error: function (err){
this.report.errors.push (err)
this.report.failures.push (err)

return this
}
Expand All @@ -72,12 +71,12 @@ function Report (filename){
if(!(this instanceof Report)) return new Report(filename)
this.report =
{ filename: filename
, errors: []
, failures: []
, os: process.platform
, version: process.version
, meta: {}
, get status (){
var m = getStatus(this.errors),
var m = getStatus(this.failures),
n = min(this.tests,function (e){return e.status})
return n < m ? n : m
}
Expand Down
18 changes: 9 additions & 9 deletions runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function run(opts,cb){

var child = spawn((opts.command || process.execPath), [ __dirname + '/child_runner.js', JSON.stringify(opts) ])
, stderr = ''
, errors = []
, failures = []

child.stdout.on('data',function(e){ process.stdout.write(e) })
child.stderr.on('data',function(e){ stderr += '' + e; process.stderr.write(e) })
Expand All @@ -24,18 +24,18 @@ function run(opts,cb){
, timer =
setTimeout(function stop (){
child.kill('SIGTSTP')
errors.push(new Error("test '" + opts.filename + "' did not complete in under " + timeToRun + " milliseconds"))
failures.push(new Error("test '" + opts.filename + "' did not complete in under " + timeToRun + " milliseconds"))
timer = setTimeout(function kill(){
child.kill()
errors.push(new Error("test didn't exit properly after timeout. KILLED."))
failures.push(new Error("test didn't exit properly after timeout. KILLED."))
},250)
},timeToRun)

child.on('exit',function (exStatus){

if(exStatus){
errors.push(stderr)
errors.push(exStatus)
failures.push(stderr)
failures.push(exStatus)
}
clearTimeout(timer)
fs.readFile(opts.tempfile, 'utf-8', c)
Expand All @@ -44,18 +44,18 @@ function run(opts,cb){
if(!err)
fs.unlink(opts.tempfile)
else
errors.push(err)
failures.push(err)
try {
var report = untangle.parse(json)
report.errors = [].concat(report.errors).concat(errors)
if(report.errors.length && report.status === 'success')
report.failures = [].concat(report.failures).concat(failures)
if(report.failures.length && report.status === 'success')
report.status = 'error'
cb(null,report)
} catch (err){
cb(null,{ filename: opts.filename
, tests: []
, status : 'error'
, errors: errors
, failures: failures
, version: opts.version
})
}
Expand Down
34 changes: 17 additions & 17 deletions test/report.node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//report.expresso.js

var it, is = it = require('it-is')
var it = require('it-is')
, Report = require('../report')
, helper = require('./lib/helper')
, test = module.exports
Expand All @@ -11,8 +11,8 @@ test ['a Report'] = function (){

it(Report(__filename))
.has({
report: is.complex()
, test: is.function()
report: it.complex()
, test: it.function()
})
var r = Report(__filename)

Expand Down Expand Up @@ -44,7 +44,7 @@ test ['a Report with an several errors'] = function (){
it(r.report)
.has({
filename: __filename
, tests: [ {name: 'error', failures: [is.equal(err),is.equal(err2)] } ]
, tests: [ {name: 'error', failures: [it.equal(err),it.equal(err2)] } ]
})
}

Expand All @@ -63,10 +63,10 @@ test ['a Report with status'] = function (){
filename: __filename
, tests: [
{ name: 'error'
, failures: [is.equal(err)]
, failures: [it.equal(err)]
, status: Report.status.error }
, { name: 'fail'
, failures: [is.equal(ass)]
, failures: [it.equal(ass)]
, status: Report.status.failure }
, { name: 'pass'
, failures: it.deepEqual([])
Expand All @@ -85,8 +85,8 @@ test ['a Report with a global error'] = function (){
it(r.report)
.has({
filename: __filename
, tests: is.deepEqual([])
, errors: [is.equal(err)]
, tests: it.deepEqual([])
, failures: [it.equal(err)]
, status: Report.status.error
})
}
Expand All @@ -99,12 +99,12 @@ test ['a Report with a global string error'] = function (){
it(r.report)
.has({
filename: __filename
, tests: is.deepEqual([])
, errors: [is.equal(err)]
, tests: it.deepEqual([])
, failures: [it.equal(err)]
, status: Report.status.error
})
}
test ['any thrown non AssertionError is an error status'] = function (){
test ['any thrown non AssertionError it an error status'] = function (){
var errors = [[], new Error, "hello", false, 324, undefined, null]

it(errors)
Expand Down Expand Up @@ -135,8 +135,8 @@ test ['a Report with a global string error'] = function (){
it(r.report)
.has({
filename: __filename
, tests: is.deepEqual([])
, errors: is.deepEqual([undefined])
, tests: it.deepEqual([])
, failures: it.deepEqual([undefined])
, status: Report.status.error
})
}
Expand All @@ -151,8 +151,8 @@ test ['a Report with a global AssertionError'] = function (){
it(r.report)
.has({
filename: __filename
, tests: is.deepEqual([])
, errors: is.deepEqual([ass])
, tests: it.deepEqual([])
, failures: it.deepEqual([ass])
, status: Report.status.failure
})
}
Expand Down Expand Up @@ -181,9 +181,9 @@ test ['add metadata' ] = function (){
var r = Report(__filename)
, s = Report(__filename)

it(r.meta('returnThis','value')).equal(r)//return this so it's chainable.
it(r.meta('returnThit','value')).equal(r)//return thit so it's chainable.

it(r.report).has({meta:{'returnThis': 'value'}})
it(r.report).has({meta:{'returnThit': 'value'}})

}

Expand Down
176 changes: 0 additions & 176 deletions test/report.synct.js

This file was deleted.

7 changes: 0 additions & 7 deletions test/report2.node.js

This file was deleted.

Loading

0 comments on commit 59f7581

Please sign in to comment.