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

kittymocklib-ts

v1.0.2

Published

That's lib is a kittymock abstraction in typescript

Downloads

2

Readme

KittyMockLib-TS

pipeline status coverage status

This lib is a Typescript KittyMock abstraction.The objective is to be an easier form to develop in typescript to use this mockers. For more information about KittyMocker, read this documentation.

Dependencies

Packages

npm install kittymocklib-ts

KittyMock Version

0.3.2

Lib Concepts Prerequisites

Short Explain

To fully use the lib some concepts need to be previously dominated, if you need some help or be interested here are a topics list and a support material for help you.

Concepts dependencies list

Lib Overview

stack Overflow

KittyMockerBuilder

Short Explain
  • This layer has the objective of build new mockers according to your configuration.
Code Example
  • IAddressParams: This interface standardizes the params used on kittyMockerBuilder creation.

    • Host: Kitty Mocker server host.

    • Port: Kitty Mocker server port.

      let serverAddress: IAddressParams = {
          host: "localhost",
          port: 6999
      }
  • it's necessary to instantiate the object KittyMockerBuilder.

      let mockerBuilder = new KittyMockerBuilder(serverAddress)

Response of MockerHttp methods

Short Explain

The manipulation method responses has an objective to help with mocker HTTP usage..

Code Example
export default interface IResponse{
    status: boolean //Boolean success
    statusCode?: number //statusCode of Http Methods
    data?: string   //Data of body kitty mock response
    message?: string    //Message for help users
}

Create mocker

Short Explain

The mocker creation will generate a random port(port range is configured in kittyMockerServer). using this port will be possible to use the mocker resources. On use create MOcker you will receive an object IMockerHttp with a mocker port created and configured for use them resources.

Method Signature
  • mockerBuilder.createMocker (): Promise <IMockerHttp>
Code Example
let mockerHttp: MockerHttp
mockerBuilder.createMocker().then((mocker: IMockerHttp) => {
    mockerHttp = mocker
)).catch((error: IResponse) => {
    console.log(
        "Boolean success state: ", error.status
        "Error Message: ", error.message,
    )
})
Response Schema Example
  • Success

      MockerHttp {
        mockerHTTPClient:
         { [Function: wrap]
           request: [Function: wrap],
           getUri: [Function: wrap],
           delete: [Function: wrap],
           get: [Function: wrap],
           head: [Function: wrap],
           options: [Function: wrap],
           post: [Function: wrap],
           put: [Function: wrap],
           patch: [Function: wrap],
           defaults:
            { headers: [Object],
              baseURL: 'http://kittymock.com.br:7008',
              transformRequest: [Array],
              transformResponse: [Array],
              timeout: 1000,
              adapter: [Function: httpAdapter],
              xsrfCookieName: 'XSRF-TOKEN',
              xsrfHeaderName: 'X-XSRF-TOKEN',
              maxContentLength: -1,
              validateStatus: [Function: validateStatus] },
           interceptors:
            { request: [InterceptorManager],
              response: [InterceptorManager] } } }
  • Error

    • Create a mocker with a inexistence host or port

        { status: false,
          message:
           'Invalid credentials or not have connectivity with kittyMocker Server' }

MockerHttp

Short Explain

This is a mocker that allows the system simulation that obeys the HTTP.

Create Route

Short Explain

The method createRoute will create a route to the created mocker.

Method Signature
  • mockerHttp.createRoute(route: IRoute): Promise<IResponse>
Code Example
  • IRoute: This interface is responsible flex the route creation standardize the form of how to create it.

    let routeSetting: IRoute = {
        filters: {path: "/route", method: "GET"}, 
        response: {code: 200, body: "Route Created"}
    };
    mockerHttp.createRoute(routeSetting).then((success: IResponse) => {
        console.log(
            "Boolean success state: ", success.status, 
            "Status Code: " success.statusCode
        )
    }).catch((error: IResponse) => {
        console.log(
            "Boolean success state: ", error.status,
            "Error Message: ", error.message,
            "Status Code: ", error.statusCode,
        )
    })
Response Schema Example
  • Success

      { status: true, statusCode: 200 }
  • Error

    • Invalid Path

        { status: false,
          statusCode: 403,
          message: 'request with invalid route path' }
    • Invalid Method

        { status: false,
          statusCode: 403,
          message: 'request with invalid route method' }
    • Invalid Response Code

            { status: false,
              statusCode: 403,
              message: 'request with invalid route response code' }

