소스 정보
- 저장소
- majiayu000/claude-skill-registry
- 최근 소스 활동
- 2026년 6월 23일 12:15
- 감지된 SKILL.md 언어
- 영어
- 스타
- 543
- 포크
- 85
설치 방법
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
소스 파일 검토
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
메뉴
기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.
설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/majiayu000/claude-skill-registry --skill api-mock명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | api-mock |
| description | Generate API mocks and stub servers from OpenAPI specs or code analysis |
| disable-model-invocation | false |
I'll help you generate API mock servers and stub services for testing and development, based on OpenAPI specifications or code analysis.
Mock Server Tools:
This skill uses mock generation-specific patterns to minimize token usage:
Pattern: Cache API specification locations and structure
.api-mock-cache (1 hour TTL)Pattern: Use yq/jq for OpenAPI parsing instead of LLM
yq '.paths | keys' (200 tokens)yq '.components.schemas' (200 tokens)Pattern: Use predefined mock server templates
Pattern: Use examples from OpenAPI spec
Pattern: Analyze first 15 endpoints for patterns
Pattern: Reuse mock server configuration
Pattern: Find existing mock servers with Grep
json-server, setupWorker, Prism.setup (200 tokens)Pattern: Detect if mocks already generated and current
Typical operation patterns:
Expected per-generation: 2,000-3,000 tokens (60% reduction from 5,000-7,000 baseline) Real-world average: 1,800 tokens (due to cached specs, template-based generation, example reuse)
Arguments: $ARGUMENTS - OpenAPI spec path, mock tool preference, or resource type
First, let me find API specifications or analyze existing code:
# Detect API specifications and existing APIs
detect_api_specs() {
echo "=== Detecting API Specifications ==="
echo ""
local spec_found=false
# Check for OpenAPI/Swagger specs
echo "Searching for OpenAPI/Swagger specifications..."
openapi_files=$(find . -type f \( -name "openapi.yaml" -o -name "openapi.yml" -o -name "swagger.yaml" -o -name "swagger.yml" -o -name "openapi.json" -o -name "swagger.json" \) 2>/dev/null)
if [ -n "$openapi_files" ]; then
spec_found=true
echo "✓ OpenAPI/Swagger specifications found:"
echo "$openapi_files" | sed 's/^/ /'
echo ""
SPEC_PATH=$(echo "$openapi_files" | head -1)
SPEC_TYPE="openapi"
fi
# Check for GraphQL schemas
if [ -z "$openapi_files" ]; then
graphql_files=$(find . -type f \( -name "schema.graphql" -o -name "*.graphql" \) 2>/dev/null | head -5)
if [ -n "$graphql_files" ]; then
spec_found=true
echo "✓ GraphQL schemas found:"
echo "$graphql_files" | sed 's/^/ /'
echo ""
SPEC_PATH=$(echo "$graphql_files" | head -1)
SPEC_TYPE="graphql"
fi
fi
# Detect REST API from code
if [ ! "$spec_found" = true ]; then
echo "No API specifications found. Analyzing code..."
echo ""
# Node.js/Express
if [ -f "package.json" ] && grep -q "express" package.json; then
echo "✓ Express API detected"
SPEC_TYPE="express"
# Try to find route definitions
routes=$(grep -r "app\.\(get\|post\|put\|delete\|patch\)" . --include="*.js" --include="*.ts" 2>/dev/null | head -5)
if [ -n "$routes" ]; then
echo " Sample routes found:"
echo "$routes" | sed 's/^/ /'
fi
echo ""
# Python/Flask
elif [ -f "requirements.txt" ] && grep -q "flask" requirements.txt; then
echo "✓ Flask API detected"
SPEC_TYPE="flask"
routes=$(grep -r "@app\.route" . --include="*.py" 2>/dev/null | head -5)
if [ -n "$routes" ]; then
echo " Sample routes found:"
echo "$routes" | sed 's/^/ /'
fi
echo ""
# Python/FastAPI
elif [ -f "requirements.txt" ] && grep -q "fastapi" requirements.txt; then
echo "✓ FastAPI detected"
SPEC_TYPE="fastapi"
routes=$(grep -r "@app\.\(get\|post\|put\|delete\)" . --include="*.py" 2>/dev/null | head -5)
if [ -n "$routes" ]; then
echo " Sample routes found:"
echo "$routes" | sed 's/^/ /'
fi
echo ""
# Go APIs
elif [ -f "go.mod" ]; then
echo "✓ Go API detected"
SPEC_TYPE="go"
routes=$(grep -r "HandleFunc\|Handle" . --include="*.go" 2>/dev/null | head -5)
if [ -n "$routes" ]; then
echo " Sample routes found:"
echo "$routes" | sed 's/^/ /'
fi
echo ""
else
echo "⚠ No API detected"
echo ""
echo "I can help you create mocks for:"
echo " - OpenAPI/Swagger specifications"
echo " - GraphQL schemas"
echo " - Custom REST APIs"
echo ""
SPEC_TYPE="custom"
fi
fi
echo "$SPEC_TYPE|$SPEC_PATH"
}
API_INFO=$(detect_api_specs)
SPEC_TYPE=$(echo "$API_INFO" | cut -d'|' -f1)
SPEC_PATH=$(echo "$API_INFO" | cut -d'|' -f2)
Selection criteria:
I'll help you select the appropriate mock server tool:
select_mock_tool() {
local spec_type=$1
echo ""
echo "=== Selecting Mock Server Tool ==="
echo ""
# Check if tool specified in arguments
if [[ "$ARGUMENTS" =~ json-server|msw|prism|wiremock ]]; then
MOCK_TOOL=$(echo "$ARGUMENTS" | grep -oE "json-server|msw|prism|wiremock" | head -1)
echo "Mock tool specified: $MOCK_TOOL"
else
# Suggest based on detected spec type
case $spec_type in
openapi)
echo "Recommended: Prism (OpenAPI-native)"
MOCK_TOOL="prism"
;;
graphql)
echo "Recommended: GraphQL Mock Server"
MOCK_TOOL="graphql-mock"
;;
express|flask|fastapi|go|custom)
echo "Recommended: json-server or MSW"
MOCK_TOOL="json-server"
;;
esac
echo ""
echo "Available mock server tools:"
echo " 1. Prism - OpenAPI/Swagger specification-based"
echo " 2. MSW - Browser and Node.js request interception"
echo " 3. json-server - Simple REST API from JSON"
echo " 4. WireMock - Advanced API simulation"
echo ""
read -p "Select tool (1-4, or Enter for recommended): " choice
case ${choice:-0} in
1) MOCK_TOOL="prism" ;;
2) MOCK_TOOL="msw" ;;
3) MOCK_TOOL="json-server" ;;
4) MOCK_TOOL="wiremock" ;;
*) ;; # Keep recommended
esac
fi
echo ""
echo "Selected mock tool: $MOCK_TOOL"
echo "$MOCK_TOOL"
}
MOCK_TOOL=$(select_mock_tool "$SPEC_TYPE")
Now I'll generate the mock server based on your selection:
generate_mock_server() {
local tool=$1
local spec_type=$2
local spec_path=$3
echo ""
echo "=== Generating Mock Server ==="
echo ""
mkdir -p mocks
case $tool in
prism)
generate_prism_mock "$spec_path"
;;
msw)
generate_msw_mock "$spec_type"
;;
json-server)
generate_json_server_mock "$spec_type"
;;
wiremock)
generate_wiremock_mock
;;
esac
}
generate_prism_mock() {
local spec_path=$1
echo "Setting up Prism mock server..."
echo ""
# Check if Prism is installed
if ! command -v prism &> /dev/null; then
echo "Installing Prism..."
npm install -g @stoplight/prism-cli
if [ $? -ne 0 ]; then
echo "⚠ Global install failed. Installing locally..."
npm install --save-dev @stoplight/prism-cli
fi
fi
# Validate OpenAPI spec
if [ -n "$spec_path" ] && [ -f "$spec_path" ]; then
echo "Validating OpenAPI specification..."
if command -v prism &> /dev/null; then
prism validate "$spec_path" || {
echo "⚠ Specification has validation errors"
echo " Continue anyway? (yes/no)"
read continue_anyway
[ "$continue_anyway" != "yes" ] && exit 1
}
fi
# Create start script
cat > mocks/start-prism.sh << EOF
#!/bin/bash
# Start Prism mock server
# Run Prism with dynamic response generation
prism mock "$spec_path" \\
--host 0.0.0.0 \\
--port 4010 \\
--dynamic
# Options:
# --dynamic: Generate dynamic realistic responses
# --errors: Include error responses
# --validateRequest: Validate requests against spec
EOF
chmod +x mocks/start-prism.sh
# Add to package.json scripts
if [ -f "package.json" ]; then
echo "Adding mock script to package.json..."
# Check if jq is available for JSON manipulation
if command -v jq &> /dev/null; then
jq '.scripts.mock = "prism mock '"$spec_path"' --port 4010 --dynamic"' package.json > package.json.tmp
mv package.json.tmp package.json
else
echo " Manually add to package.json scripts:"
echo ' "mock": "prism mock '"$spec_path"' --port 4010 --dynamic"'
fi
fi
echo ""
echo "✓ Prism mock server configured"
echo ""
echo "Start mock server:"
echo " ./mocks/start-prism.sh"
echo " # or"
echo " npm run mock"
echo ""
echo "Mock API will be available at: http://localhost:4010"
else
echo "❌ OpenAPI specification not found: $spec_path"
exit 1
fi
}
generate_msw_mock() {
local spec_type=$1
echo "Setting up MSW (Mock Service Worker)..."
echo ""
# Install MSW
if [ -f "package.json" ]; then
echo "Installing MSW..."
npm install --save-dev msw
else
echo "❌ package.json not found"
echo "Create Node.js project first: npm init -y"
exit 1
fi
# Create mock handlers
mkdir -p mocks/handlers
cat > mocks/handlers/handlers.js << 'EOF'
/**
* MSW Request Handlers
* Define mock API responses here
*/
import { rest } from 'msw';
const baseURL = process.env.API_BASE_URL || 'http://localhost:3000';
export const handlers = [
// Example: GET /api/users
rest.get(`${baseURL}/api/users`, (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{ id: 1, name: 'John Doe', email: 'john@example.com' },
{ id: 2, name: 'Jane Smith', email: 'jane@example.com' }
])
);
}),
// Example: GET /api/users/:id
rest.get(`${baseURL}/api/users/:id`, (req, res, ctx) => {
const { id } = req.params;
return res(
ctx.status(200),
ctx.json({
id: parseInt(id),
name: 'John Doe',
email: 'john@example.com',
createdAt: new Date().toISOString()
})
);
}),
// Example: POST /api/users
rest.post(`${baseURL}/api/users`, async (req, res, ctx) => {
const body = await req.json();
return res(
ctx.status(201),
ctx.json({
id: Date.now(),
...body,
createdAt: new Date().toISOString()
})
);
}),
// Example: Error response
rest.get(`${baseURL}/api/error`, (req, res, ctx) => {
return res(
ctx.status(500),
ctx.json({
error: 'Internal Server Error',
message: 'Something went wrong'
})
);
})
];
EOF
# Create server setup for Node.js
cat > mocks/server.js << 'EOF'
/**
* MSW Server for Node.js (testing)
*/
import { setupServer } from 'msw/node';
import { handlers } from './handlers/handlers.js';
export const server = setupServer(...handlers);
EOF
# Create browser setup
cat > mocks/browser.js << 'EOF'
/**
* MSW Browser Setup
*/
import { setupWorker } from 'msw';
import { handlers } from './handlers/handlers.js';
export const worker = setupWorker(...handlers);
EOF
# Create test setup file
cat > mocks/setup-tests.js << 'EOF'
/**
* Test Setup with MSW
* Import this in your test setup file
*/
import { server } from './server.js';
// Establish API mocking before all tests
beforeAll(() => server.listen());
// Reset handlers after each test
afterEach(() => server.resetHandlers());
// Clean up after all tests
afterAll(() => server.close());
EOF
echo "✓ MSW mock server configured"
echo ""
echo "Setup for Browser:"
echo " 1. npx msw init public/ --save"
echo " 2. Import worker in your app: import { worker } from './mocks/browser.js'"
echo " 3. Start worker: worker.start()"
echo ""
echo "Setup for Tests:"
echo " 1. Import in test setup: import './mocks/setup-tests.js'"
echo " 2. Tests will automatically use mocked responses"
echo ""
echo "Add handlers in: mocks/handlers/handlers.js"
}
generate_json_server_mock() {
local spec_type=$1
echo "Setting up json-server..."
echo ""
# Install json-server
if [ -f "package.json" ]; then
echo "Installing json-server..."
npm install --save-dev json-server
fi
# Generate sample database
cat > mocks/db.json << 'EOF'
{
"users": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com",
"role": "admin",
"createdAt": "2024-01-01T00:00:00.000Z"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com",
"role": "user",
"createdAt": "2024-01-02T00:00:00.000Z"
}
],
"posts": [
{
"id": 1,
"title": "First Post",
"content": "This is the content of the first post",
"userId": 1,
"createdAt": "2024-01-15T00:00:00.000Z"
},
{
"id": 2,
"title": "Second Post",
"content": "Content of the second post",
"userId": 2,
"createdAt": "2024-01-16T00:00:00.000Z"
}
],
"comments": [
{
"id": 1,
"postId": 1,
"userId": 2,
"text": "Great post!",
"createdAt": "2024-01-17T00:00:00.000Z"
}
]
}
EOF
# Create custom routes (optional)
cat > mocks/routes.json << 'EOF'
{
"/api/*": "/$1",
"/users/:id/posts": "/posts?userId=:id",
"/posts/:id/comments": "/comments?postId=:id"
}
EOF
# Create middleware for custom logic
cat > mocks/middleware.js << 'EOF'
/**
* json-server middleware
* Add custom logic like authentication, validation, etc.
*/
module.exports = (req, res, next) => {
// Add custom headers
res.header('X-Mock-Server', 'json-server');
// Log requests
console.log(`${req.method} ${req.url}`);
// Add delay to simulate network latency
if (process.env.MOCK_DELAY) {
setTimeout(next, parseInt(process.env.MOCK_DELAY));
} else {
next();
}
};
EOF
# Create start script
cat > mocks/start-json-server.sh << 'EOF'
#!/bin/bash
# Start json-server mock API
json-server \
--watch mocks/db.json \
--routes mocks/routes.json \
--middlewares mocks/middleware.js \
--port 3001 \
--host 0.0.0.0
# Options:
# --watch: Auto-reload on file changes
# --routes: Custom route mappings
# --middlewares: Custom middleware
# --delay: Add response delay (ms)
EOF
chmod +x mocks/start-json-server.sh
# Add to package.json
if [ -f "package.json" ] && command -v jq &> /dev/null; then
jq '.scripts.mock = "json-server --watch mocks/db.json --routes mocks/routes.json --port 3001"' package.json > package.json.tmp
mv package.json.tmp package.json
fi
echo "✓ json-server mock configured"
echo ""
echo "Start mock server:"
echo " ./mocks/start-json-server.sh"
echo " # or"
echo " npm run mock"
echo ""
echo "Mock API will be available at: http://localhost:3001"
echo ""
echo "Edit mock data: mocks/db.json"
}
generate_wiremock_mock() {
echo "Setting up WireMock..."
echo ""
mkdir -p mocks/wiremock/{mappings,__files}
# Create example mapping
cat > mocks/wiremock/mappings/users.json << 'EOF'
{
"request": {
"method": "GET",
"urlPattern": "/api/users"
},
"response": {
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"jsonBody": [
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com"
}
]
}
}
EOF
# Create start script
cat > mocks/start-wiremock.sh << 'EOF'
#!/bin/bash
# Start WireMock server
# Download WireMock if not exists
if [ ! -f "wiremock-standalone.jar" ]; then
echo "Downloading WireMock..."
curl -o wiremock-standalone.jar \
https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-standalone/2.35.0/wiremock-standalone-2.35.0.jar
fi
# Start WireMock
java -jar wiremock-standalone.jar \
--port 8080 \
--root-dir mocks/wiremock \
--verbose
# Options:
# --port: Server port
# --root-dir: Directory with mappings and files
# --verbose: Detailed logging
# --record-mappings: Record mode
EOF
chmod +x mocks/start-wiremock.sh
echo "✓ WireMock configured"
echo ""
echo "Start mock server:"
echo " ./mocks/start-wiremock.sh"
echo ""
echo "Mock API will be available at: http://localhost:8080"
echo ""
echo "Add mappings in: mocks/wiremock/mappings/"
}
generate_mock_server "$MOCK_TOOL" "$SPEC_TYPE" "$SPEC_PATH"
I'll create realistic mock data for your API:
generate_mock_data() {
echo ""
echo "=== Generating Realistic Mock Data ==="
echo ""
# Create data generators
mkdir -p mocks/data-generators
cat > mocks/data-generators/generate-data.js << 'EOF'
/**
* Mock Data Generator
* Generates realistic test data for API mocks
*/
const faker = require('@faker-js/faker').faker;
function generateUsers(count = 10) {
const users = [];
for (let i = 1; i <= count; i++) {
users.push({
id: i,
name: faker.person.fullName(),
email: faker.internet.email(),
avatar: faker.image.avatar(),
address: {
street: faker.location.streetAddress(),
city: faker.location.city(),
state: faker.location.state(),
zipCode: faker.location.zipCode()
},
phone: faker.phone.number(),
company: faker.company.name(),
role: faker.helpers.arrayElement(['admin', 'user', 'moderator']),
createdAt: faker.date.past().toISOString()
});
}
return users;
}
function generatePosts(count = 20, userIds = []) {
const posts = [];
for (let i = 1; i <= count; i++) {
posts.push({
id: i,
title: faker.lorem.sentence(),
content: faker.lorem.paragraphs(3),
excerpt: faker.lorem.sentence(),
userId: userIds.length > 0
? faker.helpers.arrayElement(userIds)
: faker.number.int({ min: 1, max: 10 }),
tags: faker.helpers.arrayElements(
['javascript', 'python', 'react', 'nodejs', 'testing'],
faker.number.int({ min: 1, max: 3 })
),
published: faker.datatype.boolean(),
createdAt: faker.date.past().toISOString(),
updatedAt: faker.date.recent().toISOString()
});
}
return posts;
}
function generateComments(count = 50, postIds = [], userIds = []) {
const comments = [];
for (let i = 1; i <= count; i++) {
comments.push({
id: i,
postId: postIds.length > 0
? faker.helpers.arrayElement(postIds)
: faker.number.int({ min: 1, max: 20 }),
userId: userIds.length > 0
? faker.helpers.arrayElement(userIds)
: faker.number.int({ min: 1, max: 10 }),
text: faker.lorem.paragraph(),
createdAt: faker.date.recent().toISOString()
});
}
return comments;
}
// Generate complete database
function generateDatabase() {
const users = generateUsers(10);
const userIds = users.map(u => u.id);
const posts = generatePosts(20, userIds);
const postIds = posts.map(p => p.id);
const comments = generateComments(50, postIds, userIds);
return {
users,
posts,
comments
};
}
// Export for use
if (typeof module !== 'undefined' && module.exports) {
module.exports = {
generateUsers,
generatePosts,
generateComments,
generateDatabase
};
}
// CLI usage
if (require.main === module) {
const fs = require('fs');
const db = generateDatabase();
fs.writeFileSync(
'mocks/db.json',
JSON.stringify(db, null, 2)
);
console.log('✓ Mock database generated: mocks/db.json');
console.log(` Users: ${db.users.length}`);
console.log(` Posts: ${db.posts.length}`);
console.log(` Comments: ${db.comments.length}`);
}
EOF
# Install faker if using Node.js
if [ -f "package.json" ]; then
echo "Installing @faker-js/faker for realistic data..."
npm install --save-dev @faker-js/faker
fi
echo "✓ Mock data generator created: mocks/data-generators/generate-data.js"
echo ""
echo "Generate fresh mock data:"
echo " node mocks/data-generators/generate-data.js"
}
# Generate mock data if json-server or similar
if [[ "$MOCK_TOOL" =~ json-server|msw ]]; then
generate_mock_data
fi
I'll create comprehensive documentation for using the mocks:
generate_mock_documentation() {
cat > mocks/README.md << EOF
# API Mock Server
This directory contains mock server configuration for local development and testing.
## Mock Tool: $MOCK_TOOL
EOF
case $MOCK_TOOL in
prism)
cat >> mocks/README.md << 'EOF'
### Prism Mock Server
Prism generates mock responses based on your OpenAPI specification.
**Start Server:**
```bash
./mocks/start-prism.sh
# or
npm run mock
Server URL: http://localhost:4010
Features:
Configuration:
x-* extensions for custom behaviorTesting:
# Example requests
curl http://localhost:4010/api/users
curl http://localhost:4010/api/users/1
curl -X POST http://localhost:4010/api/users \
-H "Content-Type: application/json" \
-d '{"name":"Test User"}'
EOF ;;
msw)
cat >> mocks/README.md << 'EOF'
MSW intercepts requests at the network level for testing.
Browser Setup:
import { worker } from './mocks/browser.js';
// Start worker
worker.start();
Node.js/Test Setup:
import './mocks/setup-tests.js';
// Tests automatically use mocked responses
Features:
Adding Handlers:
Edit mocks/handlers/handlers.js:
rest.get('/api/new-endpoint', (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({ data: 'mock response' })
);
})
Debugging:
Check browser DevTools Network tab
MSW logs requests to console
Use onUnhandledRequest: 'warn' option
EOF
;;
json-server)
cat >> mocks/README.md << 'EOF'
Simple REST API mock from JSON file.
Start Server:
./mocks/start-json-server.sh
# or
npm run mock
Server URL: http://localhost:3001
Features:
Database:
Edit mocks/db.json to change mock data.
Routes:
GET /users - List users
GET /users/1 - Get user by ID
POST /users - Create user
PUT /users/1 - Update user
PATCH /users/1 - Partial update
DELETE /users/1 - Delete user
Query Parameters:
# Filter
GET /users?role=admin
# Sort
GET /users?_sort=name&_order=asc
# Paginate
GET /users?_page=1&_limit=10
# Full-text search
GET /users?q=john
Relationships:
# Get user's posts
GET /users/1/posts
# Embed related data
GET /posts?_embed=comments
# Expand foreign keys
GET /posts?_expand=user
Generate Fresh Data:
node mocks/data-generators/generate-data.js
EOF ;;
wiremock)
cat >> mocks/README.md << 'EOF'
Advanced API simulation with recording and matching.
Start Server:
./mocks/start-wiremock.sh
Server URL: http://localhost:8080
Features:
Adding Mappings:
Create file in mocks/wiremock/mappings/:
{
"request": {
"method": "GET",
"urlPattern": "/api/.*"
},
"response": {
"status": 200,
"jsonBody": {
"message": "mock response"
},
"headers": {
"Content-Type": "application/json"
}
}
}
Recording Mode:
java -jar wiremock-standalone.jar \
--record-mappings \
--proxy-all="http://real-api.com"
EOF ;; esac
cat >> mocks/README.md << 'EOF'
Local Development:
Testing:
Demos:
Environment Variables:
API_BASE_URL=http://localhost:3001
MOCK_DELAY=100 # Add response delay (ms)
Jest:
describe('API Tests', () => {
beforeAll(async () => {
// Start mock server or configure MSW
});
it('fetches users', async () => {
const response = await fetch('http://localhost:3001/users');
const users = await response.json();
expect(users).toHaveLength(10);
});
});
Cypress:
describe('User Page', () => {
beforeEach(() => {
// Use mock server
cy.intercept('GET', '/api/users', {
fixture: 'users.json'
});
});
it('displays users', () => {
cy.visit('/users');
cy.get('.user').should('have.length', 10);
});
});
Server won't start:
Responses not matching:
Performance issues:
Reduce response delay
Limit mock data size
Use appropriate tool for use case EOF
echo "" echo "✓ Documentation created: mocks/README.md" }
generate_mock_documentation
## Mock Server Summary
```bash
echo ""
echo "=== Mock Server Setup Complete ==="
echo ""
cat << EOF
✓ Mock server configured successfully
**Mock Tool:** $MOCK_TOOL
**Specification:** $SPEC_TYPE
$([ -n "$SPEC_PATH" ] && echo "**Spec File:** $SPEC_PATH")
**Generated Files:**
- mocks/ (mock server directory)
EOF
case $MOCK_TOOL in
prism)
echo " - mocks/start-prism.sh (start script)"
;;
msw)
echo " - mocks/handlers/handlers.js (request handlers)"
echo " - mocks/server.js (Node.js setup)"
echo " - mocks/browser.js (browser setup)"
;;
json-server)
echo " - mocks/db.json (mock database)"
echo " - mocks/routes.json (custom routes)"
echo " - mocks/middleware.js (custom middleware)"
echo " - mocks/start-json-server.sh (start script)"
echo " - mocks/data-generators/generate-data.js (data generator)"
;;
wiremock)
echo " - mocks/wiremock/mappings/ (request mappings)"
echo " - mocks/start-wiremock.sh (start script)"
;;
esac
cat << 'EOF'
- mocks/README.md (documentation)
**Next Steps:**
1. Review mock configuration
2. Customize mock responses
3. Start mock server
4. Test endpoints
5. Integrate with application/tests
**Quick Start:**
EOF
case $MOCK_TOOL in
prism|json-server|wiremock)
echo " ./mocks/start-*.sh"
echo " # or"
[ -f "package.json" ] && echo " npm run mock"
;;
msw)
echo " # See mocks/README.md for setup instructions"
;;
esac
cat << 'EOF'
**Documentation:**
See mocks/README.md for detailed usage instructions.
EOF
This skill works well with:
/api-test-generate - Generate tests that use mocks/postman-convert - Convert Postman to tests using mocks/test - Run tests against mock serverMock Server Usage:
Maintenance:
Protection Measures:
Important: I will NEVER:
Issue: Port already in use
Issue: Responses don't match API
Issue: Mock server slow
Credits: