Registry / testing / scenario-mock-server

scenario-mock-server

JSON →
library1.2.0jsnpmunverified

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.

npm install scenario-mock-server
INSTALL
IMPORT
SIG · SCENARIO-MOCK-SERV
S
scenario-mock-server
testingjavascriptv1.2.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

run
✓ import { run } from 'scenario-mock-server';
✗ const { run } = require('scenario-mock-server');
While CommonJS `require` is supported, TypeScript projects and modern JavaScript environments should use ES Modules `import`.
createExpressApp
✓ import { createExpressApp } from 'scenario-mock-server';
✗ const { createExpressApp } = require('scenario-mock-server').createExpressApp;
Used for integrating the mock server into an existing Express application.
HttpMock
✓ import type { HttpMock } from 'scenario-mock-server';
✗ import { HttpMock } from 'scenario-mock-server';
This is a TypeScript type definition. Always use `import type` for types to avoid bundling issues and clarify intent.

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.');
Debug
Known issues
breakingThe package was renamed from `data-mocks-server` to `scenario-mock-server`. Projects upgrading or migrating from the old package name must update their `package.json` and all import/require statements.
fix
Update `npm install data-mocks-server` to `npm install scenario-mock-server` and change all code references from `data-mocks-server` to `scenario-mock-server`.
affects: >=1.0.0
gotchaCustom headers `sms-scenario-id` and `sms-context-id` for parallel testing are explicitly NOT supported when `cookieMode` is enabled. If you need per-request scenario selection, ensure `cookieMode` is set to `false` (default) or not configured.
fix
If parallel testing with headers is required, do not enable `cookieMode`. If `cookieMode` is necessary, manage scenarios and contexts via the UI or programmatically for individual users/sessions.
affects: >=1.0.0
breakingVersion 1.0.0 marked the first major release of the `scenario-mock-server` under its new name. While specific breaking changes from any pre-1.0.0 versions of `data-mocks-server` are not detailed in the release notes, users migrating from unversioned or pre-1.0.0 iterations of the original project should expect potential API shifts.
fix
Refer to the `scenario-mock-server` documentation for the latest API if migrating from older `data-mocks-server` versions. Review your mock definitions and server setup.
affects: >=1.0.0
Errors
Common errors & fixes
Error: listen EADDRINUSE: address already in use :::3000
The default port (3000) for the mock server is already occupied by another process.
fix
Specify a different port in the `options` object when calling `run()` or `createExpressApp()`, e.g., `{ options: { port: 3001 } }`.
ReferenceError: require is not defined
Attempting to use `require()` in an ECMAScript Module (ESM) context without proper configuration (e.g., `"type": "module"` in `package.json` but using `require`).
fix
Switch to `import { run } from 'scenario-mock-server';` syntax, or ensure your environment is configured for CommonJS modules, or use a build tool to transpile.
Scenario 'my-missing-scenario-id' not found or active for path '/api/data'
The requested scenario ID does not exist in your defined scenarios, or the server is not configured to select it.
fix
Verify the scenario ID spelling. Ensure the scenario is correctly defined in the `scenarios` object. If using the UI, select the correct scenario. If using `sms-scenario-id` header, confirm the header value matches an existing scenario group key.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
6
Resources
scenario-mock-server — npm install scenario-mock-server · libregistry