Documentation Index Fetch the complete documentation index at: https://mintlify.com/visible/cruel/llms.txt
Use this file to discover all available pages before exploring further.
Global mode allows you to enable or disable chaos injection across all wrapped functions without modifying each wrapper individually.
Enable global chaos
Activate chaos globally with custom options:
import { cruel } from "cruel"
// Enable global chaos
cruel . enable ({
fail: 0.1 ,
delay: [ 100 , 500 ],
timeout: 0.05 ,
})
// All wrapped functions will now have chaos injected
const api = cruel ( fetch )
const db = cruel ( query )
Disable global chaos
// Disable all chaos
cruel . disable ()
// Functions still work but without chaos
await api ( "https://api.example.com" )
Toggle chaos
// Toggle chaos on/off
const enabled = cruel . toggle ()
console . log ( enabled ) // true or false
// Check if enabled
if ( cruel . isEnabled ()) {
console . log ( "Chaos is active" )
}
Scoped chaos
Apply chaos only within a specific scope:
import { cruel } from "cruel"
// Normal execution
await api ( "/normal" )
// Chaos only in this scope
await cruel . scope ( async () => {
await api ( "/chaotic" ) // Has chaos
await db . query ( "SELECT *" ) // Has chaos
}, {
fail: 0.3 ,
delay: [ 500 , 2000 ],
})
// Back to normal
await api ( "/normal-again" )
Configuration
Configure global behavior:
cruel . configure ({
enabled: true ,
seed: 12345 , // Deterministic mode
log: true , // Log chaos events
safe: true , // Prevent destructive operations
})
Reset everything
// Reset all state
cruel . reset ()
// Clears:
// - Global chaos config
// - All scenarios
// - All profiles
// - Statistics
// - Event handlers
// - Fetch patches
Use cases
Testing Enable chaos in test environments without code changes
Development Toggle chaos on/off during development
CI/CD Conditional chaos based on environment variables
Debugging Temporarily disable chaos to isolate issues
Environment-based chaos
import { cruel } from "cruel"
// Enable based on environment
if ( process . env . NODE_ENV === "development" ) {
cruel . enable ( cruel . presets . development )
} else if ( process . env . CHAOS_ENABLED === "true" ) {
cruel . enable ({
fail: parseFloat ( process . env . CHAOS_FAIL_RATE || "0.1" ),
delay: [ 100 , 500 ],
})
}
Global mode affects all functions wrapped with cruel(). Individual wrapper options are merged with global options.