-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreporter.ts
More file actions
81 lines (67 loc) · 2.26 KB
/
reporter.ts
File metadata and controls
81 lines (67 loc) · 2.26 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
import WebdriverIOReporter, { type SuiteStats, type TestStats } from '@wdio/reporter'
import { mapTestToSource, setCurrentSpecFile, mapSuiteToSource } from './utils.js'
export class TestReporter extends WebdriverIOReporter {
#report: (data: any) => void
#currentSpecFile?: string
#suitePath: string[] = []
constructor (options: any, report: (data: any) => void) {
super(options)
this.#report = report
}
onSuiteStart(suiteStats: SuiteStats): void {
super.onSuiteStart(suiteStats)
this.#currentSpecFile = suiteStats.file
setCurrentSpecFile(suiteStats.file)
// Push title if non-empty
if (suiteStats.title) this.#suitePath.push(suiteStats.title)
// Enrich and set callSource for suites
mapSuiteToSource(suiteStats as any, this.#currentSpecFile, this.#suitePath)
if ((suiteStats as any).file && (suiteStats as any).line != null) {
;(suiteStats as any).callSource = `${(suiteStats as any).file}:${(suiteStats as any).line}`
}
this.#sendUpstream()
}
onTestStart(testStats: TestStats): void {
// Enrich testStats with callSource info
mapTestToSource(testStats, this.#currentSpecFile)
if ((testStats as any).file && (testStats as any).line != null) {
;(testStats as any).callSource = `${(testStats as any).file}:${(testStats as any).line}`
}
super.onTestStart(testStats)
this.#sendUpstream()
}
onTestEnd(testStats: TestStats): void {
super.onTestEnd(testStats)
this.#sendUpstream()
}
onSuiteEnd(suiteStats: SuiteStats): void {
super.onSuiteEnd(suiteStats)
// Pop the suite we pushed on start
if (suiteStats.title && this.#suitePath[this.#suitePath.length - 1] === suiteStats.title) {
this.#suitePath.pop()
}
// Only clear when the last suite ends
if (this.#suitePath.length === 0) {
this.#currentSpecFile = undefined
setCurrentSpecFile(undefined)
}
this.#sendUpstream()
}
#sendUpstream () {
if (!this.suites) {
return
}
const payload: Record<string, SuiteStats>[] = []
for (const [uid, suite] of Object.entries(this.suites)) {
if (suite) {
payload.push({ [uid]: suite })
}
}
if (payload.length > 0) {
this.#report(payload)
}
}
get report () {
return this.suites
}
}