-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
logGroup.ts
43 lines (32 loc) · 1.1 KB
/
logGroup.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
import _ from 'lodash'
import { $Command } from '../cypress/command'
import $errUtils from '../cypress/error_utils'
export default (Cypress, userOptions: Cypress.LogGroup.Config, fn: Cypress.LogGroup.ApiCallback) => {
const cy = Cypress.cy
const shouldEmitLog = userOptions.log === undefined ? true : userOptions.log
const options: Cypress.InternalLogConfig = {
...userOptions,
instrument: 'command',
groupStart: true,
emitOnly: !shouldEmitLog,
}
const log = Cypress.log(options)
if (!_.isFunction(fn)) {
$errUtils.throwErrByPath('group.missing_fn', { onFail: log })
}
// An internal command is inserted to create a divider between
// commands inside group() callback and commands chained to it.
const restoreCmdIndex = cy.state('index') + 1
const endLogGroupCmd = $Command.create({
name: 'end-logGroup',
injected: true,
})
const forwardYieldedSubject = () => {
if (log) {
log.endGroup()
}
return endLogGroupCmd.get('prev').get('subject')
}
cy.queue.insert(restoreCmdIndex, endLogGroupCmd.set('fn', forwardYieldedSubject))
return fn(log)
}