/
index.ts
60 lines (52 loc) · 1.86 KB
/
index.ts
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
import c from 'picocolors'
import type { UserConsoleLog } from '../../../../types'
import { BaseReporter } from '../../base'
import type { ListRendererOptions } from '../../renderers/listRenderer'
import { createTableRenderer } from './tableRender'
export class TableReporter extends BaseReporter {
renderer?: ReturnType<typeof createTableRenderer>
rendererOptions: ListRendererOptions = {} as any
async onTestRemoved(trigger?: string) {
await this.stopListRender()
this.ctx.logger.clearScreen(c.yellow('Test removed...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''), true)
const files = this.ctx.state.getFiles(this.watchFilters)
createTableRenderer(files, this.rendererOptions).stop()
this.ctx.logger.log()
await super.reportSummary(files)
super.onWatcherStart()
}
onCollected() {
if (this.isTTY) {
this.rendererOptions.logger = this.ctx.logger
this.rendererOptions.showHeap = this.ctx.config.logHeapUsage
const files = this.ctx.state.getFiles(this.watchFilters)
if (!this.renderer)
this.renderer = createTableRenderer(files, this.rendererOptions).start()
else
this.renderer.update(files)
}
}
async onFinished(files = this.ctx.state.getFiles(), errors = this.ctx.state.getUnhandledErrors()) {
await this.stopListRender()
this.ctx.logger.log()
await super.onFinished(files, errors)
}
async onWatcherStart() {
await this.stopListRender()
await super.onWatcherStart()
}
async stopListRender() {
await this.renderer?.stop()
this.renderer = undefined
}
async onWatcherRerun(files: string[], trigger?: string) {
await this.stopListRender()
await super.onWatcherRerun(files, trigger)
}
onUserConsoleLog(log: UserConsoleLog) {
if (!this.shouldLog(log))
return
this.renderer?.clear()
super.onUserConsoleLog(log)
}
}