/
reporters_spec.js
174 lines (154 loc) · 6.01 KB
/
reporters_spec.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
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
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-1.5.2',
'mochawesome-2.3.1',
'mochawesome-3.0.1',
]
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',
})
})
// 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',
})
})
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,
})
.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',
})
})
it('sends file to reporter', function () {
return systemTests.exec(this, {
spec: 'simple_passing.cy.js',
reporter: 'reporters/uses-file.js',
})
.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),
})
.then(() => {
if (ma === 'mochawesome-1.5.2') {
return fs.readFileAsync(path.join(e2ePath, 'mochawesome-reports', 'mochawesome.html'), 'utf8')
.then((xml) => {
expect(xml).to.include('<h3 class="suite-title">simple passing spec</h3>')
expect(xml).to.include('<div class="status-item status-item-passing-pct success">100% Passing</div>')
})
}
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(`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),
})
.then(() => {
if (ma === 'mochawesome-1.5.2') {
return fs.readFileAsync(path.join(e2ePath, 'mochawesome-reports', 'mochawesome.html'), 'utf8')
.then((xml) => {
expect(xml).to.include('<h3 class="suite-title">simple failing hook spec</h3>')
expect(xml).to.not.include('.status-item-hooks')
})
}
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\'',
})
})
it('shows slow tests in yellow', function () {
return systemTests.exec(this, {
spec: 'slowTestThreshold.cy.js',
snapshot: false,
config: {
slowTestThreshold: 1,
},
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')
})
})
})