New Features
-
Mock State 联动能力:
- Added shared Mock State support for dynamic response functions through
ctx.state. - Dynamic mock functions can now read and write shared state across different API rules.
- Supports realistic CRUD flows such as creating a user with
POST /api/usersand reading it later withGET /api/users. - Exported
MockContextandMockStateStoretypes for TypeScript users.
- Added shared Mock State support for dynamic response functions through
-
State Panel:
- Added a new
Statetab to the PocketMocker dashboard. - Users can view, edit, save, clear, copy, and import shared Mock State as JSON.
- Added a persistence toggle for controlling whether Mock State survives refreshes.
- Added a new
-
Mock State Persistence:
- Local mode stores Mock State in
localStorage. - Vite plugin mode stores Mock State in
pocket-mock-state.json. - Added Vite plugin endpoints for reading, saving, and resetting Mock State.
- Local mode stores Mock State in
-
Demo Experience:
- Added a linked API state demo to
src/main.ts. - Demo users can create records through
POST /api/usersand refreshGET /api/usersto verify stateful API behavior.
- Added a linked API state demo to
Bug Fixes
-
Fixed absolute path matching so parent paths no longer implicitly match child paths.
- For example,
/appplyno longer matches/appply/invite. - Use explicit wildcard rules such as
/appply/*when child path matching is intended.
- For example,
-
Added CodeMirror dependency dedupe configuration in Vite to avoid duplicate
@codemirror/stateinstances causing editor initialization failures.
Tests
- Added unit tests for Mock State store operations.
- Added handler tests covering shared state between dynamic response functions.
- Added Vite plugin tests for Mock State file read, save, validation, and reset behavior.
- Added matcher regression tests for absolute path matching boundaries.
Documentation
- Added
docs/MOCK_STATE_DESIGN.zh-CN.mdwith the Mock State design, API shape, UI plan, persistence behavior, and rollout strategy.
📦 NPM Package: pocket-mocker@1.3.0