-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
logging.spec.ts
160 lines (122 loc) · 5.17 KB
/
logging.spec.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
describe('cy.origin logging', () => {
const { _ } = Cypress
it('groups callback commands on a passing test', () => {
const logs: any[] = []
cy.on('log:added', (attrs) => {
logs.push(attrs)
})
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.get('[data-cy="dom-check"]').invoke('text')
})
cy.log('after').should(() => {
const originLog = _.find(logs, { name: 'origin' })
const getLog = _.find(logs, { name: 'get', message: '[data-cy="dom-check"]' })
const invokeLog = _.find(logs, { name: 'invoke', message: '.text()' })
const newUrlLog = _.find(logs, { name: 'new url' })
const logLog = _.find(logs, { name: 'log' })
expect(originLog.groupStart).to.be.true
expect(getLog.group).to.equal(originLog.id)
expect(invokeLog.group).to.equal(originLog.id)
expect(newUrlLog.group).to.equal(originLog.id)
expect(logLog.group).to.be.undefined // ensure the group has ended
})
})
it('logs cy.origin as group when failing with validation failure', (done) => {
const logs: any[] = []
cy.on('log:added', (attrs) => {
logs.push(attrs)
})
cy.on('fail', () => {
const originLog = _.find(logs, { name: 'origin' })
expect(originLog.groupStart).to.be.true
// FIXME: Tests that end with a cy.origin command and enqueue no further cy
// commands may have origin's unload event bleed into subsequent tests
// and prevent stability from being reached, causing those tests to hang.
// We execute done after a brief timeout to ensure stability
// is reached for the next test. This timeout can be removed with the
// completion of: https://github.com/cypress-io/cypress/issues/21300
setTimeout(done, 0)
})
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
// @ts-ignore
cy.origin(false, () => {})
})
it('logs cy.origin as group when failing with serialization failure', (done) => {
const logs: any[] = []
cy.on('log:added', (attrs) => {
logs.push(attrs)
})
cy.on('fail', () => {
const originLog = _.find(logs, { name: 'origin' })
expect(originLog.groupStart).to.be.true
// FIXME: Tests that end with a cy.origin command and enqueue no further cy
// commands may have origin's unload event bleed into subsequent tests
// and prevent stability from being reached, causing those tests to hang.
// We execute done after a brief timeout to ensure stability
// is reached for the next test. This timeout can be removed with the
// completion of: https://github.com/cypress-io/cypress/issues/21300
setTimeout(done, 0)
})
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
const options = { args: { div: Cypress.$('div') } }
cy.origin('http://foobar.com:3500', options, () => {})
})
it('groups callback commands when failing with inner command failure', (done) => {
const logs: any[] = []
cy.on('log:added', (attrs) => {
logs.push(attrs)
})
cy.on('fail', () => {
const originLog = _.find(logs, { name: 'origin' })
const getLog = _.find(logs, { name: 'get', message: '[data-cy="dom-check"]' })
const invokeLog = _.find(logs, { name: 'invoke', message: '.text()' })
const newUrlLog = _.find(logs, { name: 'new url' })
const failingGetLog = _.find(logs, { name: 'get', message: '#does-not-exist' })
expect(originLog.groupStart).to.be.true
expect(getLog.group).to.equal(originLog.id)
expect(invokeLog.group).to.equal(originLog.id)
expect(newUrlLog.group).to.equal(originLog.id)
expect(failingGetLog.group).to.equal(originLog.id)
done()
})
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.get('[data-cy="dom-check"]').invoke('text')
cy.get('#does-not-exist', { timeout: 1 })
})
cy.log('after')
})
it('groups callback commands when failing with async failure', (done) => {
const logs: any[] = []
cy.on('log:added', (attrs) => {
logs.push(attrs)
})
cy.on('fail', () => {
const originLog = _.find(logs, { name: 'origin' })
const getLog = _.find(logs, { name: 'get', message: '[data-cy="dom-check"]' })
const invokeLog = _.find(logs, { name: 'invoke', message: '.text()' })
const newUrlLog = _.find(logs, { name: 'new url' })
expect(originLog.groupStart).to.be.true
expect(getLog.group).to.equal(originLog.id)
expect(invokeLog.group).to.equal(originLog.id)
expect(newUrlLog.group).to.equal(originLog.id)
done()
})
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()
cy.origin('http://foobar.com:3500', () => {
cy.get('[data-cy="dom-check"]').invoke('text').then(() => {
setTimeout(() => {
throw new Error('async error')
})
})
cy.wait(300)
})
cy.log('after')
})
})