Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

testing how Percy handles test retries #362

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 4 additions & 0 deletions examples/visual-testing-with-percy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ If a pull request introduces visual changes, they are caught and shown as a diff
![Visual change](images/diff.gif)

**Tip:** you can use any [visual testing](https://on.cypress.io/visual-testing) plugin with component testing.

### Test retries

Testing how Percy handles Cypress test retries.
38 changes: 38 additions & 0 deletions examples/visual-testing-with-percy/src/test-retries.cy-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react'
import { mount } from 'cypress-react-unit-test'

// test retries from
// https://github.com/cypress-io/cypress/pull/3968
// you can skip the tests if there is no retries feature
const describeOrSkip = Cypress.getTestRetries ? describe : describe.skip
describeOrSkip('Test', () => {
const Hello = () => {
// this is how you can get the current retry number
// attempt 1: (first test execution) retry = 0
// attempt 2: (second test execution) retry = 1
// attempt 3: retry = 2,
// etc
const n = cy.state('test').currentRetry
? cy.state('test').currentRetry()
: 0
return <div>retry {n}</div>
}

it.skip('does not retry', { retries: 0 }, () => {
mount(<Hello />)
cy.contains('retry 0')

// now let's fail the test - it won't retry it
// enable manually to observe
// cy.contains('retry 1')
})

it('retries', { retries: 3 }, () => {
mount(<Hello />)
cy.contains('retry') // ensure the component has rendered

// now let's fail the test - it will retry several times and pass
cy.percySnapshot('Test retry')
cy.contains('retry 3', { timeout: 1500 })
})
})