-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
root.ts
36 lines (28 loc) · 842 Bytes
/
root.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
import _ from 'lodash'
interface InternalRootOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable> {
_log?: any
}
export default (Commands, Cypress, cy, state) => {
Commands.addAll({
root (options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
const _options: InternalRootOptions = _.defaults({}, options, { log: true })
if (_options.log !== false) {
_options._log = Cypress.log({
message: '',
timeout: _options.timeout,
})
}
const log = ($el) => {
if (_options.log) {
_options._log.set({ $el })
}
return $el
}
const withinSubject = state('withinSubject')
if (withinSubject) {
return log(withinSubject)
}
return cy.now('get', 'html', { log: false }).then(log)
},
})
}