npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chaosocket

v0.1.1

Published

Create websocket chaos and see how well your app performs

Downloads

4

Readme

Chaosocket Build Status :bomb: :zap: :boom: :fire: :smiling_imp:

Create websocket chaos and see how well your app performs DEMO

The motivation of this project is nothing but being able to receive predefined socket messages. Why this? usually when integrating and testing web sockets in your app it happen that you have no control over the messages you are getting. This leads to slow iterations, like having to test you app against a real source of messages (production) or not doing it at all...

Chaosocket aims to provide you a set of tools to test this sort of behaviours, also it respects the WebSocket interface, making this transparent to you, this means that you don't have to modify your code at all when you introduce the library in your app. So it's perfect for simple scenarios like what happen when the user name is longer than 50 chars? to complex ones in which you want to stress your UI with 20 messages per second.

Defining chaos boundaries :triangular_ruler:

Chaos registration

const chaos = require('chaosocket');

chaos.register(() => {
  return {
    type: 'connection',
    user: {
      name: 'Hector'
    }
  };
});

chaos.listen();

Socket usage

const socket = new WebSocket('ws://0.0.0.0:8080');

socket.onmessage = function(e) {
  const msg = JSON.parse(e.data);

  console.log(msg.type, msg.user);
};

Chaosocket will call your message callback by time to time depending in some factors with the result of your registration.

Frequency

Sometimes you want to receive more events from a specific type, you achieve that by specifying the frequency of the registration. Default value is medium and the available ones are low, medium and high. Based on it chaosocket will emit events more or less often.

chaos.register(() => {
  return {
    type: 'connection'
  };
}, 'low');

chaos.register(() => {
  return {
    type: 'typing'
  };
}, 'medium');

chaos.register(() => {
  return {
    type: 'message'
  };
}, 'high');

Delay

This will change the default delay (2000ms) to 500ms forcing the app to handle x4 more events.

chaos.listen({
  delay: 500
});

Stop chaos :no_entry:

Tired of chaos? just close it and the socket will stop to recieve fake messages.

chaos.close();

## Using Faker :ghost: Chaosocket comes with Faker, a library to generate fake and random data easily, it's passed to the register method.

chaos.register((faker) => {
  return {
    create_at: faker.date.recent(),
    event_name: faker.random.arrayElement(['connection', 'typing', 'message']),
    first_name: faker.name.firstName(),
    last_name: faker.name.lastName(),
    bio: faker.lorem.text()
  };
});

You can find all Faker methods here https://github.com/marak/Faker.js/#api-methods

Demo :rocket:

TODO: Add screenshot

zzarcon.github.io/chaosocket

Installation :wrench:

$ npm i chaosocket -D

Dependencies :bow:

## Author :person_with_blond_hair:

Hector Zarco @zzarcon