{"id":16896914,"url":"https://github.com/scottrippey/cypress-try-or-skip","last_synced_at":"2025-03-20T10:44:53.231Z","repository":{"id":86410819,"uuid":"606764288","full_name":"scottrippey/cypress-try-or-skip","owner":"scottrippey","description":"Easy conditional testing with Cypress. If a command fails, skip the test.","archived":false,"fork":false,"pushed_at":"2023-03-03T19:15:19.000Z","size":268,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-23T07:46:32.307Z","etag":null,"topics":["cypress","cypress-command","cypress-plugin","cypress-tests","testing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scottrippey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-02-26T13:57:13.000Z","updated_at":"2023-03-02T04:04:10.000Z","dependencies_parsed_at":"2023-03-04T06:30:33.441Z","dependency_job_id":null,"html_url":"https://github.com/scottrippey/cypress-try-or-skip","commit_stats":{"total_commits":27,"total_committers":2,"mean_commits":13.5,"dds":0.03703703703703709,"last_synced_commit":"a9911833e1a5a26712d2ef3a0794d42513b1a56f"},"previous_names":["scottrippey/cypress-prerequisite"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrippey%2Fcypress-try-or-skip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrippey%2Fcypress-try-or-skip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrippey%2Fcypress-try-or-skip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scottrippey%2Fcypress-try-or-skip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scottrippey","download_url":"https://codeload.github.com/scottrippey/cypress-try-or-skip/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244600664,"owners_count":20479304,"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-command","cypress-plugin","cypress-tests","testing"],"created_at":"2024-10-13T17:34:04.079Z","updated_at":"2025-03-20T10:44:53.209Z","avatar_url":"https://github.com/scottrippey.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-try-or-skip\nEasy conditional testing with Cypress.  If a command fails, skip the test.\n\n# Motivation\n\nIn an ideal world, E2E tests have control over external dependencies, and there is no need for **conditional testing**.\n\nUnfortunately, in practice, external dependencies are hard to control, and E2E tests will be brittle and flaky if they can't adapt.  \n\n`cypress-try-or-skip` enables easy conditional testing by skipping tests when a command (or assertion) fails.\n\n# Installation\n\nInstall the module as a `devDependency` via `npm install --save-dev cypress-try-or-skip`\n\nAnd in your `cypress/support/index.js` file, import the module:\n```js\nimport 'cypress-try-or-skip`;\n```\n\n# Usage\n\n## `cy.tryOrSkip(commands: () =\u003e void)`\n\nIn any test, wrap some Cypress commands with `cy.tryOrSkip(() =\u003e { ... })`.\nIf any of these commands fail, the test will be marked as **skipped**, not **failed**!\n\n### Example: usage in a `it` block\n\nIn this example, if `#feature-a` does not exist, then the test will stop executing, and be marked as **skipped**.\n\n```js\nit(\"if FEATURE A is enabled, clicking the button will open a modal\", () =\u003e {\n  cy.tryOrSkip(() =\u003e {\n    cy.get(\"#feature-a\").should(\"exist\");\n  });\n  cy.get(\"#feature-a-button\").click();\n  cy.get(\"#feature-a-modal\").should(\"be.visible\");\n});\n```\n\n### Example: usage in a `before` block\n\nIf used inside a `before` block, the **entire suite** (everything inside the `describe` block) will be skipped if the command fails.\n\n```js\ndescribe(\"if FEATURE A is enabled\", () =\u003e {\n  before(() =\u003e {\n    cy.tryOrSkip(() =\u003e {\n      cy.get(\"#feature-a\").should(\"exist\");\n    });\n  });\n  \n  it(\"the feature-a button will be visible\", () =\u003e {\n    cy.get(\"#feature-a-button\").should(\"be.visible\");\n  });\n  \n  it(\"clicking the feature-a button will open a modal\", () =\u003e {\n    cy.get(\"#feature-a-button\").click();\n    cy.get(\"#feature-a-modal\").should(\"be.visible\");\n  });\n});\n```\n\nIf `#feature-a` does not exist, both of the tests in the `describe` block will be marked as \"skipped\".\n\n# Configuration\n\nThese settings can be configured in your `cypress.config.json` or can be supplied to the config option of `describe` or `it`.\n\n### `tryOrSkipBehavior: 'skip' | 'fail'`\n\n`skip` (default)  \nBy default, a failed command means the test will be marked as \"skipped\", which means the test suite will still pass.\nThis works well in certain workflows, like Pull Request checks -- so that PRs don't get blocked by external dependencies.\n\n`fail`  \nHowever, this behavior can be disabled by setting `tryOrSkipBehavior: 'fail'`.  \nIn this mode, if the command fails, the test will fail as normal.\nIf a `tryOrSkipSuite` fails, the test will fail as normal, and the rest of the tests in the suite will be skipped.\nThis setting is especially useful when you want to see failed dependencies -- such as in nightly builds, or for local development.\n\n### `tryOrSkipMessage: string` and `tryOrSkipSuiteMessage: string`\n\nWhen `tryOrSkip` fails, this message will be appended to the skipped test title.\n\n**This only works with `cypress run`**.  The message will not show up in the `cypress open` UI.\n\nExample:\n```\n// cypress.config.json\n  \"tryOrSkipMessage\": \" (skipped: \u003c%= error %\u003e)\",\n  \"tryOrSkipSuiteMessage\": \" (skipped suite)\",\n```\nNotice you can include the `error` in the message.\n\nExample output:\n```\n~ if feature-a is enabled (skipped: AssertionError: Expected '#feature-a' to exist)\n~ the feature-a button will be visible (skipped suite)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrippey%2Fcypress-try-or-skip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscottrippey%2Fcypress-try-or-skip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscottrippey%2Fcypress-try-or-skip/lists"}