Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add configuration option for disabling screenshots #8083

Merged
merged 4 commits into from
Jul 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cli/schema/cypress.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@
"default": "cypress/plugins/index.js",
"description": "Path to plugins file. (Pass false to disable)"
},
"screenshotOnRunFailure": {
"type": "boolean",
"default": true,
"description": "Whether Cypress will take a screenshot when a test fails during cypress run"
},
"screenshotsFolder": {
"type": "string",
"default": "cypress/screenshots",
Expand Down
5 changes: 5 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2421,6 +2421,11 @@ declare namespace Cypress {
* @example 1.2.3
*/
resolvedNodeVersion: string
/**
* Whether Cypress will take a screenshot when a test fails during cypress run.
* @default true
*/
screenshotOnRunFailure: boolean
/**
* Path to folder where screenshots will be saved from [cy.screenshot()](https://on.cypress.io/screenshot) command or after a headless or CI run’s test failure
* @default "cypress/screenshots"
Expand Down
19 changes: 19 additions & 0 deletions packages/driver/cypress/integration/commands/screenshot_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ describe('src/cy/commands/screenshot', () => {
})
})

it('is noop when screenshotOnRunFailure is false', () => {
Cypress.config('isInteractive', false)
Cypress.config('screenshotOnRunFailure', false)

cy.spy(Cypress, 'action').log(false)

const test = {
err: new Error,
}

const runnable = cy.state('runnable')

Cypress.action('runner:runnable:after:run:async', test, runnable)
.then(() => {
expect(Cypress.action).not.to.be.calledWith('cy:test:set:state')
expect(Cypress.automation).not.to.be.called
})
})

it('sends before/after events', function () {
Cypress.config('isInteractive', false)
this.screenshotConfig.scale = false
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/src/cy/commands/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ module.exports = function (Commands, Cypress, cy, state, config) {
Cypress.on('runnable:after:run:async', (test, runnable) => {
const screenshotConfig = $Screenshot.getConfig()

if (!test.err || !screenshotConfig.screenshotOnRunFailure || config('isInteractive') || test.err.isPending) {
if (!test.err || !screenshotConfig.screenshotOnRunFailure || config('isInteractive') || test.err.isPending || !config('screenshotOnRunFailure')) {
return
}

Expand Down
3 changes: 3 additions & 0 deletions packages/server/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ viewportHeight responseTimeout
video taskTimeout
videoCompression
videoUploadOnPasses
screenshotOnRunFailure
watchForFileChanges
waitForAnimations resolvedNodeVersion
nodeVersion resolvedNodePath
Expand Down Expand Up @@ -142,6 +143,7 @@ const CONFIG_DEFAULTS = {
video: true,
videoCompression: 32,
videoUploadOnPasses: true,
screenshotOnRunFailure: true,
modifyObstructiveCode: true,
chromeWebSecurity: true,
waitForAnimations: true,
Expand Down Expand Up @@ -212,6 +214,7 @@ const validationRules = {
videoCompression: v.isNumberOrFalse,
videosFolder: v.isString,
videoUploadOnPasses: v.isBoolean,
screenshotOnRunFailure: v.isBoolean,
viewportHeight: v.isNumber,
viewportWidth: v.isNumber,
waitForAnimations: v.isBoolean,
Expand Down
16 changes: 16 additions & 0 deletions packages/server/test/unit/config_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,20 @@ describe('lib/config', () => {
})
})

context('screenshotOnRunFailure', () => {
it('passes if a boolean', function () {
this.setup({ screenshotOnRunFailure: false })

return this.expectValidationPasses()
})

it('fails if not a boolean', function () {
this.setup({ screenshotOnRunFailure: 42 })

return this.expectValidationFails('be a boolean')
})
})

context('viewportHeight', () => {
it('passes if a number', function () {
this.setup({ viewportHeight: 10 })
Expand Down Expand Up @@ -1125,6 +1139,7 @@ describe('lib/config', () => {
video: { value: true, from: 'default' },
videoCompression: { value: 32, from: 'default' },
videoUploadOnPasses: { value: true, from: 'default' },
screenshotOnRunFailure: { value: true, from: 'default' },
videosFolder: { value: 'cypress/videos', from: 'default' },
supportFile: { value: 'cypress/support', from: 'default' },
pluginsFile: { value: 'cypress/plugins', from: 'default' },
Expand Down Expand Up @@ -1201,6 +1216,7 @@ describe('lib/config', () => {
video: { value: true, from: 'default' },
videoCompression: { value: 32, from: 'default' },
videoUploadOnPasses: { value: true, from: 'default' },
screenshotOnRunFailure: { value: true, from: 'default' },
videosFolder: { value: 'cypress/videos', from: 'default' },
supportFile: { value: 'cypress/support', from: 'default' },
pluginsFile: { value: 'cypress/plugins', from: 'default' },
Expand Down