Giter Club home page Giter Club logo

react-chaos's Introduction

๐Ÿ”ฅ๐Ÿ’๐Ÿ’ฅ React Chaos

Chaos Engineering for your React applications.

What It Does

React Chaos is currently a higher order component that will randomly throw Errors in the component it wraps. The likelihood for the error to throw is based on a level you set when you wrap a component.

Blog post: Announcing React Chaos Demo: https://react-chaos.netlify.com/

๐Ÿ›‘ Pre-Installation Notes

  • This is currently WIP and a proof-of-concept.
  • There is nothing in place to help ensure good performance practices. Use at your own risk.

Installation

npm i --save-dev react-chaos

Usage

First, import the Chaos:

import withChaos from 'react-chaos';

Wrap any component with the Chaos:

const ComponentToWrap = () => <p>I may have chaos.</p>;

const ComponentWithChaos = withChaos(ComponentToWrap);

You can optionally set a Chaos level between 1 and 10 (the higher the number, the more Chaos ๐Ÿ˜ˆ) as well as a custom error message:

const ComponentWithChaos = withChaos(ComponentToWrap);

const ComponentWithChaos = withChaos(
  ComponentToWrap,
  10,
  'This error message will almost certainly be shown since we are at Chaos level 10.'
);

Note: The default Chaos level is 5.

Chaos in Production

By default, React Chaos will not run in production. If you want to override this by passing in true as a 4th parameter like this:

const ComponentWithChaos2 = withChaos(
  ComponentWillHaveChaos2,
  3,
  'a custom error message, level 3',
  true
);

Why

  • Because simple UI errors shouldn't bring down your app.
  • This library can help expose areas of your component tree that don't handle errors very gracefully. Used in conjunction with Error Boundaries, this can be a powerful tool to improve the resiliency of your UI components.

What is Chaos Engineering?

Chaos Engineering is the practice of experimenting with entropy on a software system to test its resiliency. You can read more about it here.

Inspiration

Other Notes

This project uses TSDX.

react-chaos's People

Contributors

dependabot[bot] avatar jchiatt avatar karlhorky avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-chaos's Issues

Nothing is exported?

Looking into /dist in the npm packaged bundle - there's nothing in the index.js?

         'use strict'

      if (process.env.NODE_ENV === 'production') {
        module.exports = require('./chaos-react.cjs.production.js')
      } else {
        module.exports = require('./chaos-react.cjs.development.js')
      }

Chaotic Interaction

Love that youโ€™ve taken up this effort!

What are your views on a Chaos actor that performs random interaction with the UI? Eg clicking buttons, entering text in inputs etc.

While this does not really simulate typical user interaction, perhaps it can highlight issues around what should be interactive at any given time (contrived example is to disable a button that triggers some async action)?

the newest npm package wrong?

Hi,

I try to install the the newest react-chaos(version 0.1.0?) and have a try.
I found that you may don't publish release files to npm.

Best.

React hooks

Looks like a really nice project!

I think having a useChaos hook can be really useful and will also won't encapsulate the wrapped component

runtime error of this package

error - ./node_modules/react-chaos/dist/index.js:7:0
Module not found: Can't resolve './chaos-react.cjs.development.js'

Module not found: Error: Can't resolve './chaos-react.cjs.development.js' in '/home/xxxxx/chaos-demo/node_modules/react-chaos/dist

Hi, I am experiencing this error when I use the package.

Compiled with problems:
ร—
ERROR
Cannot find module './chaos-react.cjs.development.js'
    at webpackMissingModule (http://localhost:3000/static/js/bundle.js:7050:69)
    at ./node_modules/react-chaos/dist/index.js (http://localhost:3000/static/js/bundle.js:7050:176)
    at options.factory (http://localhost:3000/static/js/bundle.js:41417:31)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:40840:33)
    at fn (http://localhost:3000/static/js/bundle.js:41074:21)
    at ./src/App.js (http://localhost:3000/static/js/bundle.js:17:69)
    at options.factory (http://localhost:3000/static/js/bundle.js:41417:31)
    at __webpack_require__ (http://localhost:3000/static/js/bundle.js:40840:33)
    at fn (http://localhost:3000/static/js/bundle.js:41074:21)
    at ./src/index.js (http://localhost:3000/static/js/bundle.js:119:62)
ERROR in ./node_modules/react-chaos/dist/index.js 6:2-62
Module not found: Error: Can't resolve './chaos-react.cjs.development.js' in '/home/xxxxx/chaos-demo/node_modules/react-chaos/dist'

What I tried

  • Deleting package-lock.json and running npm install
  • Verified that the module 'react-chaos' is installed in my project by running npm list react-chaos

my code

import React from 'react';
import withChaos from 'react-chaos';

// Define a component
const ComponentToWrap = () => {
  // Simulate an error
  if (Math.random() < 0.5) {
    throw new Error('Oops! Something went wrong.');
  }

  return <p>I may have chaos.</p>;
};

// Wrap the component with Chaos
const ComponentWithChaos = withChaos(ComponentToWrap, 8, 'Custom error message: Chaos level 8');

// Create a component with Chaos level 8 and a custom error message
const App = () => {
  return (
    <div>
      <h1>React Chaos Demo</h1>
      <ComponentWithChaos />
    </div>
  );
};

export default App;

Think through public API for Chaos component

This is a first pass at what the API for Chaos could look like. Suggestions welcome!

<Chaos
  level={5}
  message="a custom error message"
  shallow
  depth={3}
  statelessOnly
  statefulOnly
  monkeys
  disasters={[
    "network",
    "language",
    "time",
    "location",
    "machine"
  ]}
>
  <SomeComponent />
  <AnotherComponent />
</Chaos>

level

This is a number (1-10) that allows you to set the likelihood of chaos occurring.

message

This is a custom error message you can pass in that will be displayed as the message when an error is triggered.

shallow & depth (Children & Nested Components)

Ideally, one should be able to wrap a single component, a component with children, or a component with grandchildren (possibly even their entire application), with Chaos.

It could have a depth prop that allows you to explicitly set the number of grandchildren to apply chaos to. It could also recursively apply chaos to all grandchildren unless you pass in a shallow prop, in which case chaos would only be applied to the immediate children.

statelessOnly & statefulOnly

These props would allow you to only apply potential chaos to stateless components or stateful components.

monkeys

This will be a special surprise. ๐Ÿ’

disasters

This will allow you to specify the types of chaos that could occur. I think there will be a lot of new types in the future, but off the top of my head I thought about those listed. I think there's also potential for React-specific types of chaos, such as causing random re-renders and such, but only insofar that it mimics chaos that could actually occur in the real world.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.