Socket
Socket
Sign inDemoInstall

@cypress/skip-test

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cypress/skip-test

Simple commands to skip a test based on platform, browser or an url


Version published
Weekly downloads
184K
increased by2.33%
Maintainers
1
Weekly downloads
 
Created
Source

@cypress/skip-test renovate-app badge semantic-release CircleCI

Simple commands to skip a test based on platform, browser or an url

it('skips this test when running on Mac', () => {
  cy.log('about to run custom command to skip this test')
    .wait(1000)
    .skipOn('mac')
})

Skip in action

Important

This is a simple utility plugin until Cypress supports filtering of tests.

Install

npm install -D @cypress/skip-test

Example

You can use this module as custom Cypress commands cy.skipOn and cy.onlyOn or by importing its functions. To use custom commands like cy.skipOn, add this module to your support file cypress/support/index.js

require('@cypress/skip-test/support')

cy.skipOn

Skip this test if running in Electron browser

it('only runs on Electron', () => {
  cy.skipOn('electron')
  // the rest of the test
})

Skip this test if running on Windows platform

it('runs on Linux and Mac', () => {
  cy.skipOn('windows')
  // the rest of the test
})

cy.onlyOn

Continues the test only when running on Mac, skips when running on any other platform

it('runs on Mac only', () => {
  cy.onlyOn('mac')
  // the rest of the test
})

Continues this test only when running against localhost. Use baseUrl to set the url to compare.

it('only tests localhost', () => {
  cy.onlyOn('localhost')
  // the rest of the test
})

imports

import { onlyOn, skipOn } from '@cypress/skip-test'

it('runs only on Mac', () => {
  // using the exported function instead of
  // the custom command cy.onlyOn(...)
  onlyOn('mac')
})

it('skips on Mac', () => {
  skipOn('darwin')
})

imports with callback

Instead of dynamically skipping a test at run-time, you can hide entire blocks of tests using the callback format.

import { onlyOn, skipOn } from '@cypress/skip-test'
onlyOn('mac', () => {
  // this callback will only evaluate on Mac
  // thus the tests will be completely hidden from other platforms
  describe('Mac tests', () => {
    it('works', () => {})
  })
})
skipOn('mac', () => {
  // this test will run on every platform but Mac
  it('hides this test on Mac', () => {})
})

Tip: you can nest the callbacks to combine the conditions

// run these group of tests only on Mac and only on Chrome
onlyOn('mac', () => {
  onlyOn('chrome', () => {
    it('works', () => {})
  })
})

boolean flag

You can pass a boolean to each function or command if you want to calculate when to run the tests yourself.

// run this test if S is "foo"
cy.onlyOn(S === 'foo')

You can use callback form with the flag

onlyOn(S === 'foo', () => {
  describe('foo', () => {
    it('works', () => {...})
  })
})

You can even run other Cypress commands before deciding to skip or continue

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

You can chain conditions together

it('combination of skip and only', () => {
  cy.skipOn('firefox')
  cy.onlyOn('electron').onlyOn('mac')
  cy.log('running test')
})

If the test runs, it will print the conditions in the command log

Skip and only

Intellisense

To get typings, reference this module, for example by using reference comment

/// <reference types="@cypress/skip-test" />

Skip intellisense

For more details read Cypress Intelligent Completion Guide

Warning

Skipping tests in Mocha at run-time skips the afterEach hooks. In this example, afterEach will be skipped, and after hook will run.

it('example', () => {
  cy.skipOn('mac')
})
afterEach(() => {
  // this will be skipped when a test is skipped
})
after(() => {
  // this will run even after skipping test
})

Authors

  • Kevin Old
  • Gleb Bahmutov

MIT License

Keywords

FAQs

Package last updated on 07 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc