Skip to content

Commit

Permalink
feat: support Cypress v9 (#22)
Browse files Browse the repository at this point in the history
* feat: add Cypress v9 support

* set up CI to test Cypress v9
  • Loading branch information
bahmutov committed Sep 6, 2022
1 parent 73daf4e commit 88476c8
Show file tree
Hide file tree
Showing 8 changed files with 3,278 additions and 7 deletions.
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,10 +7,45 @@ jobs:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Run tests 🧪
- name: Run Cypress tests 🧪
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v4

test-cypress-v9:
runs-on: ubuntu-20.04
steps:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Install top dependencies 📦
# https://github.com/cypress-io/github-action
uses: cypress-io/github-action@v4
with:
runTests: false

- name: Run Cypress v9 tests 🧪
uses: cypress-io/github-action@v4
with:
working-directory: cypress-v9

- uses: actions/upload-artifact@v2
name: Store any v9 screenshots 🖼
if: failure()
with:
name: cypress-screenshots-v9
path: cypress-v9/cypress/screenshots

release:
needs: [test, test-cypress-v9]
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout 🛎
uses: actions/checkout@v3

- name: Install only the semantic release 📦
run: npm install semantic-release

- name: Semantic Release 🚀
uses: cycjimmy/semantic-release-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -2,7 +2,7 @@

> Easy conditional if-else logic for your Cypress tests
Tested with `cy.get`, `cy.contains`, `cy.find`, `.then`, `.within` commands in Cypress v10+ only.
Tested with `cy.get`, `cy.contains`, `cy.find`, `.then`, `.within` commands in Cypress v9 and v10+.

- 📺 [Introduction To Using cypress-if Plugin to Write Conditional Cypress Commands](https://youtu.be/TVwU0OvrVUA)
- 🎓 Covered in my [Cypress Plugins course](https://cypress.tips/courses/cypress-plugins)
Expand Down
5 changes: 5 additions & 0 deletions cypress-v9/cypress.json
@@ -0,0 +1,5 @@
{
"pluginsFile": false,
"supportFile": false,
"fixturesFolder": false
}
36 changes: 36 additions & 0 deletions cypress-v9/cypress/integration/spec.cy.js
@@ -0,0 +1,36 @@
/// <reference path="../../../src/index.d.ts" />
import '../../../src'

it('executes the IF branch', () => {
cy.wrap(1)
.if('equal', 1)
.then(cy.spy().as('if'))
.else()
.then(cy.spy().as('else'))
.finally()
.should('equal', 1)
cy.get('@if').should('have.been.calledOnce')
cy.get('@else').should('not.be.called')
})

describe('wrapped value', () => {
it('performs an action if the wrapped value is equal to 42', () => {
cy.wrap(42).if('equal', 42).then(cy.spy().as('action')).then(cy.log)
cy.get('@action').should('have.been.calledOnce')
})

it('does nothing if it is not 42', () => {
cy.wrap(1).if('equal', 42).then(cy.spy().as('action')).then(cy.log)
cy.get('@action').should('not.have.been.called')
})

context('.else', () => {
it('passes the subject to the else branch', () => {
cy.wrap(1).if('equal', 42).log('if branch').else().should('equal', 1)
})

it('passes the subject if().else()', () => {
cy.wrap(1).if('equal', 42).else().should('equal', 1)
})
})
})

0 comments on commit 88476c8

Please sign in to comment.