-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
results.ts
249 lines (229 loc) · 6.14 KB
/
results.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* eslint-disable @cypress/dev/arrow-body-multiline-braces */
import _ from 'lodash'
import type { FoundBrowser, SpecWithRelativeRoot } from '@packages/types'
import path from 'path'
import type { Cfg } from '../project-base'
type dateTimeISO = string
type ms = number
type pixels = number
interface TestError {
message: string
name: string
stack: string
}
interface AttemptResult {
error: TestError | null
failedFromHookId: string | null
state: string
timings: {
lifecycle: number
test: {
afterFnDuration: number
fnDuration: number
}
} | null
videoTimestamp: ms | null
wallClockStartedAt: dateTimeISO | null
wallClockDuration: ms | null
}
interface TestResult {
attempts: AttemptResult[]
body: string
displayError: string | null
state: string
title: string[]
}
type HookName = 'before' | 'beforeEach' | 'afterEach' | 'after'
interface HookInformation {
hookName: HookName
title: string[]
body: string
}
interface ScreenshotInformation {
height: pixels
name: string
path: string
takenAt: dateTimeISO
width: pixels
}
interface RunResult {
error: string | null
hooks: HookInformation[]
reporter: string
reporterStats: object
screenshots: ScreenshotInformation[]
skippedSpec: boolean
spec: SpecWithRelativeRoot
stats: {
duration: ms
failures: number
passes: number
pending: number
skipped: number
suites: number
tests: number
wallClockDuration?: number
wallClockEndedAt: dateTimeISO
wallClockStartedAt: dateTimeISO
}
tests: TestResult[]
video: string | null
}
export interface CypressRunResult {
browserName: string
browserPath: string
browserVersion: string
config: Cfg
cypressVersion: string
endedTestsAt: dateTimeISO
osName: string
osVersion: string
runs: RunResult[]
runUrl?: string
startedTestsAt: dateTimeISO
status: 'finished'
totalDuration: ms
totalFailed: number
totalPassed: number
totalPending: number
totalSkipped: number
totalSuites: number
totalTests: number
}
const createPublicTest = (test: TestResult): CypressCommandLine.TestResult => {
const duration = _.reduce(test.attempts, (memo, attempt) => {
return memo + (attempt.wallClockDuration || 0)
}, 0)
return {
attempts: _.map(test.attempts, ({ state }) => ({ state })),
displayError: test.displayError,
duration,
state: test.state,
title: test.title,
}
}
const createPublicRun = (run: RunResult): CypressCommandLine.RunResult => ({
error: run.error,
reporter: run.reporter,
reporterStats: run.reporterStats,
screenshots: _.map(run.screenshots, (screenshot) => ({
height: screenshot.height,
name: screenshot.name,
path: screenshot.path,
takenAt: screenshot.takenAt,
width: screenshot.width,
})),
spec: createPublicSpec(run.spec),
stats: {
duration: run.stats.wallClockDuration,
endedAt: run.stats.wallClockEndedAt,
failures: run.stats.failures,
passes: run.stats.passes,
pending: run.stats.pending,
skipped: run.stats.skipped,
startedAt: run.stats.wallClockStartedAt,
suites: run.stats.suites,
tests: run.stats.tests,
},
tests: _.map(run.tests, createPublicTest),
video: run.video,
})
/**
* Normalize browser object to remove private props and make it more consistent
*/
export const createPublicBrowser = (browser: Cypress.Browser | FoundBrowser): Cypress.PublicBrowser => {
return {
channel: browser.channel,
displayName: browser.displayName,
family: browser.family,
majorVersion: browser.majorVersion,
name: browser.name,
path: browser.path,
version: browser.version,
}
}
const omitConfigKeys = [
'additionalIgnorePattern',
'autoOpen',
'browserUrl',
'clientRoute',
'cypressEnv',
'devServerPublicPathRoute',
'morgan',
'namespace',
'proxyServer',
'proxyUrl',
'rawJson',
'remote',
'repoRoot',
'report',
'reporterRoute',
'reporterUrl',
'resolved',
'setupNodeEvents',
'socketId',
'socketIoCookie',
'socketIoRoute',
'specs',
'state',
'supportFolder',
'protocolEnabled',
'hideCommandLog',
'hideRunnerUi',
]
/**
* Normalize config object to remove private props and make it more consistent
*/
export const createPublicConfig = (config: Cfg): CypressCommandLine.PublicConfig => {
// this removes/changes values while leaving all others as-is, so that new
// config properties don't need to be manually accounted for
return {
..._.omit(config, omitConfigKeys) as Omit<CypressCommandLine.PublicConfig, 'browsers' | 'cypressInternalEnv'>,
browsers: _.map(config.browsers, createPublicBrowser),
// @ts-expect-error
cypressInternalEnv: config.cypressEnv,
}
}
/**
* Normalize results for module API/after:run to remove private props and make
* them more consistent and user-friendly
*/
export const createPublicRunResults = (results: CypressRunResult): CypressCommandLine.CypressRunResult => ({
browserName: results.browserName,
browserPath: results.browserPath,
browserVersion: results.browserVersion,
config: createPublicConfig(results.config),
cypressVersion: results.cypressVersion,
endedTestsAt: results.endedTestsAt,
osName: results.osName,
osVersion: results.osVersion,
runs: _.map(results.runs, createPublicRun),
runUrl: results.runUrl,
startedTestsAt: results.startedTestsAt,
totalDuration: results.totalDuration,
totalFailed: results.totalFailed,
totalPassed: results.totalPassed,
totalPending: results.totalPending,
totalSkipped: results.totalSkipped,
totalSuites: results.totalSuites,
totalTests: results.totalTests,
})
/**
* Normalize spec object to remove private props and make it more consistent
*/
export const createPublicSpec = (spec: SpecWithRelativeRoot): CypressCommandLine.SpecResult => {
return {
absolute: spec.absolute,
fileExtension: spec.fileExtension,
fileName: spec.fileName,
name: path.basename(spec.name || ''),
relative: spec.relative,
}
}
/**
* Normalize results for after:spec to remove private props and make
* them more consistent and user-friendly
*/
export const createPublicSpecResults = (spec: SpecWithRelativeRoot, runResult: RunResult) => {
return [createPublicSpec(spec), createPublicRun(runResult)]
}