Skip to content

Commit

Permalink
screenshot.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
sainthkh committed Mar 14, 2022
1 parent 933ab6f commit 1265cd0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions packages/driver/src/cy/commands/screenshot.ts
Expand Up @@ -410,6 +410,10 @@ const takeScreenshot = (Cypress, state, screenshotConfig, options: TakeScreensho
.finally(after)
}

interface InternalScreenshotOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable & Cypress.ScreenshotOptions> {
_log?: any
}

export default function (Commands, Cypress, cy, state, config) {
// failure screenshot when not interactive
Cypress.on('runnable:after:run:async', (test, runnable) => {
Expand Down Expand Up @@ -440,8 +444,7 @@ export default function (Commands, Cypress, cy, state, config) {
})

Commands.addAll({ prevSubject: ['optional', 'element', 'window', 'document'] }, {
// TODO: any -> Partial<Loggable & Timeoutable & ScreenshotOptions>
screenshot (subject, name, options: any = {}) {
screenshot (subject, name, options: Partial<Cypress.Loggable & Cypress.Timeoutable & Cypress.ScreenshotOptions> = {}) {
let userOptions = options

if (_.isObject(name)) {
Expand All @@ -463,16 +466,16 @@ export default function (Commands, Cypress, cy, state, config) {
// TODO: handle hook titles
const runnable = state('runnable')

options = _.defaults({}, userOptions, {
const _options: InternalScreenshotOptions = _.defaults({}, userOptions, {
log: true,
timeout: config('responseTimeout'),
})

const isWin = $dom.isWindow(subject)

let screenshotConfig: any = _.pick(options, 'capture', 'scale', 'disableTimersAndAnimations', 'overwrite', 'blackout', 'waitForCommandSynchronization', 'padding', 'clip', 'onBeforeScreenshot', 'onAfterScreenshot')
let screenshotConfig: any = _.pick(_options, 'capture', 'scale', 'disableTimersAndAnimations', 'overwrite', 'blackout', 'waitForCommandSynchronization', 'padding', 'clip', 'onBeforeScreenshot', 'onAfterScreenshot')

screenshotConfig = $Screenshot.validate(screenshotConfig, 'screenshot', options._log)
screenshotConfig = $Screenshot.validate(screenshotConfig, 'screenshot', _options._log)
screenshotConfig = _.extend($Screenshot.getConfig(), screenshotConfig)

// set this regardless of options.log b/c its used by the
Expand All @@ -488,10 +491,10 @@ export default function (Commands, Cypress, cy, state, config) {
consoleProps.name = name
}

if (options.log) {
options._log = Cypress.log({
if (_options.log) {
_options._log = Cypress.log({
message: name,
timeout: options.timeout,
timeout: _options.timeout,
consoleProps () {
return consoleProps
},
Expand All @@ -500,7 +503,7 @@ export default function (Commands, Cypress, cy, state, config) {

if (!isWin && subject && subject.length > 1) {
$errUtils.throwErrByPath('screenshot.multiple_elements', {
log: options._log,
log: _options._log,
args: { numElements: subject.length },
})
}
Expand All @@ -515,8 +518,8 @@ export default function (Commands, Cypress, cy, state, config) {
name,
subject,
runnable,
log: options._log,
timeout: options.timeout,
log: _options._log,
timeout: _options.timeout,
})
.then((props) => {
const { duration, path, size } = props
Expand Down

0 comments on commit 1265cd0

Please sign in to comment.