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

wdio-wiremock-service

v7.0.2

Published

A WebdriverIO service to start & stop WireMock Standalone

Downloads

5,100

Readme

WebdriverIO WireMock Service

npm version downloads

Join the chat at https://gitter.im/erwinheitzman/wdio-wiremock-service

This service helps you to run WireMock seamlessly when running tests with WebdriverIO. It uses the well known Maven repository to download the WireMock jar for you which is then automatically installed, started and stopped. Stay up to date by joining the community over at Gitter for help and support.

Installation

npm i -D wdio-wiremock-service

Instructions on how to install WebdriverIO can be found here.

Usage

In the root directory (default ./mock) you find two subdirectories, __files and mappings which are used for your fixtures and mocks.

For more information, checkout WireMock's official documentation.

Configuration

In order to use the service with the wdio testrunner you need to add it to your service array:

// wdio.conf.js
export.config = {
  // ...
  services: ['wiremock'],
  // ...
};

When using webdriverio standalone you need to add the service and trigger the onPrepare and onComplete hooks manually. An example can be found here (the example makes use of Jest):

Options

The following options can be added to the service.

port

Port where WireMock should run on.

Type: Number

Default: 8080

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { port: 8181 }]],
	// ...
};

rootDir

Path where WireMock will look for files.

Type: String

Default: ./mock

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { rootDir: './mock' }]],
	// ...
};

version

Version of WireMock to be downloaded and used.

Type: String

Default: 3.3.1

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { version: '2.25.1' }]],
	// ...
};

skipWiremockInstall

Tell the service to skip downloading WireMock.

Type: Boolean

Default: false

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { skipWiremockInstall: true }]],
	// ...
};

binPath

Custom path to a local Wiremock binary (often used in combination with skipWiremockInstall).

Type: String

Default: './wiremock-standalone-3.0.0.jar' (relative from service)

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { binPath: './my-custom/example-path/wiremock-standalone-3.0.0.jar' }]],
	// ...
};

silent

Silent mode for logging WireMock's output (including additional logging from the service itself).

Type: Boolean

Default: false

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { silent: true }]],
	// ...
};

mavenBaseUrl

Base download url for Maven.

Type: String

Default: https://repo1.maven.org/maven2

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [['wiremock', { mavenBaseUrl: 'https://repo1.maven.org/maven2' }]],
	// ...
};

args

List where you can pass all the supported arguments for configuring WireMock

Note: you cannot pass the options (port, rootDir, stdio, mavenBaseUrl) here as they will be ignored.

Type: Array

Example:

// wdio.conf.js
export const config = {
	// ...
	services: [
		[
			'wiremock',
			{
				args: ['--verbose', '--match-headers'],
			},
		],
	],
	// ...
};

Writing tests

Writing your first test is really straight forward:

Using the WDIO testrunner

import fetch from 'node-fetch'; // you can use any HTTP client you like
import { equal } from 'node:assert'; // you can use any assertion library you like

describe('example', () => {
	it(`should assert the mock data`, async () => {
		const body = await fetch('http://localhost:8080/api/mytest');
		equal(body.text(), 'Hello world!');
	});
});

Using WebdriverIO Standalone

import fetch from 'node-fetch'; // you can use any HTTP client you like
import { equal } from 'node:assert'; // you can use any assertion library you like
import { remote } from 'webdriverio';
import { launcher } from 'wdio-wiremock-service';

const WDIO_OPTIONS = {
	capabilities: {
		browserName: 'chrome',
	},
};

describe('example', () => {
	let wiremockLauncher;
	let client;

	beforeAll(async () => {
		wiremockLauncher = new launcher(); // create instance of the service
		await wiremockLauncher.onPrepare(WDIO_OPTIONS); // run the onPrepare hook
		client = await remote(WDIO_OPTIONS);
	});

	afterAll(async () => {
		await client.deleteSession();
		await wiremockLauncher.onComplete(); // run the onComplete hook
	});

	test('should showoff a mocked api response', async () => {
		const body = await fetch('http://localhost:8080/api/mytest');
		equal(body.text(), 'Hello world!');
	});
});

For more information on WebdriverIO see the homepage.