Registry / testing / cypress-skip-this-test

cypress-skip-this-test

JSON →
library1.0.1jsnpmunverified

The `cypress-skip-this-test` package provides a utility to automatically skip subsequent tests within a Cypress test suite if any preceding test in that suite has failed. This is particularly useful for end-to-end test scenarios where tests are interdependent, preventing unnecessary runs of tests that rely on a previously failed setup step. The current stable version is `1.0.1`, released recently in September 2024. As a new package, its release cadence is still establishing, but it indicates active maintenance. Its key differentiator is simplifying the management of interdependent tests in Cypress by automating test skipping through a `beforeEach` hook, addressing a common pain point in E2E testing where manual skipping or cleanup can be cumbersome. It offers a concise, declarative way to manage test execution flow based on preceding test outcomes.

npm install cypress-skip-this-test
INSTALL
IMPORT
SIG · CYPRESS-SKIP-THIS-
C
cypress-skip-this-test
testingjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

skipIfPreviousTestsFailed
import { skipIfPreviousTestsFailed } from 'cypress-skip-this-test'
const skipIfPreviousTestsFailed = require('cypress-skip-this-test')
This is a named export, primarily intended for ES module usage in Cypress spec files. CommonJS `require` is not officially supported or tested, and may not work as expected in a modern Cypress setup.

Demonstrates how to import and apply `skipIfPreviousTestsFailed` as a `beforeEach` hook within a `describe` block. If 'test 2' fails, 'test 3' will be automatically skipped, illustrating the plugin's core functionality for managing interdependent tests.

import { skipIfPreviousTestsFailed } from 'cypress-skip-this-test' describe('Parent suite', () => { // second test fails on purpose // and the third test should skip beforeEach(skipIfPreviousTestsFailed) it('test 1', () => { cy.log('Test 1 runs') expect(true).to.be.true }) it('test 2', () => { cy.log('Test 2 runs and fails') throw new Error('fail on purpose') }) it('test 3', () => { cy.log('Test 3 should be skipped') expect(true).to.be.true // This assertion should not be reached }) })
Debug
Known issues
gotchaThe `skipIfPreviousTestsFailed` hook operates per `describe` block. If your tests are structured with nested `describe` blocks or across multiple top-level suites, you must apply `beforeEach(skipIfPreviousTestsFailed)` within each relevant `describe` block where this skipping behavior is desired. It does not automatically propagate to child or sibling suites without explicit application.
fix
Apply `beforeEach(skipIfPreviousTestsFailed)` within every `describe` block where you need tests to be skipped based on prior failures in that specific suite.
affects: >=1.0.0
gotchaThis plugin is designed for scenarios where tests have explicit sequential dependencies. If your tests are truly independent or their order of execution is not critical, applying this plugin might inadvertently mask failures or make debugging harder by skipping tests that could have provided valuable insights, even if a previous test failed.
fix
Carefully consider your test structure and dependencies. Only apply `cypress-skip-this-test` to suites where a failure in an earlier test legitimately renders subsequent tests invalid or redundant. For independent tests, rely on Cypress's default behavior.
affects: >=1.0.0
gotchaWhen tests are skipped using Mocha's `this.skip()` (which this plugin leverages internally), `afterEach` hooks for the skipped tests might also be skipped or behave unexpectedly depending on the Cypress runner and environment (headed vs. headless).
fix
Be mindful of cleanup logic in `afterEach` hooks within suites using this plugin. If critical cleanup is needed regardless of test skipping, consider moving it to `after` hooks or ensuring `afterEach` hooks are resilient to the state of a skipped test.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'call') or similar when invoking `beforeEach`
The `skipIfPreviousTestsFailed` function was invoked immediately with `()` instead of being passed as a function reference to `beforeEach`.
fix
Ensure you pass the function reference: `beforeEach(skipIfPreviousTestsFailed)` instead of `beforeEach(skipIfPreviousTestsFailed())`.
Tests are not being skipped as expected, even after a previous test failed in the suite.
The `beforeEach(skipIfPreviousTestsFailed)` hook was not placed in the correct `describe` block scope, or `testIsolation` is set to `true` (the Cypress default) which resets the browser state for each test, making the plugin's state tracking ineffective.
fix
Ensure `beforeEach(skipIfPreviousTestsFailed)` is placed directly within the `describe` block containing the interdependent tests. Also, consider setting `testIsolation: false` in your Cypress configuration (`cypress.config.js`) for the spec files using this plugin, as it relies on state persistence across tests in the same suite. Note that disabling `testIsolation` has other implications for test independence.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Resources
cypress-skip-this-test — npm install cypress-skip-this-test · libregistry