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

mockserver-client

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockserver-client

A node client for the MockServer

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53K
increased by7.66%
Maintainers
1
Weekly downloads
 
Created
Source

mockserver-client-node

Communicate with MockServer from any node or grunt build

Build Status Dependency Status devDependency Status Still Maintained

Stories in Backlog Stories in Backlog Stories in Backlog

NPM

Getting Started

MockServer is for mocking of any system you integrate with via HTTP or HTTPS (i.e. services, web sites, etc).

This npm modules is allows any grunt of node project to easily communicate with the MockServer.

An addition to this module for communicating with the MockServer there is also a grunt task that can be used to start and stop MockServer from grunt called mockserver-grunt.

The both the MockServer and proxy clients can be created as follows:

var mockServer = require('mockserver-client'),
    mockServerClient = mockServer.mockServerClient, // MockServer client
    proxyClient = mockServer.proxyClient; // proxy client

Note: this assumes you have an instance of MockServer running on port 1080 for more information on how to do this see mockserver-grunt.

Setup Expectation

Then an simple expectation can be setup as follows:

mockServerClient("localhost", 1080).
    mockSimpleResponse('/somePath', { name: 'value' }, 203);

Or a more complex expectation can be setup as follows:

mockServerClient("localhost", 1080).mockAnyResponse(
    {
        'httpRequest': {
            'method': 'POST',
            'path': '/somePath',
            'queryString': 'test=true',
            'parameters': [
                {
                    'name': 'test',
                    'values': [ 'true' ]
                }
            ],
            'body': {
                'type': "STRING",
                'value': 'someBody'
            }
        },
        'httpResponse': {
            'statusCode': 200,
            'body': JSON.stringify({ name: 'value' }),
            'delay': {
                'timeUnit': 'MILLISECONDS',
                'value': 250
            }
        },
        'times': {
            'remainingTimes': 1,
            'unlimited': false
        }
    }
);

For the full syntax support see MockServer - Creating JavaScript Expectations.

Verify Requests

It is also possible to verify that request were made as follows:

mockServerClient("localhost", 1080).verify(
    {
        'method': 'POST',
        'path': '/somePath',
        'body': 'someBody'
    }, 1, true);

Release History

  • 2014-28-11   v0.0.1   Initial release
  • 2014-28-11   v0.0.2   Fixed module naming
  • 2014-28-11   v0.0.3   Fixing module loading
  • 2014-28-11   v0.0.4   Fixing badges

Task submitted by James D Bloom

Keywords

FAQs

Package last updated on 28 Oct 2014

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