-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
performance-reporter.js
124 lines (100 loc) · 3.63 KB
/
performance-reporter.js
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
const path = require('path')
const chalk = require('chalk')
const Libhoney = require('libhoney')
const { v4: uuidv4 } = require('uuid')
const ciProvider = require('@packages/server/lib/util/ci_provider')
const { commitInfo } = require('@cypress/commit-info')
const { getNextVersionForPath } = require('../../scripts/get-next-version')
class HoneycombReporter {
constructor (runner) {
if (!process.env.HONEYCOMB_API_KEY) {
return
}
console.log(chalk.green('Reporting to honeycomb'))
this.honey = new Libhoney({
dataset: 'systemtest-performance',
writeKey: process.env.HONEYCOMB_API_KEY,
})
runner.on('suite', (suite) => {
if (suite.root) {
suite.honeycombEvent = this.rootEvent()
return
}
suite.honeycombEvent = this.honey.newEvent()
suite.honeycombEvent.timestamp = Date.now()
suite.honeycombEvent.add({
suite: suite.title,
specFile: path.basename(suite.file),
spanId: uuidv4(),
parentId: suite.parent.honeycombEvent.data.spanId,
traceId: suite.parent.honeycombEvent.data.traceId,
})
})
runner.on('test', (test) => {
const title = test.titlePath().join(' / ')
// This regex pulls apart a string like `e2e async timeouts / failing1 [electron]`
// into `e2e async timeouts / failing1` and `electron`, letting us use the same
// test name for all browsers, with the browser as a separate field.
// The browser capture group is optional because some tests aren't browser specific,
// in which case it will be undefined and not passed as a field to honeycomb.
const [, testTitle, browser] = title.match(/(.+?)(?: \[([a-z]+)\])?$/)
test.honeycombEvent = this.honey.newEvent()
test.honeycombEvent.timestamp = Date.now()
test.honeycombEvent.add({
test: testTitle,
browser,
spanId: uuidv4(),
parentId: test.parent.honeycombEvent.data.spanId,
traceId: test.parent.honeycombEvent.data.traceId,
})
})
runner.on('test end', (test) => {
// Skipped tests never get a 'start' event, but they still get 'test end' somehow.
if (!test.state || test.state === 'skipped') {
return
}
test.honeycombEvent.add({
state: test.state,
err: test.err && test.err.message,
errStack: test.err && test.err.stack,
durationMs: Date.now() - test.honeycombEvent.timestamp,
})
test.honeycombEvent.send()
})
runner.on('suite end', (suite) => {
suite.honeycombEvent.add({
durationMs: Date.now() - suite.honeycombEvent.timestamp,
})
suite.honeycombEvent.send()
})
}
// If there is no done callback, then mocha-multi-reporter will kill the process without waiting for our honeycomb post to complete.
done (failures, callback) {
if (this.honey) {
this.honey.flush().then(callback)
}
}
rootEvent () {
const honeycombEvent = this.honey.newEvent()
honeycombEvent.timestamp = Date.now()
honeycombEvent.add({
buildUrl: process.env.CIRCLE_BUILD_URL,
platform: process.platform,
arch: process.arch,
spanId: uuidv4(),
traceId: uuidv4(),
})
commitInfo().then((commitInformation) => {
const ciInformation = ciProvider.commitParams() || {}
honeycombEvent.add({
branch: commitInformation.branch || ciInformation.branch,
commitSha: commitInformation.sha || ciInformation.sha,
})
})
getNextVersionForPath('../../packages').then((next) => {
honeycombEvent.add({ nextVersion: next })
})
return honeycombEvent
}
}
module.exports = HoneycombReporter