/
pausing.ts
50 lines (40 loc) · 1.47 KB
/
pausing.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
export const handlePausing = (getCypress, reporterBus) => {
const Cypress = getCypress()
// tracks whether the cy.pause() was called from the primary driver
// (value === null) or from a cross-origin spec bridge (value is the origin
// matching that spec bridge)
let sendEventsToOrigin = null
reporterBus.on('runner:next', () => {
const Cypress = getCypress()
if (!Cypress) return
// if paused from within a cy.origin() callback, send the event to the
// corresponding spec bridge
if (sendEventsToOrigin) {
Cypress.primaryOriginCommunicator.toSpecBridge(sendEventsToOrigin, 'resume:next')
} else {
Cypress.emit('resume:next')
}
})
reporterBus.on('runner:resume', () => {
const Cypress = getCypress()
if (!Cypress) return
// if paused from within a cy.origin() callback, send the event to the
// corresponding spec bridge
if (sendEventsToOrigin) {
Cypress.primaryOriginCommunicator.toSpecBridge(sendEventsToOrigin, 'resume:all')
} else {
Cypress.emit('resume:all')
}
// pause sequence is over - reset this for subsequent pauses
sendEventsToOrigin = null
})
// from the primary driver
Cypress.on('paused', (nextCommandName) => {
reporterBus.emit('paused', nextCommandName)
})
// from a cross-origin spec bridge
Cypress.primaryOriginCommunicator.on('paused', ({ nextCommandName, origin }) => {
sendEventsToOrigin = origin
reporterBus.emit('paused', nextCommandName)
})
}