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

Commit

Permalink
feat: add environment checks to skipOn (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
  • Loading branch information
rafael-anachoreta and bahmutov committed Jan 13, 2021
1 parent 355dc7a commit bac20b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cypress/integration/bool-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ it('runs if task returns production', () => {
.then(onlyOn)
})

it('runs when on the set environment', () => {
Cypress.env('ENVIRONMENT', 'production')
onlyOn('production')
})

it('skips when on the set environment', () => {
Cypress.env('ENVIRONMENT', 'production')
skipOn('production')
})

it('skips if task returns production', () => {
cy.task('getDbName').then(name => skipOn(name === 'production'))
})
18 changes: 18 additions & 0 deletions cypress/integration/callback-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,21 @@ it('does not run given function for other environments', () => {
})
expect(called, 'callback was NOT called').to.be.undefined
})

it('does not run given function for some environment', () => {
Cypress.env('ENVIRONMENT', 'test1')
let called
skipOn('test1', () => {
called = true
})
expect(called, 'callback was called').to.be.undefined
})

it('runs given function for other environments', () => {
Cypress.env('ENVIRONMENT', 'test1')
let called
skipOn('testX', () => {
called = true
})
expect(called, 'callback was NOT called').to.be.true
})
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const skip = () => {
const isPlatform = name => ['win32', 'darwin', 'linux'].includes(name)
const isBrowser = name => ['electron', 'chrome', 'firefox'].includes(name)
const isHeadedName = name => ['headed', 'headless'].includes(name)
const isEnvironmentSet = () => typeof Cypress.env('ENVIRONMENT') === 'string' && Cypress.env('ENVIRONMENT')

const headedMatches = name => {
if (name === 'headed') {
Expand Down Expand Up @@ -163,6 +164,13 @@ const skipOn = (name, cb) => {
return it(`Skipping test(s) in ${normalizedName} mode`)
}

if (isEnvironmentSet()) {
if (!isEnvironment(normalizedName)) {
return cb()
}
return it(`Skipping test(s) on ${normalizedName} environment`)
}

if (!matchesUrlPart(normalizedName)) {
return cb()
}
Expand All @@ -183,6 +191,12 @@ const skipOn = (name, cb) => {
return
}

if (isEnvironmentSet()) {
if (isEnvironment(normalizedName)) {
return skip()
}
}

if (matchesUrlPart(normalizedName)) {
return skip()
}
Expand Down

0 comments on commit bac20b5

Please sign in to comment.