This repository has been archived by the owner on Dec 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.js
86 lines (71 loc) · 1.71 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module.exports = Report
var stati =
{ started: 'started'
, success: 'success'
, failure: 'failure'
, error: 'error' }
, order = [stati.success, stati.failure, stati.error]
, assert = require('assert')
Report.status = stati
function update(old, newer){
var o = order.indexOf(old)
, n = order.indexOf(newer)
return order[o > n ? o : n]
}
function min (array,func){
var m = 'success'
for(var i in array){
var n = func(array[i],i,array)
if(n && n < m)
m = n
}
return m
}
function getStatus (array){
return min(array,function (e){
if(e && e.name && e.name === "AssertionError")
return stati.failure
return stati.error
})
}
Report.prototype = {
test: function (name,error){
if(!this.tests[name]) {
var test =
{ name: name
, failures: arguments.length > 1 ? [error] : []
, get status (){
return getStatus(this.failures)
}
}
this.report.tests.push(this.tests[name] = test)
} else if (arguments.length > 1)
this.tests[name].failures.push(error)
return this
}
, error: function (err){
this.report.failures.push (err)
return this
}
, meta: function (key,value){
this.report.meta[key] = value
return this
}
}
function Report (filename){
if(!(this instanceof Report)) return new Report(filename)
this.report =
{ name: filename
, filename: filename
, failures: []
, os: process.platform
, version: process.version
, meta: {}
, get status (){
var m = getStatus(this.failures),
n = min(this.tests,function (e){return e.status})
return n < m ? n : m
}
, tests: [] }
this.tests = {}
}