Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-fixturer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-fixturer

Easily manage your API fixtures

  • 0.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
8
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

Express-fixturer

Express middleware that save the response payload (fixtures) of each http request against a hash and reply with those fixtures when you turn it into fixture mode.

The name of the file is the hash created from the request so you get the right mocked data for each of your request.

It should help you mocking endpoints so you don't have to bother updating fixtures.

How to get started

Install the middleware:

npm install express-fixturer

Plug it to express:

const app = express();
app.use(expressFixturer({ fixtureBasePath: './fixtures' }));

API

middlewareFactory

Description

Create a unique hash for each http request and use this hash as a filename to save the response payload.

How to import:
import middlewareFactory from 'express-fixturer';
Parameters of the factory function:
  • saveRoutes (optional, default: true) boolean | string[]: If true, it will create fixtures for each of your express endpoints. You can also pass an array of routes and it will only create fixtures for those routes.
  • fixtureRoutes (optional, default: false) boolean | string[]: If true, it will use the fixtures if it find them or will trigger your handler and save the response payload as a fixture.
  • fixtureBasePath (optional, default: ./) string: Define the path to the folder of your fixtures.
  • hashFn (optional) (req: express.Request) => object: Define how to generate your hash used to identify the fixture to the right request. The default hash function will include req.body, req.cookies, req.params, req.query and req.path
  • logging (optional, default: verbose) verbose | quiet: If set to verbose it will log.
Example

This will save fixtures to the fixtures folder.

const app = express();
app.use(expressFixturer({ fixtureBasePath: './fixtures' }));

TODO

  • Implement string[] routes to save fixtures or not
  • Implement string[] for using fixtures or not
  • Handle nested folder structure for fixtureBasePath

Keywords

FAQs

Package last updated on 09 Aug 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc