/
runnables.cy.ts
238 lines (194 loc) · 6.5 KB
/
runnables.cy.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
import { EventEmitter } from 'events'
import { RootRunnable } from '../../src/runnables/runnables-store'
import { itHandlesFileOpening } from '../support/utils'
import type { BaseReporterProps } from '../../src/main'
import type { RunnablesErrorModel } from '../../src/runnables/runnable-error'
import appState from '../../src/lib/app-state'
import { MobxRunnerStore } from '@packages/app/src/store'
import scroller from '../../src/lib/scroller'
const runnerStore = new MobxRunnerStore('e2e')
runnerStore.setSpec({
name: 'foo.js',
relative: 'relative/path/to/foo.js',
absolute: '/absolute/path/to/foo.js',
})
describe('runnables', () => {
let runner: EventEmitter
let runnables: RootRunnable
let render: (renderProps?: Partial<BaseReporterProps>, cypressMode?: 'run' | 'open') => void
let start: (renderProps?: Partial<BaseReporterProps>) => Cypress.Chainable
beforeEach(() => {
cy.fixture('runnables').then((_runnables) => {
runnables = _runnables
})
runner = new EventEmitter()
render = (renderProps: Partial<BaseReporterProps> = {}, cypressMode = 'open') => {
cy.visit('/').then((win: Cypress.AUTWindow) => {
win.__CYPRESS_MODE__ = cypressMode
win.render({
runner,
studioEnabled: renderProps.studioEnabled || false,
runnerStore,
scroller,
appState,
...renderProps,
})
})
}
start = (renderProps?: Partial<BaseReporterProps>) => {
render(renderProps)
return cy.get('.reporter').then(() => {
runner.emit('runnables:ready', runnables)
runner.emit('reporter:start', {})
})
}
})
it('displays loader when runnables have not yet loaded', () => {
render()
cy.contains('Your tests are loading...').should('be.visible')
// ensure the page is loaded before taking snapshot
cy.percySnapshot()
})
it('displays runnables when they load', () => {
start()
cy.get('.runnable').should('have.length', 9)
cy.contains('test 4').should('be.visible')
cy.percySnapshot()
})
it('displays bundle error if specified', () => {
const error: RunnablesErrorModel = {
title: 'Oops...we found an error preparing this test file:',
link: 'https://on.cypress.io/we-found-an-error-preparing-your-test-file',
callout: '/path/to/spec',
message: 'We found an error',
}
start({ error })
cy.contains(error.title)
cy.contains(error.callout)
cy.contains(error.message)
cy.get('.error a').should('have.attr', 'href', error.link)
cy.get('.error a').should('have.attr', 'target', '_blank')
})
it('error does not render link if there is not one specified', () => {
const error = {
title: 'Oops...we found an error preparing this test file:',
callout: '/path/to/spec',
message: 'We found an error',
}
start({ error })
cy.get('.error a').should('not.exist')
})
it('error does not display callout if there is not one specified', () => {
const error = {
title: 'Oops...we found an error preparing this test file:',
message: 'We found an error',
}
start({ error })
cy.get('.error pre').should('not.exist')
})
it('error displays message with markdown', () => {
const error = {
title: 'Oops...we found an error preparing this test file:',
message: `We **found** an _error_:
- fix
- it
`,
}
start({ error })
cy.get('.error strong').should('have.text', 'found')
cy.get('.error em').should('have.text', 'error')
cy.get('.error li').should('have.length', 2)
})
it('displays the time taken in seconds', () => {
start()
const startTime = new Date(2000, 0, 1)
const now = new Date(2000, 0, 1, 0, 0, 12, 340)
cy.clock(now).then(() => {
runner.emit('reporter:start', { startTime: startTime.toISOString() })
})
cy.get('.runnable-header span:last').should('have.text', '00:12')
})
it('does not display time if no time taken', () => {
start()
cy.get('.runnable-header span:first').should('have.text', 'foo.js')
cy.get('.runnable-header span:last').should('not.have.text', '--')
})
describe('when there are no tests', () => {
beforeEach(() => {
runnables.suites = []
})
it('displays error', () => {
start()
cy.contains('No tests found.').should('be.visible')
cy.contains('Cypress could not detect tests in this file.').should('be.visible')
cy.contains('Open file in IDE').should('be.visible')
cy.contains('Create test with Cypress Studio').should('not.exist')
cy.get('.help-link').should('have.attr', 'href', 'https://on.cypress.io/intro')
cy.get('.help-link').should('have.attr', 'target', '_blank')
cy.percySnapshot()
})
it('can launch studio', () => {
start({ studioEnabled: true }).then(() => {
cy.stub(runner, 'emit')
cy.contains('Cypress Studio').click()
cy.wrap(runner.emit).should('be.calledWith', 'studio:init:suite', 'r1')
})
})
describe('open in ide', () => {
beforeEach(() => {
start({
runnerStore,
})
})
itHandlesFileOpening({
getRunner: () => runner,
selector: '.no-tests a',
file: {
file: '/absolute/path/to/foo.js',
line: 0,
column: 0,
},
})
})
})
describe('runnable-header (unified)', () => {
let spy: Cypress.Agent<sinon.SinonSpy>
beforeEach(() => {
scroller.__setScrollThreholdMs(500)
spy = cy.spy(appState, 'temporarilySetAutoScrolling')
start({
runnerStore,
})
})
afterEach(() => {
scroller.__reset()
})
it('contains name of spec and emits when clicked', () => {
const selector = '.runnable-header a'
cy.stub(runner, 'emit').callThrough()
cy.get(selector).as('spec-title').contains('foo.js')
cy.get(selector).click().then(() => {
expect(runner.emit).to.be.calledWith('open:file:unified')
})
})
it('adds a scroll listener in open mode', () => {
appState.startRunning()
cy.get('.container')
.trigger('scroll')
.trigger('scroll')
.trigger('scroll').then(() => {
expect(spy).to.have.been.calledWith(false)
})
})
it('does not add a scroll listener in run mode', () => {
render({}, 'run')
appState.startRunning()
cy.get('.container')
.trigger('scroll')
.trigger('scroll')
.trigger('scroll').then(() => {
expect(spy).not.to.have.been.calledWith(false)
})
})
})
})