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

simdummy

v0.1.5

Published

Simple tool for HTTP response simulation, automated and load testing

Downloads

2

Readme

simdummy

npm

Simple tool for HTTP response simulation, automated and load testing.

When started, server parses query string of incoming requests and responds with simulated latency, status code, JSON payload or any combination of the mentioned above.

Installation

npm install simdummy

Usage

To simulate HTTP response with latency, start listener at custom port:

const run = require('simdummy').run

run((port, stats, server) => {
    console.log(`Simulation server started at ${port}`)
}, 9999)

Then make HTTP call and specify required latency (eg: 200ms) in query string:

time curl http://localhost:9999/?l=200\&eh=1

Testing with Promises

To start HTTP listener to test asynchronous code with promises and async/await:

const test = require('simdummy').test

it('test async promise', async () => {
    await test(async (port, stats, server) => {
        const res = await yourHttpClient.get(`http://localhost:${port}`)
        expect(res.status).to.equal(200)
        expect(stats.calls).to.equal(1)
    })
})

Sim server collects basic statistics about number of requests received, responses sent and calls droped. The stats are exposed on sim sever instance as property and passed to run and test callbacks as argument:

  • calls - number of requests accepted
  • sents - number of responses sent
  • drops - number of responses dropped

Testing with Callbacks

To start HTTP listener to test asynchronous code with callbacks, pass done to test call:

it('test async callback', done => {
    test((port, stats, server, done) => {
        yourHttpClient.get(`http://localhost:${port}`, res => {
            expect(res.status).to.equal(200)
            expect(stats.calls).to.equal(1)
            done()
        })
    }, done)
})

Simulation Settings

Simulation settings are passed as query string parameters:

  • l=200 - base latency
  • n=50 - latency noise
  • s=404 - response status
  • eb=1 - request body is piped to response body
  • eh=1 - request headers are stringified to response body
  • bs=1024 - response body size in bytes, rounded to octet
  • d=1 - destroy request socket
  • lr=1 - log request to console

Startup Options and Events

Here is an example of how the simulation server can be started and which events are exposed.

const SimServer = require('simdummy').SimServer

// set latency and response body size limits
const limits = { maxLatency: 500, maxBodySize: 16 * 1024 }

const server = new SimServer(limits)

server.start(s =>
    // execute code on start
    console.log(`Simulation server started at ${s.address().port}`),

    // set custom port
    9999
)

// request event is emitted after settings parsed and limits applied
server.on('request', (req, res, settings) => {
    console.log('Accepted request')

    // override response latency
    setting.latency.actual = 1000

    // override response body
    settings.response.body = 'Hello, world!'

    // or end response right here
    res.end()
})

// response event is emitted before sending response
server.on('response', (req, res, settings) => {
    console.log('Sending response')

    // pipe request to response
    settings.response.echoBody = true

    // or override the whole body
    settings.response.body = 'Hello, world!'

    // set different status code
    res.statusCode = 201
})

// stop the server
server.close(err => {
    // execute code on stop
    console.log('Simulation server stopped')
})

Docker

To start simdummy in Docker container:

docker run --name sd -p 9999:9999 -d alexpereverzyev/simdummy