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

distrest

v0.1.0

Published

External API stubing module for on the fly stubbing for automated testing

Downloads

1

Readme

distRest

Stop stressing about mocking out those pesky external APIs and let distRest do all the worrying. This library was created to keep all the management of your external stubs right where they should be, in your tests. It will spin up and spin down a server on the fly within your tests and do it FAST. No need to worry about external dependency management and waiting for those stub servers to start up, these start up with your tests and stop with your tests.

Getting started is as easy as installing the module and calling start().

What are you waiting for? A worry free test is waiting for you.

Packages

npm

npm install distrest

Usage

	import { start, stop } from 'distRest';
    import request from 'request'; //npm i request

	let server = start();

    request('http://localhost:1337/ping', function (error, response, body) {
    	console.log(body); // PONG!
    });

    request('http://localhost:1337/notPing', function (error, response, body) {
    	console.log(body); // 404 - These are not the paths you are looking for.
        stop(server);
    });
	import distrest from 'distRest';
    import request from 'request'; //npm i request

	let server = distrest.start();

    request('http://localhost:1337/ping', function (error, response, body) {
    	console.log(body); // PONG!
    });

    request('http://localhost:1337/notPing', function (error, response, body) {
    	console.log(body); // 404 - These are not the paths you are looking for.
        distrest.stop(server);
    });

Methods

  • start - Takes options object and starts the server up.
    • returns a server object.
  • stop - Takes a server object and will stop it.

Options

  • assert - A boolean to specify if the server should do an assert when an endpoint is called but an expectation is missed, making it easier to understand why your response isn't getting to your application. Defaults to false.
  • basic - Specifying a basic authentication and will require the requester to have Authentication="Basic {basic string}".
  • bearer - Specifying a bearer authentication and will require the requester to have Authentication="Baerer {bearer string}".
  • port - Specifying which port the server should start on. Defaults to 1337.
  • paths - An array of paths defining how your stub should respond to calls
    • body - (String or Object) of the request body and will require the requester to have this as their request's body.
    • headers - Object of headers to be requred in the request
      • {'accept-charset': 'utf-8', accept: 'text/plain'}
    • path - String specifying the path to stub. (e.g. /ping)
    • response - (String or Object) which will be responeded back.
      • If the response is an Object, distRest will automatically set the Content-Type to application/json.
    • responseOptions - Object of options
      • headers Object of headers to be returned in the response
        • {'content-type': 'application/json', 'cache-control': 'no-store'}
    • status - HTTP Status code for the response. Defaults to 200.

Contributors

James Armstead
Ajdin Hedzic - https://github.com/ajdinhedzic
Todd Eschweiler

Contribute!

Be a part of this project! You can run the test using the following.

  1. Install dependencies from package.json by running npm install
  2. Run the test via npm test
  3. Contribute!

This project is licensed under the MIT License

Proudly written in Des Moines, Iowa.