f5afe194df525855db0d7e05cfe2256409346bb7.svn-base
1.7 KB
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
const React = require('react')
const importJSX = require('import-jsx')
const Base = importJSX('../base')
const Footer = importJSX('./footer.js')
const Log = importJSX('./log.js')
const Summary = importJSX('./summary.js')
const chalk = require('chalk')
const TestPoint = importJSX('./test-point.js')
class Specy extends Base {
constructor ({tap}) {
super({tap})
this.lastThing = null
this.tap = tap
}
// just override these with no-ops
logRes () {}
tapResume () {}
// TODO: Instead of doing this on the root TAP object, save up all the
// results on each Test object, and then dump them out when the test ends.
// Test order is not important, but the asserts from one test can't be
// interleaved with another.
componentDidMount () {
const tap = this.tap
const onAssert = p => res => {
const c = p.lastChild
p.lastChild = null
if (c && res.name === c.name)
return
res.level = p.level
this.lastThing = 'assert'
this.setState(prevState => ({
...prevState,
log: prevState.log.concat({res}),
}))
}
const onParser = p => {
if (p.parent)
p.parent.lastChild = p
p.on('child', onParser)
p.on('assert', onAssert(p))
if (p.level === 0)
return
const raw = (this.lastThing === 'assert' ? '\n' : '')
+ new Array(p.level).join(' ') + p.name
this.lastThing = 'suite'
this.setState(prevState => ({
...prevState,
log: prevState.log.concat({raw}),
}))
}
onParser(tap.parser)
tap.resume()
}
get Log () {
return Log
}
get Footer () {
return Footer
}
get Summary () {
return Summary
}
}
module.exports = Specy