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

  • 5.2.3
  • 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 Code Climate

NPM

For chat room: Gitter

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)
    .then(
        function(result) {
            // do something next
        }, 
        function(error) {
            // handle error
        }
    );

Or a more complex expectation can be setup as follows:

mockServerClient("localhost", 1080)
    .mockAnyResponse(
        {
            'httpRequest': {
                'method': 'POST',
                'path': '/somePath',
                'queryStringParameters': [
                    {
                        '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
            }
        }
    )
    .then(
        function(result) {
            // do something next
        }, 
        function(error) {
            // handle error
        }
    );

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
    )
    .then(
        function() {
            // do something next
        }, 
        function(failure) {
            // handle verification failure
        }
    );

It is also possible to verify that sequences of requests were made in a specific order as follows:

mockServerClient("localhost", 1080)
    .verifySequence(
        {
            'method': 'POST',
            'path': '/somePathOne',
            'body': 'someBody'
        },
        {
            'method': 'GET',
            'path': '/somePathTwo'
        },
        {
            'method': 'GET',
            'path': '/somePathThree'
        }
    )
    .then(
        function() {
            // do something next
        }, 
        function(failure) {
            // handle verification failure
        }
    );

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Release History

DateVersionDescription
2014-28-10v0.0.1Initial release
2014-28-10v0.0.2Fixed module naming
2014-28-10v0.0.3Fixing module loading
2014-28-10v0.0.4Fixing badges
2014-01-11v1.0.0Cleaned code & removed duplication
2014-02-11v1.0.1Added wercker build process
2014-21-11v1.0.2Fixed asynchronous errors
2014-04-12v1.0.3Improved connection error handling
2014-04-12v1.0.4Supporting protractor based promises
2015-04-06v1.0.5Upgrading dependencies
2015-06-02v1.0.6Improved clear and dumpToLog options
2015-09-27v1.0.7Fixed error with query parameter handling
2015-09-27v1.0.8Fixed documentation
2015-09-28v1.0.9Fixed documentation again
2015-10-11v1.0.10Added retrieve requests or expectations
2016-09-27v1.0.11Updated dependencies
2016-10-09v1.0.12Resolved issues with dependencies
2017-04-30v1.0.13Added websocket (i.e. method callbacks)
2017-05-03v1.0.14Backward compatibility for mockAnyResponse
2017-05-03v1.0.15Improving promise logic for protractor
2017-05-04v1.0.16Removed grunt peer dependencies
2017-11-18v2.0.0Improved error handling for server validation
2017-12-06v5.1.0Upgrading MockServer to 5.1.0
2017-12-07v5.1.1Upgrading MockServer to 5.1.1
2017-12-10v5.2.0Upgrading MockServer to 5.2.0
2017-12-11v5.2.1Improved error output + upgrade to 5.2.1
2017-12-12v5.2.2Fixed incorrect error format 5.2.2
2017-12-18v5.2.3  Added retrieveLogs + upgrade to 5.2.3

Task submitted by James D Bloom

Analytics

Keywords

FAQs

Package last updated on 18 Dec 2017

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