{"id":13725476,"url":"https://github.com/cypress-io/cypress-skip-test","last_synced_at":"2025-05-07T20:32:32.065Z","repository":{"id":35928035,"uuid":"220144097","full_name":"cypress-io/cypress-skip-test","owner":"cypress-io","description":"Simple commands to skip a test based on platform, browser or a url","archived":true,"fork":false,"pushed_at":"2022-12-10T08:09:32.000Z","size":839,"stargazers_count":178,"open_issues_count":47,"forks_count":10,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-04-14T08:35:36.869Z","etag":null,"topics":["cypress","cypress-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cypress-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-07T03:31:24.000Z","updated_at":"2023-12-23T18:38:36.000Z","dependencies_parsed_at":"2023-01-16T09:20:41.617Z","dependency_job_id":null,"html_url":"https://github.com/cypress-io/cypress-skip-test","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcypress-skip-test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcypress-skip-test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcypress-skip-test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cypress-io%2Fcypress-skip-test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cypress-io","download_url":"https://codeload.github.com/cypress-io/cypress-skip-test/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645382,"owners_count":17346139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cypress","cypress-plugin"],"created_at":"2024-08-03T01:02:24.573Z","updated_at":"2024-11-14T15:31:21.432Z","avatar_url":"https://github.com/cypress-io.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# @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)\n\n\u003e Simple commands to skip a test based on platform, browser or an url\n\n```js\nit('skips this test when running on Mac', () =\u003e {\n  cy.log('about to run custom command to skip this test')\n    .wait(1000)\n    .skipOn('mac')\n})\n```\n\n![Skip in action](images/skip.gif)\n\n## Important\n\nThis is a simple utility plugin until [Cypress supports filtering of tests](https://github.com/cypress-io/cypress/pull/5346).\n\n## Install\n\n```shell\nnpm install -D @cypress/skip-test\n```\n\n## Example\n\nYou 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`\n\n```js\nrequire('@cypress/skip-test/support')\n```\n\n### `cy.skipOn`\n\nSkip this test if running in Electron browser\n\n```js\nit('only runs on Electron', () =\u003e {\n  cy.skipOn('electron')\n  // the rest of the test\n})\n```\n\nSkip this test if running on Windows platform\n\n```js\nit('runs on Linux and Mac', () =\u003e {\n  cy.skipOn('windows')\n  // the rest of the test\n})\n```\n\n### `cy.onlyOn`\n\nContinues the test only when running on Mac, skips when running on any other platform\n\n```js\nit('runs on Mac only', () =\u003e {\n  cy.onlyOn('mac')\n  // the rest of the test\n})\n```\n\nContinues this test only when running against `localhost`. Use `baseUrl` to set the url to compare.\n\n```js\nit('only tests localhost', () =\u003e {\n  cy.onlyOn('localhost')\n  // the rest of the test\n})\n```\n\n### imports\n\n```js\nimport { onlyOn, skipOn } from '@cypress/skip-test'\n\nit('runs only on Mac', () =\u003e {\n  // using the exported function instead of\n  // the custom command cy.onlyOn(...)\n  onlyOn('mac')\n})\n\nit('skips on Mac', () =\u003e {\n  skipOn('darwin')\n})\n```\n\n### imports with callback\n\nInstead of dynamically skipping a test at run-time, you can hide entire blocks of tests using the callback format.\n\n```js\nimport { onlyOn, skipOn } from '@cypress/skip-test'\nonlyOn('mac', () =\u003e {\n  // this callback will only evaluate on Mac\n  // thus the tests will be completely hidden from other platforms\n  describe('Mac tests', () =\u003e {\n    it('works', () =\u003e {})\n  })\n})\nskipOn('mac', () =\u003e {\n  // this test will run on every platform but Mac\n  it('hides this test on Mac', () =\u003e {})\n})\n```\n\n**Tip:** you can nest the callbacks to combine the conditions\n\n```js\n// run these group of tests only on Mac and only on Chrome\nonlyOn('mac', () =\u003e {\n  onlyOn('chrome', () =\u003e {\n    it('works', () =\u003e {})\n  })\n})\n```\n\nWhen skipping a block of tests or a single test using browser name, it will insert a dummy empty test to let you know what has happened\n\n```js\nskipOn('firefox', () =\u003e {\n  it('works', () =\u003e {...})\n  it('works too', () =\u003e {...})\n})\n// output in the console\n//  Skipping test(s) on firefox\n```\n\n### boolean flag\n\nYou can pass a boolean to each function or command if you want to calculate when to run the tests yourself.\n\n```js\n// run this test if S is \"foo\"\ncy.onlyOn(S === 'foo')\n```\n\nYou can use callback form with the flag\n\n```js\nonlyOn(S === 'foo', () =\u003e {\n  describe('foo', () =\u003e {\n    it('works', () =\u003e {...})\n  })\n})\n```\n\nAlso you can pass sync and async function returning boolean flag.\n\n```js\n// run this test if function returns true\nconst fnReturningTrue = () =\u003e true\n\ncy.onlyOn(fnReturningTrue())\n```\n\n```js\n// run this test if async function returns true\nconst fnReturningPromiseTrue = () =\u003e new Promise((resolve) =\u003e resolve(true))\n\ncy.onlyOn(fnReturningPromiseTrue())\n```\n\nYou can even run other Cypress commands before deciding to skip or continue\n\n```js\nit('runs if task returns production', () =\u003e {\n  cy.task('getDbName').then((name) =\u003e cy.onlyOn(name === 'production'))\n  // equivalent\n  cy.task('getDbName').then((name) =\u003e onlyOn(name === 'production'))\n  // equivalent\n  cy.task('getDbName')\n    .then((name) =\u003e name === 'production')\n    .then(onlyOn)\n})\n```\n\n### `isOn`\n\nYou can check the condition against a browser name or an environment yourself.\n\n```js\nimport { isOn } from '@cypress/skip-test'\nit('loads users', () =\u003e {\n  // when running on Windows locally, the backend is not running\n  // thus we need to stub XHR requests\n  if (isOn('windows') \u0026\u0026 isOn('localhost')) {\n    cy.server()\n    cy.route('/users', 'fixture:users')\n  }\n  cy.visit('/')\n  cy.get('.user').should('have.length', 10)\n})\n```\n\n### Headed\n\nYou can skip or run tests in headed / headless environments\n\n```js\nimport { skipOn, onlyOn } from '@cypress/skip-test'\n\nskipOn('headed', () =\u003e {\n  it('skips the current test in headed mode', () =\u003e {\n    cy.wrap(true).should('equal', true)\n  })\n})\n\nonlyOn('headless', () =\u003e {\n  it('runs only in headless mode', () =\u003e { ... })\n})\n```\n\n**Note:** when skipping tests in this case, it will insert an empty placeholder test to provide information why the tests were skipped.\n\n```text\n- Skipping test(s), not on headed\n```\n\n### `ENVIRONMENT`\n\nThis module also reads special environment variable `ENVIRONMENT` inside its checks. For example, to only stub network calls on `staging` environment, execute the tests like this:\n\n```shell\nCYPRESS_ENVIRONMENT=staging npx cypress run\n```\n\nInside the spec file you can write\n\n```js\nimport {onlyOn, skipOn} from '@cypress/skip-test'\nconst stubServer = () =\u003e {\n  cy.server()\n  cy.route('/api/me', 'fx:me.json')\n  cy.route('/api/permissions', 'fx:permissions.json')\n  // Lots of fixtures ...\n}\nit('works', () =\u003e {\n  onlyOn('staging', stubServer)\n  ...\n})\nskipOn('staging', () =\u003e {\n  it('works on non-staging', () =\u003e {...})\n})\n```\n\nThe test `works` will stub network calls when running on `staging`, but will skip calling `stubServer` for other environments. The test `works on non-staging` will be skipped when the environment is `staging`.\n\n### Notes\n\nYou can chain conditions together\n\n```js\nit('combination of skip and only', () =\u003e {\n  cy.skipOn('firefox')\n  cy.onlyOn('electron').onlyOn('mac')\n  cy.log('running test')\n})\n```\n\nIf the test runs, it will print the conditions in the command log\n\n![Skip and only](images/skip-and-only.png)\n\n## Intellisense\n\nTo get typings, reference this module, for example by using `reference` comment\n\n```js\n/// \u003creference types=\"@cypress/skip-test\" /\u003e\n```\n\n![Skip intellisense](images/skip.png)\n\nFor more details read [Cypress Intelligent Completion Guide](https://on.cypress.io/intellisense)\n\n## Warning\n\nSkipping tests in Mocha at run-time skips the `afterEach` hooks. In this example, `afterEach` will be skipped, and `after` hook will run.\n\n```js\nit('example', () =\u003e {\n  cy.skipOn('mac')\n})\nafterEach(() =\u003e {\n  // this will be skipped when a test is skipped\n})\nafter(() =\u003e {\n  // this will run even after skipping test\n})\n```\n\n## Authors\n\n- Kevin Old\n- Gleb Bahmutov\n\n[MIT License](LICENSE)\n\n[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fcypress-skip-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcypress-io%2Fcypress-skip-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcypress-io%2Fcypress-skip-test/lists"}