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 - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

75

index.js

@@ -6,2 +6,12 @@ /// <reference path="./index.d.ts" />

/**
* Cleans up the passed name which could be browser, platform or other.
* @param {string} name The environment or platform or something else, like url
* @returns {string} Normalized name
* @example
* normalizeName('mac') // 'darwin'
* normalizeName('windows') // 'win32'
* normalizeName('WIN') // 'win32'
* normalizeName('localhost') // 'localhost'
*/
const normalizeName = name => {

@@ -13,3 +23,4 @@ name = name.toLowerCase()

mac: 'darwin',
windows: 'win32'
windows: 'win32',
win: 'win32'
}

@@ -20,2 +31,26 @@ const normalizedName = aliases[name] ? aliases[name] : name

/**
* Returns true if the test is running on the given browser or platform
* or against given url.
* @param {string} name Browser name, platform or url.
* @returns {boolean} Returns true if the test runs against the given condition.
*/
const isOn = name => {
if (!_.isString(name)) {
throw new Error('Invalid syntax: isOn expects a string argument')
}
const normalizedName = normalizeName(name)
if (isPlatform(normalizedName)) {
return Cypress.platform === normalizedName
}
if (isBrowser(normalizedName)) {
return Cypress.browser.name === normalizedName
}
return matchesUrlPart(normalizedName)
}
const getMochaContext = () => cy.state('runnable').ctx

@@ -70,7 +105,2 @@ const skip = () => {

const skip = () => {
const ctx = getMochaContext()
return ctx.skip()
}
const normalizedName = normalizeName(name)

@@ -155,34 +185,10 @@

const normalizedName = normalizeName(name)
if (cb) {
if (isPlatform(normalizedName) && Cypress.platform === normalizedName) {
if (isOn(name)) {
return cb()
}
if (isBrowser(normalizedName) && Cypress.browser.name === normalizedName) {
return cb()
}
if (matchesUrlPart(normalizedName)) {
return cb()
}
} else {
const normalizedName = normalizeName(name)
cy.log(`onlyOn **${normalizedName}**`)
if (isPlatform(normalizedName)) {
if (Cypress.platform !== normalizedName) {
skip()
}
return
}
if (isBrowser(normalizedName)) {
if (Cypress.browser.name !== normalizedName) {
skip()
}
return
}
if (!matchesUrlPart(normalizedName)) {
if (!isOn(name)) {
return skip()

@@ -195,3 +201,4 @@ }

skipOn,
onlyOn
onlyOn,
isOn
}
{
"name": "@cypress/skip-test",
"version": "2.1.0",
"version": "2.2.0",
"description": "Simple commands to skip a test based on platform, browser or an url",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -151,2 +151,20 @@ # @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)

### `isOn`
You can check the condition against a browser name or an environment yourself.
```js
import {isOn} from '@cypress/skip-test'
it('loads users', () => {
// when running on Windows locally, the backend is not running
// thus we need to stub XHR requests
if (isOn('windows') && isOn('localhost')) {
cy.server()
cy.route('/users', 'fixture:users')
}
cy.visit('/')
cy.get('.user').should('have.length', 10)
})
```
### Notes

@@ -153,0 +171,0 @@

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