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

koa-sham

v0.0.11

Published

To send fake request to a Koa application without starting a http server. So that, you can require a Koa app into your code.

Downloads

1,114

Readme

koa-sham

To send fake request to a Koa application without starting a http server.

Sending multipart data will be supported later.

Installation

$ npm i koa-sham --save

Usage

const Koa = require( 'koa' );
const sham = require( 'koa-sham' );

const app = new Koa();

app.use( ctx => {
    ctx.body = { status : 1 };
} );

sham( app, ( err, res, body ) => {
    console.log( body ); // { status : 1 }
} );

sham( app, {
    qs : {
        x : 1
    }
}, ( err, res, body ) => {
    console.log( body ); // { status : 1 }
} );

sham( app, '/path', { https: true }, ( err, res, body ) => {
    console.log( body ); // { status : 1 }
} );

sham( app, { 
    method : 'POST',
    body : {
        x : 1
    }
}, ( err, res, body ) => {
    console.log( body ); // { status : 1 }
} );

Promise

sham( app, { promise : true } ).then( data => {
    console.log( data );
} );

Streaming

sham( app ).pipe( process.stdout );

API

sham( app, [ url, options, callback ] )

Returns a Readable Stream by default, but can be changed by using { promise : true } in options.

app

The instance of Koa application.

url

Type: String

The URL or PATH the you want to request. The host of the URL will be set as 127.0.0.1 by default. The protocol will be set to http if options.https is not true. The default port is 80 and it can be changed with options.port.

If the protocol of the URL is https, the request will be set to secure, even thought the options.https is not set to true.

options

Type: Object

Options for the fake request.

  • remoteAddress String The remote IP address, 127.0.0.1 by default.

  • host String The host of URL, this item will be ignored if the passed URL contains it's host.

  • port Number The port of URL, this item will be ignored if the passed URL contains it's host.

  • https Boolean To set the request to secure, this item will be ignored if the passed URL contains it's protocol and is not 'https'.

  • method String The request method

  • qs Object The query string, should be an object.

  • headers Object The headers of the request.

  • cookies Object The cookies that will be set while sending request, it will overwrite the same cookie which is also in headers.

  • body Object String The request body for POST or PUT request.

  • promise Boolean If promise is true, the function will return a Promise object.

  • **resolveWithFullResponse Boolean By setting this option to true, the returned promise will use the full response data as it's value.