Skip to content

Commit

Permalink
feat: add currentRetry to Cypress API (#25297)
Browse files Browse the repository at this point in the history
Co-authored-by: Emily Rohrbough <emilyrohrbough@users.noreply.github.com>
Co-authored-by: Emily Rohrbough <emilyrohrbough@yahoo.com>
  • Loading branch information
3 people authored Jan 3, 2023
1 parent 736c599 commit acc61d8
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
5 changes: 5 additions & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ declare namespace Cypress {
titlePath: string[]
}

/**
* Information about current test retry
*/
currentRetry: number

/**
* Information about the browser currently running the tests
*/
Expand Down
92 changes: 91 additions & 1 deletion packages/driver/cypress/e2e/cypress/cypress.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,96 @@ describe('driver/src/cypress/index', () => {
})
})

context('.currentRetry', () => {
describe('test is not retried', () => {
before(() => {
expect(Cypress.currentRetry).to.eq(0)
})

beforeEach(() => {
expect(Cypress.currentRetry).to.eq(0)
})

afterEach(() => {
expect(Cypress.currentRetry).to.eq(0)
})

after(() => {
expect(Cypress.currentRetry).to.eq(0)
})

it('correctly returns currentRetry', () => {
expect(Cypress.currentRetry).to.eq(0)
})
})

describe('test is retried due to beforeEach hook failure', { retries: 1 }, () => {
before(() => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

beforeEach(() => {
expect(Cypress.currentRetry).to.eq(1)
})

it('correctly returns currentRetry', () => {
expect(Cypress.currentRetry).to.eq(1)
})

afterEach(() => {
expect(Cypress.currentRetry).to.eq(1)
})

after(() => {
expect(Cypress.currentRetry).to.eq(1)
})
})

describe('test is retried due to test failure', { retries: 1 }, () => {
before(() => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

beforeEach(() => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

it('correctly returns currentRetry', () => {
expect(Cypress.currentRetry).to.eq(1)
})

afterEach(() => {
expect(Cypress.currentRetry).to.eq(1)
})

after(() => {
expect(Cypress.currentRetry).to.eq(1)
})
})

describe('test is retried due to afterEach hook failure', { retries: 1 }, () => {
before(() => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

beforeEach(() => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

it('correctly returns currentRetry', () => {
expect(Cypress.currentRetry).to.be.oneOf([0, 1])
})

afterEach(() => {
expect(Cypress.currentRetry).to.eq(1)
})

after(() => {
expect(Cypress.currentRetry).to.eq(1)
})
})
})

context('.isCy', () => {
it('returns true on cy, cy chainable', () => {
expect(Cypress.isCy(cy)).to.be.true
Expand All @@ -104,7 +194,7 @@ describe('driver/src/cypress/index', () => {
})
})

context('.Log', () => {
context('.log', () => {
it('throws when passing non-object to Cypress.log()', () => {
const fn = () => {
Cypress.log('My Log')
Expand Down
6 changes: 6 additions & 0 deletions packages/driver/src/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,12 @@ class $Cypress {
}
}

get currentRetry (): number {
const ctx = this.cy.state('runnable').ctx

return ctx?.currentTest?._currentRetry || ctx?.test?._currentRetry
}

static create (config: Record<string, any>) {
const cypress = new $Cypress()

Expand Down

5 comments on commit acc61d8

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on acc61d8 Jan 3, 2023

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 arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/linux-arm64/develop-acc61d8bd24d0e584aa61db59629b6e0bcb99f5c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on acc61d8 Jan 3, 2023

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 build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/linux-x64/develop-acc61d8bd24d0e584aa61db59629b6e0bcb99f5c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on acc61d8 Jan 3, 2023

Choose a reason for hiding this comment

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

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/darwin-arm64/develop-acc61d8bd24d0e584aa61db59629b6e0bcb99f5c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on acc61d8 Jan 3, 2023

Choose a reason for hiding this comment

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

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

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/darwin-x64/develop-acc61d8bd24d0e584aa61db59629b6e0bcb99f5c/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on acc61d8 Jan 3, 2023

Choose a reason for hiding this comment

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

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

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/12.3.0/win32-x64/develop-acc61d8bd24d0e584aa61db59629b6e0bcb99f5c/cypress.tgz

Please sign in to comment.