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

@mockthat/core

v0.1.1

Published

[![npm version](https://badge.fury.io/js/%40mockthat%2Fcore.svg)](https://badge.fury.io/js/%40mockthat%2Fcore)

Downloads

13

Readme

Mock that!

npm version

Installation

Mockserver can be installed globally if you need to run it as a command:

$ npm install -g @mockthat/web

$ mockthat --path ./custom-folder --port 8080
Mock that! is currently runnig at http://localhost:8080/
Serving Files: <your-project-path>/custom-folder

Note: You can install @mockthat/core if you want a version without the web browser, if you use @mockthat/web will be using the web from @mockthat/web

Options

  • --path (default: <your-project-path>/mocks): Path that will be as root of mocks
  • --port (default: 7000): Where the server will be started

Usage

You can check some demo structure at ./examples

Create a ./mock folder into the root of your project. You have the following entities:

  • Category: is a main wrapper of module tests, you can have only one category running at time
  • Scenarios: is the current state of the mock - there you can define api and websockets

Category

Every folder inside ./mock will be considered a different "category" for mocking - you can only run one mock category at time

  1. Create a sub-folder into your ./mock folder.
  2. Inside that folder you must create:
    • ./scenarios folder - where it you will have the scenarios for each mock state
    • main.json file - where you will have this category name
{
  "name": "Your category name"
}

Scenarios

On scenario is where you define what your mock will be using (api or/and websocket) and it's under a category, for example ./category-a/scenarios/<my-scenario>

A simple example of scenario configutarion:

{
  "name": "Scenario name",
  "api": {
    "active": true,
    "config": "./api/main.json"
  },
  "websocket": {
    "active": true,
    "config": "./websocket/main.json"
  }
}

API

You can check all fields type on https://github.com/mockthat/core/blob/master/src/shared/interfaces/main/service-main.interface.ts

Here you can define what port your API will be running, response code, what will reply, method and others.

Example of api JSON:

{
  "services": [
    {
      "api": "/balance",
      "method": "GET",
      "path": "./response/success.json",
      "code": 200,
      "header": {
        "custom-header": "Oh yeah!"
      }
    }
  ],
  "port": 5000
}

Please not that all paths are relative from where this JSON is located.

Websocket

You can check all fields type on https://github.com/mockthat/core/blob/master/src/shared/interfaces/main/service-main.interface.ts

Here you can define the repetition strategy, when it will be trigged and what messages you will be sending.

Example of Websocket JSON:

{
  "trigger": "IMMEDIATELY",
  "repeat": "LOOPING",
  "messages": [{
    "event": "dummy",
    "path": "./messages/1.json",
    "delay": 300
  }, {
    "event": "dummy",
    "path": "./messages/2.json",
    "delay": 300
  }, {
    "event": "dummy",
    "path": "./messages/3.json",
    "delay": 300
  }]
}

Please not that all paths are relative from where this JSON is located.