Skip to content

Commit

Permalink
fix: Prevent null snapshots from being stored and causing errors (#16015
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chrisbreiding authored Apr 15, 2021
1 parent e9457e2 commit 0a63455
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/driver/cypress/integration/cypress/log_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ describe('src/cypress/log', function () {
expect(result).to.equal(log)
})

// https://github.com/cypress-io/cypress/issues/15816
it('does not add snapshot if createSnapshot returns null', function () {
this.cy.createSnapshot.returns(null)

const log = this.log()
const result = log.snapshot()

expect(result.get('snapshots')).to.have.length(0)
})

it('is no-op if not interactive', function () {
this.config.withArgs('isInteractive').returns(false)

Expand Down
3 changes: 3 additions & 0 deletions packages/driver/src/cy/snapshots.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ const create = ($$, state) => {
// are no side effects from cloning it. see below for how we re-attach
// it to the AUT document
// https://github.com/cypress-io/cypress/issues/8679
// this can fail if snapshotting before the page has fully loaded,
// so we catch this below and return null for the snapshot
// https://github.com/cypress-io/cypress/issues/15816
const $body = $$(snapshotDocument.importNode($$('body')[0], true))

// for the head and body, get an array of all CSS,
Expand Down
9 changes: 7 additions & 2 deletions packages/driver/src/cypress/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,13 @@ const Log = function (cy, state, config, obj) {

const snapshots = this.get('snapshots') || []

// insert at index 'at' or whatever is the next position
snapshots[options.at || snapshots.length] = snapshot
// don't add snapshot if we couldn't create one, which can happen
// if the snapshotting process errors
// https://github.com/cypress-io/cypress/issues/15816
if (snapshot) {
// insert at index 'at' or whatever is the next position
snapshots[options.at || snapshots.length] = snapshot
}

this.set('snapshots', snapshots)

Expand Down

3 comments on commit 0a63455

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0a63455 Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 ia32 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/appveyor-develop-0a63455174f79453750544f93990aebf35f759c1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0a63455 Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppVeyor has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/appveyor-develop-0a63455174f79453750544f93990aebf35f759c1/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0a63455 Apr 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/7.2.0/circle-develop-0a63455174f79453750544f93990aebf35f759c1/cypress.tgz

Please sign in to comment.