-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
cypress.config.js
101 lines (80 loc) · 2.5 KB
/
cypress.config.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
const { defineConfig } = require('cypress')
const CDP = require('chrome-remote-interface')
const debug = require('debug')('cypress:server:protocol')
function ensureRdpPort (args) {
const existing = args.find(
(arg) => arg.slice(0, 23) === '--remote-debugging-port'
)
if (existing) {
return Number(existing.split('=')[1])
}
const port = 40000 + Math.round(Math.random() * 25000)
args.push(`--remote-debugging-port=${port}`)
return port
}
let port = 0
let client = null
module.exports = defineConfig({
fixturesFolder: false,
e2e: {
supportFile: false,
setupNodeEvents (on, config) {
on('before:browser:launch', (browser, launchOptionsOrArgs) => {
debug('browser launch args or options %o', launchOptionsOrArgs)
const args = Array.isArray(launchOptionsOrArgs)
? launchOptionsOrArgs
: launchOptionsOrArgs.args
port = ensureRdpPort(args)
debug('ensureRdpPort %d', port)
debug('Chrome arguments %o', args)
})
on('task', {
resetCRI: async () => {
if (client) {
debug('resetting CRI client')
await client.close()
client = null
}
return Promise.resolve(true)
},
activatePrintMediaQuery: async () => {
debug('activatePrintMediaQuery')
client =
client ||
(await CDP({
port,
}))
return client.send('Emulation.setEmulatedMedia', {
media: 'print',
})
},
activateHoverPseudo: async ({ selector }) => {
debug('activateHoverPseudo')
client =
client ||
(await CDP({
port,
}))
await client.DOM.enable()
await client.CSS.enable()
// as the Window consists of two IFrames, we must retrieve the right one
const allRootNodes = await client.DOM.getFlattenedDocument()
const isIframe = (node) => {
return node.nodeName === 'IFRAME' && node.contentDocument
}
const filtered = allRootNodes.nodes.filter(isIframe)
// The first IFrame is our App
const root = filtered[0].contentDocument
const { nodeId } = await client.DOM.querySelector({
nodeId: root.nodeId,
selector,
})
return client.CSS.forcePseudoState({
nodeId,
forcedPseudoClasses: ['hover'],
})
},
})
},
},
})