Code Monkey home page Code Monkey logo

mocks-server-lite's Introduction

Mocks Server Lite

Credit: This is heavily inspired by mocks-server and takes some of the main concepts from it. It is massively simplified though, currently with only the core functionality as well as being TypeScript first. I created this because the mocks-server project doesnt currently seem to be very active and doesnt come with types and a few other features I think is key, which are listed below.

Introduction

Node.js mock server that can run live, interactive mocks in place of real APIs. It allows you to define many different responses for a same route, so you can change the whole mocked API behavior by simply changing the response of one or many routes while the server is running. This really helps with local FrontEnd development when the BackEnd isnt ready/available and also really good for automated test runs where you want to change how the backing server behaves whilst it is still running.

Installation/Getting Started

Main Features

  • define multiple static or dynamic mock responses (variants) for api endpoints (routes)
  • group together route mock responses in collections
  • change route responses without having to restart the mocks server
  • support route middleware
  • add response delays with route override
  • call logs so you can return something different on subsequent calls
  • web sockets support
  • static paths support

Learn more...

FAQ

No advantages per se but different in the fact youre actually calling a mocked server served at a URL rather than the request being intercepted at any level in code. Also different in that I don't see this as a mocking tool to use with jest or vitest, more to use with local development (if a BackEnd isnt ready/available) or supporting an E2E test run (using tools like cypress or playwright) where you dont want it hit a real BackEnd.

Example Repo

https://github.com/burt202/mocks-server-lite-example

  • all mocking code is in mocks/, with the mock server being created in mocks/server.ts
  • also see how the playwright test run can change the behaviour of the mocks server by caling setMockCollection which in turn calls POST /__set-collection with a new collection name

mocks-server-lite's People

Stargazers

Ben Ibinson avatar

Watchers

AB avatar  avatar  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.