Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Commit

Permalink
feat: use new Cypress.isBrowser method if available
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Feb 3, 2020
1 parent 987c436 commit 90ec292
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 8 additions & 0 deletions cypress/integration/skip-on-firefox-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference types="cypress" />
import { skipOn } from '../..'

skipOn('firefox', () => {
it('runs the current test', () => {
expect(Cypress.browser.name !== 'firefox', 'should not be firefox!')
})
})
14 changes: 12 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

const { _ } = Cypress

const checkBrowserName = name => {
if ('isBrowser' in Cypress) {
// use the new v4.0 method
// @ts-ignore
return Cypress.isBrowser(name)
} else {
return Cypress.browser.name === name
}
}

/**
* Cleans up the passed name which could be browser, platform or other.
* @param {string} name The environment or platform or something else, like url
Expand Down Expand Up @@ -124,10 +134,10 @@ const skipOn = (name, cb) => {
}

if (isBrowser(normalizedName)) {
if (Cypress.browser.name !== normalizedName) {
if (!checkBrowserName(normalizedName)) {
return cb()
}
return
return it(`Skipping test(s) on ${normalizedName}`)
}

if (!matchesUrlPart(normalizedName)) {
Expand Down

0 comments on commit 90ec292

Please sign in to comment.