From 5fb595b321248e8c1b58c523a46cf76b6e2ffe4d Mon Sep 17 00:00:00 2001 From: Rafael Anachoreta Date: Wed, 11 Mar 2020 22:45:00 +0100 Subject: [PATCH 1/3] fix: add environment checks to skipOn --- cypress/integration/bool-spec.js | 10 ++++++++++ cypress/integration/callback-spec.js | 18 ++++++++++++++++++ index.js | 14 ++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/cypress/integration/bool-spec.js b/cypress/integration/bool-spec.js index 6086a2a..cbb849e 100644 --- a/cypress/integration/bool-spec.js +++ b/cypress/integration/bool-spec.js @@ -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')) }) diff --git a/cypress/integration/callback-spec.js b/cypress/integration/callback-spec.js index 2fcd7d7..594f5d5 100644 --- a/cypress/integration/callback-spec.js +++ b/cypress/integration/callback-spec.js @@ -31,3 +31,21 @@ it('does not run given function for other environments', () => { }) expect(called, 'callback was NOT called').to.be.undefined }) + +it('skips 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 +}) diff --git a/index.js b/index.js index 2b9f05a..715f3d1 100644 --- a/index.js +++ b/index.js @@ -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 = () => Cypress.env('ENVIRONMENT') const headedMatches = name => { if (name === 'headed') { @@ -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() } @@ -183,6 +191,12 @@ const skipOn = (name, cb) => { return } + if (isEnvironmentSet()) { + if (isEnvironment(normalizedName)) { + return skip() + } + } + if (matchesUrlPart(normalizedName)) { return skip() } From 0cbf6271e20b2b3ab4289dd986864af599fc5937 Mon Sep 17 00:00:00 2001 From: Rafael Anachoreta Date: Wed, 23 Sep 2020 18:53:27 +0100 Subject: [PATCH 2/3] chore: update test description --- cypress/integration/callback-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cypress/integration/callback-spec.js b/cypress/integration/callback-spec.js index 594f5d5..30126c4 100644 --- a/cypress/integration/callback-spec.js +++ b/cypress/integration/callback-spec.js @@ -32,7 +32,7 @@ it('does not run given function for other environments', () => { expect(called, 'callback was NOT called').to.be.undefined }) -it('skips given function for some environment', () => { +it('does not run given function for some environment', () => { Cypress.env('ENVIRONMENT', 'test1') let called skipOn('test1', () => { From 384bd789db1d9f933b4d5adb875f7247fbe404c5 Mon Sep 17 00:00:00 2001 From: Gleb Bahmutov Date: Wed, 13 Jan 2021 09:07:40 -0500 Subject: [PATCH 3/3] Update index.js --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 715f3d1..ee97634 100644 --- a/index.js +++ b/index.js @@ -78,7 +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 = () => Cypress.env('ENVIRONMENT') +const isEnvironmentSet = () => typeof Cypress.env('ENVIRONMENT') === 'string' && Cypress.env('ENVIRONMENT') const headedMatches = name => { if (name === 'headed') {