medusa-testing

Test Medusa v2 applications — Jest setup, module unit tests, workflow integration tests, API route tests, medusaIntegrationTestRunner, and mock patterns. Use when writing tests for Medusa projects.

17 stars

Best use case

medusa-testing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Test Medusa v2 applications — Jest setup, module unit tests, workflow integration tests, API route tests, medusaIntegrationTestRunner, and mock patterns. Use when writing tests for Medusa projects.

Teams using medusa-testing should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/medusa-testing/SKILL.md --create-dirs "https://raw.githubusercontent.com/OrcaQubits/agentic-commerce-skills-plugins/main/dist/antigravity/medusa-commerce/.agent/skills/medusa-testing/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/medusa-testing/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How medusa-testing Compares

Feature / Agentmedusa-testingStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Test Medusa v2 applications — Jest setup, module unit tests, workflow integration tests, API route tests, medusaIntegrationTestRunner, and mock patterns. Use when writing tests for Medusa projects.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Medusa v2 Testing

## Before writing code

**Fetch live docs**:
1. Web-search `site:docs.medusajs.com testing` for official testing guide and setup
2. Web-search `site:docs.medusajs.com medusaIntegrationTestRunner` for integration test utilities
3. Web-search `site:docs.medusajs.com unit test module` for module unit testing patterns
4. Fetch `https://docs.medusajs.com/resources/medusa-testing` and review test runner configuration
5. Web-search `medusajs v2 jest test workflow 2026` for latest workflow testing patterns

## Test Architecture

### Test Pyramid

```
        ┌─────────┐
        │  E2E    │  API route tests (slow, high confidence)
        ├─────────┤
        │ Integr. │  Workflow + cross-module tests
        ├─────────┤
        │  Unit   │  Module service + utility tests (fast)
        └─────────┘
```

### Test Types

| Type | Scope | Runner | Speed |
|------|-------|--------|-------|
| Unit | Single module service | Jest | Fast |
| Integration | Workflows, cross-module | `medusaIntegrationTestRunner` | Medium |
| API Route | HTTP endpoints | `medusaIntegrationTestRunner` + supertest | Slow |
| E2E | Full user flows | Playwright/Cypress (optional) | Slowest |

## Jest Setup

```ts
// Skeleton: jest.config.ts for Medusa v2
// Fetch live docs for current recommended config
module.exports = {
  preset: "ts-jest",
  testEnvironment: "node",
  // Fetch live docs for moduleNameMapper and transform
}
```

### Package Dependencies

| Package | Purpose |
|---------|---------|
| `jest` | Test runner |
| `ts-jest` | TypeScript support |
| `@medusajs/test-utils` | Medusa test utilities |
| `supertest` | HTTP assertion library |

> **Fetch live docs** for the current `@medusajs/test-utils` package exports and version compatibility.

## Module Unit Tests

```ts
// Skeleton: module unit test
// Fetch live docs for module test setup
describe("ProductModuleService", () => {
  let service: IProductModuleService
  // Fetch live docs for beforeAll setup with test database
})
```

### Service Method Testing

| Test Target | What to Verify |
|-------------|----------------|
| `createProducts` | Returns product with correct fields |
| `listProducts` | Filters, pagination, sorting work |
| `retrieveProduct` | Relations loaded correctly |
| `updateProducts` | Partial updates applied |
| `deleteProducts` | Cascade behavior correct |

### Setup and Teardown

| Hook | Purpose |
|------|---------|
| `beforeAll` | Initialize module with test database |
| `beforeEach` | Seed test data |
| `afterEach` | Clean up created records |
| `afterAll` | Close database connection |

> **Fetch live docs** for test database initialization and module container setup.

## Integration Tests with medusaIntegrationTestRunner

`medusaIntegrationTestRunner` provides a full Medusa application container with all modules, test database setup/teardown, API client, and seeded admin user.

```ts
// Skeleton: integration test — Fetch live docs for config
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"

medusaIntegrationTestRunner({
  testSuite: ({ api, getContainer }) => {
    // Fetch live docs for api and container usage
  },
})
```

### Runner Context

| Property | Description |
|----------|-------------|
| `api` | Pre-configured HTTP client (AxiosInstance) |
| `getContainer` | Returns the DI container for resolving services |
| `dbConnection` | Database connection reference |
| `modulesConfig` | Override module configurations (runner option) |

> **Fetch live docs** for the full context object shape and available helper methods.

## Workflow Tests

### What to Test

| Aspect | Verification |
|--------|-------------|
| Success path | Workflow completes, returns expected result |
| Side effects | Linked modules updated (pricing, inventory) |
| Compensation | Failed step triggers rollback of previous steps |
| Input validation | Invalid inputs produce expected errors |
| Idempotency | Repeated execution does not create duplicates |

### Compensation Testing

| Strategy | Description |
|----------|-------------|
| Force step failure | Mock a step to throw an error |
| Verify rollback | Check that previous steps are compensated |
| Check data state | Ensure database is clean after rollback |

> **Fetch live docs** for workflow step mocking and compensation test patterns.

## API Route Tests

### Route Test Checklist

