-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
137 lines (124 loc) · 3.32 KB
/
index.js
File metadata and controls
137 lines (124 loc) · 3.32 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import ansi from 'ansi-escape-sequences'
/**
* Custom view API.
*/
class LiveView {
constructor (options) {
this.options = options
this.fails = []
}
log (...args) {
if (this.prevLineCount) {
process.stdout.write(ansi.cursor.previousLine(this.prevLineCount))
}
console.log(ansi.format(args.join(' ')))
}
/**
* Runner start.
* @param {number}
*/
start (count) {
this.log()
this.printTree()
}
/**
* Test start
* @param {Tom}
*/
testStart (test) {
this.printTree()
}
/**
* Test passed.
* @param {Tom}
* @param {*}
*/
testPass (test, result) {
this.printTree()
}
/**
* Test passed.
* @param {Tom}
* @param {*}
*/
testFail (test, err) {
this.printTree()
this.fails.push(test)
}
/**
* Test skipped.
* @param {Tom}
*/
testSkip (test) {
this.printTree()
}
/**
* @params {object} stats
* @params {object} stats.fail
* @params {object} stats.pass
* @params {object} stats.skip
* @params {object} stats.start
* @params {object} stats.end
*/
_end () {
const stats = this.runner.stats
this.prevLineCount = 0
const failColour = stats.fail > 0 ? 'red' : 'white'
const passColour = stats.pass > 0 ? 'green' : 'white'
const skipColour = stats.skip > 0 ? 'grey' : 'white'
const inProgressColour = stats.inProgress > 0 ? 'rgb(255,191,0)' : 'white'
const statsSummary = `\nIn-progress: [${inProgressColour}]{${stats.inProgress}}, pass: [${passColour}]{${stats.pass}}, fail: [${failColour}]{${stats.fail}}, skip: [${skipColour}]{${stats.skip}}, todo: [${skipColour}]{${stats.todo}}.\n`
this.log(statsSummary)
const fails = []
for (const test of this.fails) {
const err = test.result
const parent = test.parent ? test.parent.name : ''
fails.push(`[red]{⨯} [magenta]{${parent}} ${test.name}`)
const lines = err.stack.split('\n').map(line => {
return ' ' + line
})
fails.push(`\n${lines.join('\n').trimEnd()}\n`)
}
if (fails.length) {
this.log(fails.join('\n'))
}
}
printTree () {
const groups = Array.from(this.runner.tom).filter(t => t.type === 'group')
const lines = []
for (const group of groups) {
const line = [ansi.erase.inLine(2)]
const indent = ' '.repeat(group.level())
line.push(`${indent}- [magenta]{${group.name}} `)
for (const test of group.children) {
if (test.type !== 'group') {
if (test.state === 'pass') {
line.push('[green]{✓}')
} else if (test.state === 'fail') {
line.push('[red]{⨯}')
} else if (test.state === 'in-progress') {
line.push('[rgb(255,191,0)]{•}')
} else if (test.state === 'skipped') {
line.push('[grey]{-}')
} else if (test.state === 'pending') {
line.push(`[white]{•}`)
} else if (test.state === 'ignored') {
line.push(`[yellow]{•}`)
} else if (test.state === 'todo') {
line.push(`[cyan]{•}`)
}
}
}
lines.push(line.join(''))
}
this.log(lines.join('\n'))
this._end()
this.prevLineCount = lines.length + 3
}
/**
* Option definitions.
* @returns {OptionDefinition[]}
*/
static optionDefinitions () {}
}
export default LiveView