Giter Site home page Giter Site logo

core's Introduction

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 ./mocks 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 ./mocks will be considered a different "category" for mocking - you can only run one mock category at time

  1. Create a sub-folder into your ./mocks 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.

core's People

Contributors

picheli20 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.