@cypress/skip-test
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -13,4 +13,17 @@ /// <reference types="cypress" /> | ||
* .skipOn('electron') | ||
* @example | ||
* // skip the test if S is "foo" | ||
* cy.skipOn(S === 'foo') | ||
* | ||
* @example | ||
``` | ||
// skip entire block of tests on Firefox | ||
// without starting them | ||
skipOn('firefox', () => { | ||
it('works', () => {...}) | ||
it('works too', () => {...}) | ||
}) | ||
``` | ||
*/ | ||
skipOn(name: string): Chainable<Subject> | ||
skipOn(nameOrFlag: string|boolean, cb?: () => void): Chainable<Subject> | ||
@@ -21,6 +34,18 @@ /** | ||
* @example | ||
* // run this test on Mac | ||
* cy.onlyOn('darwin') | ||
* @example | ||
* // run this test if S is "foo" | ||
* cy.onlyOn(S === 'foo') | ||
* @example | ||
``` | ||
// run this group of tests against localhost only | ||
onlyOn('localhost', () => { | ||
it('works', () => {...}) | ||
it('works too', () => {...}) | ||
}) | ||
``` | ||
*/ | ||
onlyOn(name: string): Chainable<Subject> | ||
onlyOn(nameOrFlag: string|boolean, cb?: () => void): Chainable<Subject> | ||
} | ||
} |
50
index.js
@@ -33,2 +33,22 @@ /// <reference path="./index.d.ts" /> | ||
const skipOnBool = (flag, cb) => { | ||
if (!_.isBoolean(flag)) { | ||
throw new Error( | ||
'Invalid syntax: cy.skipOn(<boolean flag>), for example cy.skipOn(true)' | ||
) | ||
} | ||
if (cb) { | ||
if (!flag) { | ||
return cb() | ||
} | ||
} else { | ||
cy.log(`skipOn **${flag}**`) | ||
if (flag) { | ||
skip() | ||
} | ||
} | ||
} | ||
/** | ||
@@ -38,2 +58,6 @@ * Skips the current test based on the browser, platform or url. | ||
const skipOn = (name, cb) => { | ||
if (_.isBoolean(name)) { | ||
return skipOnBool(name, cb) | ||
} | ||
if (!_.isString(name) || '') { | ||
@@ -93,6 +117,32 @@ throw new Error( | ||
const onlyOnBool = (flag, cb) => { | ||
if (!_.isBoolean(flag)) { | ||
throw new Error( | ||
'Invalid syntax: cy.onlyOn(<boolean>), for example cy.onlyOn(true)' | ||
) | ||
} | ||
if (cb) { | ||
if (flag) { | ||
return cb() | ||
} | ||
} else { | ||
cy.log(`onlyOn **${flag}**`) | ||
if (!flag) { | ||
skip() | ||
} | ||
} | ||
} | ||
/** | ||
* Runs the current test only in the specified browser, platform or against url. | ||
* @param {string|boolean} name - condition, could be platform, browser name, url or true|false. | ||
* @param {() => void} cb - Optional, run the given callback if the condition passes | ||
*/ | ||
const onlyOn = (name, cb) => { | ||
if (_.isBoolean(name)) { | ||
return onlyOnBool(name, cb) | ||
} | ||
if (!_.isString(name) || '') { | ||
@@ -99,0 +149,0 @@ throw new Error( |
{ | ||
"name": "@cypress/skip-test", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Simple commands to skip a test based on platform, browser or an url", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -14,2 +14,6 @@ # @cypress/skip-test [![renovate-app badge][renovate-badge]][renovate-app] [![semantic-release][semantic-image] ][semantic-url] [![CircleCI](https://circleci.com/gh/cypress-io/cypress-skip-test/tree/master.svg?style=svg)](https://circleci.com/gh/cypress-io/cypress-skip-test/tree/master) | ||
## Important | ||
This is a simple utility plugin until [Cypress supports filtering of tests](https://github.com/cypress-io/cypress/pull/5346). | ||
## Install | ||
@@ -115,2 +119,35 @@ | ||
### boolean flag | ||
You can pass a boolean to each function or command if you want to calculate when to run the tests yourself. | ||
```js | ||
// run this test if S is "foo" | ||
cy.onlyOn(S === 'foo') | ||
``` | ||
You can use callback form with the flag | ||
```js | ||
onlyOn(S === 'foo', () => { | ||
describe('foo', () => { | ||
it('works', () => {...}) | ||
}) | ||
}) | ||
``` | ||
You can even run other Cypress commands before deciding to skip or continue | ||
```js | ||
it.only('runs if task returns production', () => { | ||
cy.task('getDbName').then(name => cy.onlyOn(name === 'production')) | ||
// equivalent | ||
cy.task('getDbName').then(name => onlyOn(name === 'production')) | ||
// equivalent | ||
cy.task('getDbName') | ||
.then(name => name === 'production') | ||
.then(onlyOn) | ||
}) | ||
``` | ||
### Notes | ||
@@ -117,0 +154,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12153
211
206