-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathreporters_spec.js
More file actions
204 lines (185 loc) · 6.6 KB
/
reporters_spec.js
File metadata and controls
204 lines (185 loc) · 6.6 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
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
const path = require('path')
const { fs } = require('@packages/server/lib/util/fs')
const glob = require('@packages/server/lib/util/glob')
const systemTests = require('../lib/system-tests').default
const Fixtures = require('../lib/fixtures')
const e2ePath = Fixtures.projectPath('e2e')
const mochaAwesomes = [
'mochawesome-7.1.4',
]
describe('e2e reporters', () => {
systemTests.setup()
it('reports error if cannot load reporter', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
snapshot: true,
expectedExitCode: 1,
reporter: 'module-does-not-exist',
config: {
screenshotOnRunFailure: false,
},
})
})
// https://github.com/cypress-io/cypress/issues/1192
it('reports error when thrown from reporter', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
snapshot: true,
expectedExitCode: 1,
reporter: 'reporters/throws.js',
config: {
screenshotOnRunFailure: false,
},
})
})
it('supports junit reporter and reporter options', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js,simple_failing.cy.js',
snapshot: true,
reporter: 'junit',
reporterOptions: 'mochaFile=junit-output/result.[hash].xml,testCaseSwitchClassnameAndName=true',
expectedExitCode: 2,
config: {
screenshotOnRunFailure: false,
},
})
.then(() => {
return glob(path.join(e2ePath, 'junit-output', 'result.*.xml'))
.then((paths) => {
expect(paths.length).to.eq(2)
return Promise.all([fs.readFileAsync(paths[0], 'utf8'), fs.readFileAsync(paths[1], 'utf8')])
.then((results) => {
const str = results.join('')
expect(str).to.include('<testsuite name="simple passing spec"')
expect(str).to.include('<testcase name="passes"')
expect(str).to.include('classname="simple passing spec passes"')
expect(str).to.include('<testsuite name="simple failing spec"')
expect(str).to.include('<testcase name="fails1"')
expect(str).to.include('<testcase name="fails2"')
expect(str).to.include('classname="simple failing spec fails1"')
expect(str).to.include('classname="simple failing spec fails2"')
})
})
})
})
it('supports local custom reporter', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
snapshot: true,
reporter: 'reporters/custom.js',
config: {
screenshotOnRunFailure: false,
},
})
})
it('sends file to reporter', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
reporter: 'reporters/uses-file.js',
config: {
screenshotOnRunFailure: false,
},
})
.then(({ stdout }) => {
expect(stdout).to.include('suite.file: cypress/e2e/simple_passing.cy.js')
})
})
describe('mochawesome', () => {
return mochaAwesomes.forEach((ma) => {
it(`passes with ${ma} npm custom reporter`, function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
snapshot: true,
// cypress supports passing module name, relative path, or absolute path
reporter: require.resolve(ma),
config: {
screenshotOnRunFailure: false,
},
})
.then(() => {
return fs.readJsonAsync(path.join(e2ePath, 'mochawesome-report', 'mochawesome.json'))
.then((json) => {
expect(json.stats).to.be.an('object')
expect(json.stats.passes).to.eq(1)
})
})
})
it(`pending with ${ma} npm custom reporter`, function () {
return systemTests.exec(this, {
spec: 'simple_pending.cy.js',
snapshot: true,
// cypress supports passing module name, relative path, or absolute path
reporter: require.resolve(ma),
config: {
screenshotOnRunFailure: false,
},
})
.then(() => {
return fs.readJsonAsync(path.join(e2ePath, 'mochawesome-report', 'mochawesome.json'))
.then((json) => {
expect(json.stats).to.be.an('object')
expect(json.stats.pending).to.eq(1)
// https://github.com/cypress-io/cypress/issues/24477
expect(json.stats.skipped).to.eq(0)
expect(json.stats.hasSkipped).to.eq(false)
})
})
})
it(`fails with ${ma} npm custom reporter`, function () {
return systemTests.exec(this, {
spec: 'simple_failing_hook.cy.js',
snapshot: true,
expectedExitCode: 3,
reporter: require.resolve(ma),
config: {
screenshotOnRunFailure: false,
},
})
.then(() => {
return fs.readJsonAsync(path.join(e2ePath, 'mochawesome-report', 'mochawesome.json'))
.then((json) => {
// mochawesome does not consider hooks to be
// 'failures' but it does collect them in 'other'
// HOWEVER we now change how mocha events fire to make mocha stats reflect ours
expect(json.stats).to.be.an('object')
expect(json.stats.passes).to.eq(1)
expect(json.stats.failures).to.eq(3)
expect(json.stats.skipped).to.eq(1)
expect(json.stats.other).to.eq(0)
})
})
})
})
})
it('supports teamcity reporter and reporter options', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
snapshot: true,
reporter: 'teamcity',
reporterOptions: 'topLevelSuite=top suite,flowId=12345,useStdError=\'true\',useStdError=\'true\',recordHookFailures=\'true\',actualVsExpected=\'true\'',
config: {
screenshotOnRunFailure: false,
},
})
})
it('shows slow tests in yellow', function () {
return systemTests.exec(this, {
spec: 'slowTestThreshold.cy.js',
snapshot: false,
stripAnsi: false,
config: {
slowTestThreshold: 1,
screenshotOnRunFailure: false,
},
processEnv: {
MOCHA_COLORS: 1,
CI: 1,
CIRCLECI: true,
},
}).then((result) => {
expect(result.stdout.match(/passes inherited(.*)/)[1], 'when verifying "passes inherited" test time colors').to.contain('\u001b[33m')
expect(result.stdout.match(/passes quickly(.*)/)[1], 'when verifying "passes quickly" test time colors').not.to.contain('\u001b[33m')
expect(result.stdout.match(/passes slowly(.*)/)[1], 'when verifying "passes slowly" test time color').to.contain('\u001b[33m')
})
})
})