/
default.ts
58 lines (50 loc) · 1.74 KB
/
default.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
import c from 'picocolors'
import type { UserConsoleLog } from '../../types'
import { BaseReporter } from './base'
import type { ListRendererOptions } from './renderers/listRenderer'
import { createListRenderer } from './renderers/listRenderer'
export class DefaultReporter extends BaseReporter {
renderer?: ReturnType<typeof createListRenderer>
rendererOptions: ListRendererOptions = {} as any
async onTestRemoved(trigger?: string) {
await this.stopListRender()
this.ctx.clearScreen()
this.ctx.log(c.yellow('Test removed...') + (trigger ? c.dim(` [ ${this.relative(trigger)} ]\n`) : ''))
const files = this.ctx.state.getFiles(this.watchFilters)
createListRenderer(files, this.rendererOptions).stop()
this.ctx.log()
await super.reportSummary(files)
super.onWatcherStart()
}
onCollected() {
if (this.isTTY) {
this.rendererOptions.outputStream = this.ctx.outputStream
const files = this.ctx.state.getFiles(this.watchFilters)
if (!this.renderer)
this.renderer = createListRenderer(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.log()
await super.onFinished(files, errors)
}
async onWatcherStart() {
await this.stopListRender()
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) {
this.renderer?.clear()
super.onUserConsoleLog(log)
}
}