{"id":11984,"library":"scenario-mock-server","title":"Scenario Mock Server","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/kenneth-gray/scenario-mock-server","tags":["javascript","mock","mocks","server","scenario","scenarios","typescript"],"install":[{"cmd":"npm install scenario-mock-server","lang":"bash","label":"npm"},{"cmd":"yarn add scenario-mock-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add scenario-mock-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` is supported, TypeScript projects and modern JavaScript environments should use ES Modules `import`.","wrong":"const { run } = require('scenario-mock-server');","symbol":"run","correct":"import { run } from 'scenario-mock-server';"},{"note":"Used for integrating the mock server into an existing Express application.","wrong":"const { createExpressApp } = require('scenario-mock-server').createExpressApp;","symbol":"createExpressApp","correct":"import { createExpressApp } from 'scenario-mock-server';"},{"note":"This is a TypeScript type definition. Always use `import type` for types to avoid bundling issues and clarify intent.","wrong":"import { HttpMock } from 'scenario-mock-server';","symbol":"HttpMock","correct":"import type { HttpMock } from 'scenario-mock-server';"}],"quickstart":{"code":"import { run } from 'scenario-mock-server';\n\nrun({\n\tscenarios: {\n\t\titem: [\n\t\t\t{\n\t\t\t\tpath: '/api/test-me',\n\t\t\t\tmethod: 'GET',\n\t\t\t\tresponse: { data: { blue: 'yoyo' } },\n\t\t\t},\n\t\t],\n\t\tcheese: [\n\t\t\t{\n\t\t\t\tpath: '/api/test-me',\n\t\t\t\tmethod: 'GET',\n\t\t\t\tresponse: { data: { blue: 'cheese' } },\n\t\t\t},\n\t\t],\n\t},\n\toptions: {\n\t\tport: process.env.MOCK_SERVER_PORT ? parseInt(process.env.MOCK_SERVER_PORT) : 3000,\n\t\tcookieMode: false\n\t}\n});\n\nconsole.log('Scenario Mock Server running. Visit http://localhost:3000 to manage scenarios.');","lang":"typescript","description":"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."},"warnings":[{"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`.","message":"The 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"Custom 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Specify a different port in the `options` object when calling `run()` or `createExpressApp()`, e.g., `{ options: { port: 3001 } }`.","cause":"The default port (3000) for the mock server is already occupied by another process.","error":"Error: listen EADDRINUSE: address already in use :::3000"},{"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.","cause":"Attempting to use `require()` in an ECMAScript Module (ESM) context without proper configuration (e.g., `\"type\": \"module\"` in `package.json` but using `require`).","error":"ReferenceError: require is not defined"},{"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.","cause":"The requested scenario ID does not exist in your defined scenarios, or the server is not configured to select it.","error":"Scenario 'my-missing-scenario-id' not found or active for path '/api/data'"}],"ecosystem":"npm"}