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 🙏

© 2025 – Pkg Stats / Ryan Hefner

mock-cmdr

v1.1.0

Published

Wiremock Client

Readme

Mock Commander

Wiremock client for Node JS which promotes separation of dynamic mocking commands from test code logic.

Installation

npm install mock-cmdr

Documentation

https://mock-cmdr.js.org/

Usage

Mock Commander can be simply used as a Wiremock rest API client:

const mockCmdr = require('mock-cmdr');
mockCmdr.init({ baseUrl: 'http://wiremock' });
mockCmdr.createMapping({
  request: {
    method: 'GET',
    urlPath: '/user/1',
  },
  response: {
    jsonBody: {
      id: 1
    }
  },
});

However, Mock Commander's real utility comes from defining templated Wiremock commands. If the mapping definintion above is moved into ${__dirname}/mock/stub/get-user-by-id.js then the same create mapping call can be made by:

const user = { id: 1 };
await mockCmdr.stub.getUserById(user);

Commands are loaded by providing the cmdDir option to mockCmdr.init():

const path = require('path');
const mockCmdr = require('mock-cmdr');
mockCmdr.init({
  baseUrl: wiremockBaseUrl,
  cmdDir: path.resolve(__dirname, 'mock'),
});

See the Mock Commander Cucumber Test Suite for a full example demonstrating how to define and use templated Wiremock commands with Cucumber.

Command Dir Layout

The following example demonstrates the layout of a command dir:

[cmdDir]
  |- stub
  |  |- user
  |     |- create.js
  |     |- get-by-id.js
  |
  |- find
     |- user
        |- create-by-email.js

The resulting commands after calling mockCmdr.init({ cmdDir }) will be:

mockCmdr.stub.user.create()
mockCmdr.stub.user.getById()
mockCmdr.find.user.createByEmail()

Example Stub Command

/**
 * @returns {WiremockStubMapping}
 */
module.exports = function(user) {
  return {
    request: {
      method: 'GET',
      urlPath: `/user/${user.id}`,
    },
    response: {
      jsonBody: user.toApiModel(),
    },
  };
};

Example Find Command

/**
 * @returns {WiremockRequestCriteria}
 */
module.exports = function(user) {
  return {
    method: 'GET',
    urlPath: `/user/${user.id}`,
  };
};

API Summary

mock-cmdr module

.init(options)

Initialize the Mock Commander session. If cmdDir is specified then loadCmds() will also be called.

options:

  • baseUrl (string) - the mock server base URL, eg: http://wiremock:8080.
  • cmdDir (string) - the dir to load commands from.

.defineCmd(command)

Define a templated mocking command that will be available via mockCmdr.{type}.{path} or mockCmdr.{type}.{name}. When the command is invoked then createMapping() or findRequests() will be called with the output of the command's template function.

command:

  • type (string) - "stub" or "find".
  • path (string[]) - the path the command will be available at within mockCmdr.stub or mockCmdr.find.
  • name (string) - shorthand for { path: [ name ] }
  • template (function) - A function that returns either a "find requests" criteria or a "stub mapping" definition.

.loadCmds(dir)

Load all "find" and "stub" mocking commands by searching recursively within baseDir.

The discovered commands will be passed to defineCmd() using the camel cased file names as the command path. Modules found within a "find" directory are treated as "find" commands and modules found within a "stub" directory are treated as "stub" commands. Modules not within a "find" or "stub" directory are ignored.

Any intermediate directories other than "find" and "stub" will be treated as namespaces. Namespaces can be arbitrarily deep and are also camel cased. The "find" and "stub" dirs are excluded from the namespace and need not appear at the top level allowing related commands to be grouped appropriately.

.createMapping(mapping)

async

Call the Wiremock Stub Mapping API.

.findRequests(criteria)

async

Call the Wiremock Find Requests API.

.stub

Access to "stub" commands registered via mockCmdr.defineCmd().

.find

Access to "find" commands registered via mockCmdr.defineCmd().

.cleanUp()

async

Remove stub mappings from the Wiremock server that have been created by the current session.

Legal

Copyright 2020 Nathan Jones. Licensed under the Apache License, Version 2.0.