Skip to content
Latest stable: v0.8.0.

Cypress Adapter

Use @chaos-maker/cypress to inject chaos into the next cy.visit() and inspect decisions through Cypress commands.

import '@chaos-maker/cypress/support';
CommandPurpose
cy.injectChaos(config, options?)Injects chaos into the next visit.
cy.removeChaos()Stops chaos in the current AUT window.
cy.getChaosLog()Yields ChaosEvent[].
cy.getChaosSeed()Yields the active seed or null.
cy.injectSWChaos(config, options?)Sends config to the active Service Worker.
cy.removeSWChaos(options?)Stops Service Worker chaos.
cy.getSWChaosLog()Yields Service Worker chaos events buffered on the page.
cy.getSWChaosLogFromSW(options?)Yields chaos events pulled directly from the Service Worker.

By default, chaos persists across navigations until cy.removeChaos() runs. Pass { persistAcrossNavigations: false } to limit chaos to the next visit.

cy.injectChaos(config, { persistAcrossNavigations: false });
cy.visit('/checkout');

Call cy.injectChaos() before cy.visit() so Cypress can install the bundle before app code executes.

For Service Worker chaos, call cy.visit() first, wait until navigator.serviceWorker.controller is present, then call cy.injectSWChaos() before the action that triggers SW fetches.

SSE chaos and GraphQL operation matching use the same cy.injectChaos() command as network, UI, and WebSocket chaos.

Pass profile (and optionally profileOverrides and customProfiles) on the config object - the command forwards them through to core’s resolution pipeline unchanged.

cy.injectChaos({
profile: 'mobile-checkout',
profileOverrides: {
network: { latencies: [{ urlPattern: '/api/extra', delayMs: 999, probability: 1 }] },
},
seed: 42,
});

See Scenario profiles for the resolution rules, the singular built-in mobileCheckout demo profile, the runtime override precedence, and the validation errors that surface as ChaosConfigError.

Pass debug: true to cy.injectChaos() to enable Debug Mode. It does not affect Cypress’s own --browser debugger or the DEBUG=cypress:* env var - Chaos Maker never reads them. Capture console mirrors with cy.spy(win.console, 'debug') inside onBeforeLoad; debug events also surface in cy.getChaosLog().

cy.injectChaos validates the config synchronously inside the command body. A malformed config throws ChaosConfigError and fails the step before cy.visit() runs.

cy.injectChaos(config, {
validation: { unknownFields: 'warn' },
});

Pass validation to relax unknown-field handling, hook deprecation events, or run custom per-RuleType validators. See Rule Validation.