/
multi_domain_log.spec.ts
69 lines (59 loc) · 2.11 KB
/
multi_domain_log.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
import { assertLogLength } from '../../../../support/utils'
context('cy.origin log', () => {
let logs: any = []
let lastTestLogId = ''
beforeEach(() => {
logs = []
cy.on('log:added', (attrs, log) => {
logs.push(log)
})
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="dom-link"]').click()
})
it('logs in primary and secondary origins', () => {
cy.origin<string>('http://foobar.com:3500', () => {
const afterLogAdded = new Promise<void>((resolve) => {
const listener = (attrs) => {
if (attrs.message === 'test log in cy.origin') {
expect(attrs.message).to.eq('test log in cy.origin')
cy.removeListener('log:added', listener)
resolve(attrs.id)
}
}
cy.on('log:added', listener)
})
cy.log('test log in cy.origin')
cy.wrap(afterLogAdded)
}).then((id) => {
lastTestLogId = id
// Verify the log is also fired in the primary origin.
expect(logs[6].get('message')).to.eq('test log in cy.origin')
// Verify the log has the same ID as was generated in the cross-origin
expect(logs[6].get('id')).to.equal(id)
assertLogLength(logs, 11)
})
})
it('has a different id in a second test', () => {
cy.origin('http://foobar.com:3500', () => {
const afterLogAdded = new Promise<void>((resolve) => {
const listener = (attrs) => {
if (attrs.message === 'test log in cy.origin') {
expect(attrs.message).to.eq('test log in cy.origin')
cy.removeListener('log:added', listener)
resolve(attrs.id)
}
}
cy.on('log:added', listener)
})
cy.log('test log in cy.origin')
cy.wrap(afterLogAdded)
}).then((id) => {
// Verify the log is also fired in the primary origin.
expect(logs[6].get('message')).to.eq('test log in cy.origin')
// Verify the log has the same ID as was generated in the cross-origin
expect(logs[6].get('id')).to.equal(id)
expect(logs[6].get('id')).to.not.equal(lastTestLogId)
assertLogLength(logs, 12)
})
})
})