Skip to content

Commit 1265cd0

Browse files
committed
screenshot.ts
1 parent 933ab6f commit 1265cd0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/driver/src/cy/commands/screenshot.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ const takeScreenshot = (Cypress, state, screenshotConfig, options: TakeScreensho
410410
.finally(after)
411411
}
412412

413+
interface InternalScreenshotOptions extends Partial<Cypress.Loggable & Cypress.Timeoutable & Cypress.ScreenshotOptions> {
414+
_log?: any
415+
}
416+
413417
export default function (Commands, Cypress, cy, state, config) {
414418
// failure screenshot when not interactive
415419
Cypress.on('runnable:after:run:async', (test, runnable) => {
@@ -440,8 +444,7 @@ export default function (Commands, Cypress, cy, state, config) {
440444
})
441445

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

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

466-
options = _.defaults({}, userOptions, {
469+
const _options: InternalScreenshotOptions = _.defaults({}, userOptions, {
467470
log: true,
468471
timeout: config('responseTimeout'),
469472
})
470473

471474
const isWin = $dom.isWindow(subject)
472475

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

475-
screenshotConfig = $Screenshot.validate(screenshotConfig, 'screenshot', options._log)
478+
screenshotConfig = $Screenshot.validate(screenshotConfig, 'screenshot', _options._log)
476479
screenshotConfig = _.extend($Screenshot.getConfig(), screenshotConfig)
477480

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

491-
if (options.log) {
492-
options._log = Cypress.log({
494+
if (_options.log) {
495+
_options._log = Cypress.log({
493496
message: name,
494-
timeout: options.timeout,
497+
timeout: _options.timeout,
495498
consoleProps () {
496499
return consoleProps
497500
},
@@ -500,7 +503,7 @@ export default function (Commands, Cypress, cy, state, config) {
500503

501504
if (!isWin && subject && subject.length > 1) {
502505
$errUtils.throwErrByPath('screenshot.multiple_elements', {
503-
log: options._log,
506+
log: _options._log,
504507
args: { numElements: subject.length },
505508
})
506509
}
@@ -515,8 +518,8 @@ export default function (Commands, Cypress, cy, state, config) {
515518
name,
516519
subject,
517520
runnable,
518-
log: options._log,
519-
timeout: options.timeout,
521+
log: _options._log,
522+
timeout: _options.timeout,
520523
})
521524
.then((props) => {
522525
const { duration, path, size } = props

0 commit comments

Comments
 (0)