Request in a Route

Short Explain

The method requestRoute makes an HTTP requisition in a created route of the used mocker. method and path have been previously created.

Method Signature
  • mockerHttp.requestRoute(path: string, method: Method): Promise<IResponse>
Code Example
  • The example using routeSetting in createRoute example only demonstrated the standard usage form, but just is necessary that the route is created in the right form in the words using valid path and methods previously created.

      mockerHttp.requestRoute(routeSetting.filters.path, routeSetting.filters.method).then((success: IResponse) => {
          console.log(
              "Boolean success state: ", success.status, 
              "Status Code: " success.statusCode
              "Request Body: " success.data
          )
      }).catch((error: IResponse) => {
          console.log(
              "Boolean success state: ", error.status,
              "Error Message: ", error.message,
              "Status Code: ", error.statusCode,
          )
      })
Response Schema Example
  • Success

      { status: true, statusCode: 200, data: '"oi"' }
  • Error

    • Request in a route, method valid but not created or a invalid path

        { status: false,
          statusCode: undefined,
          message: 'Request failed with status code 404' } 

Get a Route History

Short Explain

The method getRouteHistory takes a created route history. for verifying the reliability of the requests from the route.

Method Signature
  • mockerHttp.getRouteHistory(filter: IFilter): Promise<IResponse>
Code Example
mockerHttp.getRouteHistory(routeSetting.filters).then((success: IResponse) => {
    console.log(
        "Boolean success state: ", success.status,
        "Success Message: ", success.message,
        "Request History: " success.data
    )
}).catch((error: IResponse) => {
    console.log(
        "Boolean: ", error.status,
        "Error Message: ", error.message,
        "Status Code: ", error.statusCode,
    )
})
Response Schema Example
  • Success

      { status: true,
        statusCode: 200,
        data: '{"status":"success","data":[]}' }
  • Error

    • Get Route History using invalid path or method

        { status: false, statusCode: 404, message: 'Not Found' }

Clear a Route History

Short Explain

The method clearRouteHistory clear a created route's history.

Method Signature
  • mockerHttp.clearRouteHistory(filter: IFilter): Promise<IResponse>
Code Example
mockerHttp.clearRouteHistory(routeSetting.filters).then((success: IResponse) => {
    console.log(
        "Boolean success state: ", success.status,
        "Status Code: ", success.statusCode,
    )
}).catch((error: IResponse) => {
    console.log(
        "Boolean success state: ", error.status,
        "Error Message: ", error.message,
        "Status Code: ", error.statusCode,
    )
})
Response Schema Example
  • Success

      { status: true, statusCode: 204 }
  • Error

    • Clear Route History using invalid path or method

        { status: false,
          statusCode: 404,
          message: 'Request failed with status code 404'}

Delete a Route

Short Explain

The method deleteRoute deletes an existence route and release the route.

Method Signature
  • mockerHttp.deleteRoute(path: string): Promise<IResponse>
Code Example
mockerHttp.deleteRoute(routeSetting.filters.path).then((success: IResponse) => {
    console.log(
        "Boolean success state: ", success.status,
        "Success Message: ", success.message,
    )
}).catch((error: IResponse) => {
    console.log(
        "Boolean: ", error.status,
        "Error Message: ", error.message,
        "Status Code: ", error.statusCode,
    )
})
Response Schema Example
  • Success

      { status: true, statusCode: 204 }
  • Error

    • Delete a inexistence route

        { status: false,
          statusCode: 404,
          message: 'route does not exist' }

Delete Mocker

Short Explain

The method delete Docker finished the mocker's life cycle Releasing the occupied port and destroy any data saved in the mocker that will be destroyed.

Method Signature
  • mockerHttp.deleteMocker(): Promise<IResponse>;
Code Example
mockerHttp.deleteMocker().then((success: IResponse) => {
    console.log(
        "Boolean success state: ", success.status,
        "Success Message: ", success.message,
        "Status Code: ", success.statusCode,
    )
}).catch((error: IResponse) => {
    console.log(
        "Boolean success state: ", error.status,
        "Error Message: ", error.message,
        "Status Code: ", error.statusCode,
    )
})
Response Schema Example
  • Success

      { status: true, statusCode: 204, message: 'No Content' }