| Check | Description |
|-------|-------------|
| Status code | Correct HTTP status for success and error |
| Response body | Expected fields present with correct types |
| Side effects | Database state updated correctly |
| Authentication | Unauthenticated requests rejected |
| Validation | Invalid inputs return 400 with errors |
| Pagination | List endpoints paginate correctly |

### Authentication in Tests

| Actor | Header | Source |
|-------|--------|--------|
| Admin | `Authorization: Bearer <jwt>` | Login via `/auth/user/emailpass` |
| Customer | `Authorization: Bearer <jwt>` | Login via `/auth/customer/emailpass` |
| Store API | `x-publishable-api-key` | Created in test setup |

## Mock Patterns

| Pattern | When to Use |
|---------|-------------|
| Full module mock | Unit testing code that depends on a module |
| Service method stub | Override specific method behavior |
| Test database | Integration tests with real data |

### Common Mocks

| Mock Target | Purpose |
|-------------|---------|
| Payment provider | Avoid real payment calls in tests |
| Fulfillment provider | Avoid real shipping API calls |
| Email service | Capture sent emails for assertion |
| Event bus | Capture emitted events for assertion |

> **Fetch live docs** for recommended mock patterns and test utility helpers.

## Best Practices

### Test Organization
- Co-locate tests with source: `src/modules/product/__tests__/`
- Name test files with `.spec.ts` suffix; group by feature, not test type
- Use factory functions to generate test data — avoid hardcoded fixtures

### Test Data and Integration
- Use `medusaIntegrationTestRunner` for all cross-module tests
- Always test compensation (rollback) paths for critical workflows
- Clean up in `afterEach` to prevent pollution; seed minimal data

### CI/CD and Coverage
- Run unit tests on every commit, integration tests on PR; target 80% coverage
- Use a dedicated test database — never test against production

Fetch the Medusa v2 testing documentation and `@medusajs/test-utils` reference for exact runner configuration, mock patterns, and test utility APIs before implementing.

Related Skills

woo-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test WooCommerce extensions — PHPUnit unit/integration tests, WP test suite, WooCommerce test helpers, E2E with Playwright, and WP-CLI test scaffolding. Use when writing tests for WooCommerce plugins or setting up a test environment.

webmcp-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test WebMCP tools with AI agents — Chrome DevTools integration, agent testing workflows, tool discovery verification, and end-to-end commerce flow testing. Use when validating that tools work correctly with real AI agents.

spree-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test Spree applications and extensions with RSpec — `spree_dev_tools` gem (v5.2+) for factories and helpers, FactoryBot patterns (prefer `build` over `create`), Capybara feature specs, controller/request specs, testing decorators and subscribers, dummy app for extension testing, system specs for the Hotwire admin, and CI patterns. Use when writing Spree tests, setting up CI, or refactoring slow specs.

shopify-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test Shopify applications — app testing with Vitest and Playwright, theme testing with Theme Check, Function testing, webhook testing, extension testing, and CI/CD pipelines. Use when writing tests for Shopify projects.

sf-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test Salesforce Commerce code — B2C (Node.js unit testing, sfcc-ci CI/CD, sandbox management, linting) and B2B (Apex test classes with 75% coverage minimum, Jest for LWC, sf CLI deployment and validation). Use when writing tests or setting up CI/CD.

saleor-testing

17
from OrcaQubits/agentic-commerce-skills-plugins

Test Saleor applications — pytest setup, Django test client, GraphQL test patterns, App testing, factory_boy fixtures, and webhook testing. Use when writing tests for Saleor projects.

medusa-workflows

17
from OrcaQubits/agentic-commerce-skills-plugins

Build Medusa v2 workflows — steps with createStep, compensation/rollback, parallel execution, hooks for extending built-in workflows, and when conditions. Use when orchestrating multi-step operations.

medusa-subscribers

17
from OrcaQubits/agentic-commerce-skills-plugins

Implement Medusa v2 event subscribers — pub/sub event handling, subscriber handler functions, scheduled jobs with cron, and the event module (Redis or in-memory). Use when reacting to commerce events.

medusa-storefront

17
from OrcaQubits/agentic-commerce-skills-plugins

Build Medusa v2 storefronts with Next.js 15 — App Router, JS SDK client setup, Tanstack Query, server components, product pages, cart, and checkout flow. Use when developing headless storefronts.

medusa-setup

17
from OrcaQubits/agentic-commerce-skills-plugins

Set up a Medusa v2 development environment — CLI, PostgreSQL/Redis prerequisites, project creation, medusa-config.ts, directory structure, environment variables. Use when starting a new Medusa project.

medusa-security

17
from OrcaQubits/agentic-commerce-skills-plugins

Secure Medusa v2 applications — authentication strategies, API key types (publishable vs secret), CORS configuration, JWT and cookie secrets, admin vs store auth, and session management. Use when configuring security.

medusa-pricing

17
from OrcaQubits/agentic-commerce-skills-plugins

Configure Medusa v2 pricing — pricing module, price lists with rules, currencies, tax calculation, regions, and promotion campaigns. Use when setting up pricing and discounts.