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

mockingjay.js

v0.1.2

Published

"Provides Mockdata or downloads it from predefined REST services"

Downloads

3

Readme

Mockingjay.js

When should you use Mockingjay

Did you ever created client centric apps like React or Angular apps, that depend on a complex set of REST-Services, that you can not simply mock by creating a database in the same format and fill it with testing data.

But you still want to have your test suite running properly with a fixed data set, so that you can rely on its results and write simple assertions.

Why no random fixtures?

Depending on how complex and entangled your REST data is, you might get a way with a combination of json-server and factory-girl

However, I was confronted with highly entangled data which was hard to autogenerate with factory-girl or other mock data generators. My Rest responses needed to share IDs accross several object literals and after I implemented it with a mock data generator, I figured it would be too hard to maintain it like that.

What is the basic idea?

So how can you generate highly complex but properly entangled mock data? You get it from real data of your servers. But setting up such complex system on each development machine can be a harsh pain in the ass. But you still need a source of mock data that you are controll of its changes and that are still available if your complex REST-System is down.

Mockingjay now gives you the opportunity to record the REST-calls and their results in a tiny express based node server as long as your production system is available by simply running your test suite. And use the prerecorded data when your production system might be offline or is changing its interface.

Setup

To install Mockingjay simply install it via npm: npm install mockingjay.js --save-dev Now you can start it by adding it as script to your package.json ... "scripts": { "mockingjay": "mockingjay", ... } and start it by npm: npm run mockingjay By default mockingjay awaits a db.json-file and runs on port 3000. But you can define this also by its cli. npm run mockingjay --db myDb.json --port 1234

Angular 1 Adapter

If you are working with Angular 1 you can simply use the provided $http-Interceptor that you can find in /lib/adapters/mockingjay-ng1-adapter.js

If you include this script into your build and make it a dependency of your angular app: angular.module('myApp', ['Mockingjay']) .constant('MockingjaySettings', { baseUrl: 'http://localhost', port: 3000, includingUrls: [ <regexes matching urls> ], excludingUrls: [ <regexes matching ulrs> ] }) Now all urls that match on of the regexes defined in includingUrls will be redirected to mockingay. All Urls matching also excludingUrls will not be redirected to Mockingjay.

If an adapter for your favorite framework is still missing

You can simply redirect urls by yourself if your favorite framework is not yet supported (looking forward to your pull requests :). You call your mockingjay instance with the (encodedURIComponent)[http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp] version of the url you want to be recorded by mockingjay: http://localhost:3000/urls/http%3A%2F%2Fmy-rest-service

Record by testing

Now you can set Mocksettings set into recording mode by putting {"dbIntegrityMode": "OVERWRITE"} to http://localhost:3000/dbIntegrityMode and run a suite of tests that call your complex REST-System and afterwards db.json will contain all your mockdata. Mockingjay supports all sorts of REST-verbs (GET, PUT, POST, DELETE)