Scenario Mock Server

1.2.0 · active · verified Sun Apr 19

Scenario Mock Server is a Node.js library for creating highly configurable mock servers driven by user-defined scenarios. Currently stable at version 1.2.0, it is actively maintained with regular minor and patch releases, recently adding features like scenario grouping in the UI and exposing request headers to response functions. Key differentiators include an integrated web UI for dynamic scenario selection, a 'cookie mode' for multi-user isolation allowing each client to manage their own scenario state, and support for parallel testing through custom `sms-scenario-id` and `sms-context-id` headers, which bypass server-side scenario selection for specific requests. It can run as a standalone server or integrate into an existing Express application.

Common errors

Warnings

Install

Imports

Quickstart

This example initializes the mock server with two distinct scenarios, 'item' and 'cheese', for the '/api/test-me' endpoint, demonstrating basic setup and scenario definition.

import { run } from 'scenario-mock-server';

run({
	scenarios: {
		item: [
			{
				path: '/api/test-me',
				method: 'GET',
				response: { data: { blue: 'yoyo' } },
			},
		],
		cheese: [
			{
				path: '/api/test-me',
				method: 'GET',
				response: { data: { blue: 'cheese' } },
			},
		],
	},
	options: {
		port: process.env.MOCK_SERVER_PORT ? parseInt(process.env.MOCK_SERVER_PORT) : 3000,
		cookieMode: false
	}
});

console.log('Scenario Mock Server running. Visit http://localhost:3000 to manage scenarios.');

view raw JSON →