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

feat: add environment checks to skipOn #99

Merged
merged 3 commits into from
Jan 13, 2021
Merged
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
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