dist/codex/medusa-commerce/skills/medusa-testing/SKILL.md
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.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins medusa-testingInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Fetch live docs:
site:docs.medusajs.com testing for official testing guide and setupsite:docs.medusajs.com medusaIntegrationTestRunner for integration test utilitiessite:docs.medusajs.com unit test module for module unit testing patternshttps://docs.medusajs.com/resources/medusa-testing and review test runner configurationmedusajs v2 jest test workflow 2026 for latest workflow testing patterns ┌─────────┐
│ E2E │ API route tests (slow, high confidence)
├─────────┤
│ Integr. │ Workflow + cross-module tests
├─────────┤
│ Unit │ Module service + utility tests (fast)
└─────────┘
| 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 |
// 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 | 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-utilspackage exports and version compatibility.
// 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
})
| 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 |
| 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.
medusaIntegrationTestRunner provides a full Medusa application container with all modules, test database setup/teardown, API client, and seeded admin user.
// 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
},
})
| 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.
| 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 |
| 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.
| 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 |
| 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 |
| 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 |
| 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.
src/modules/product/__tests__/.spec.ts suffix; group by feature, not test typemedusaIntegrationTestRunner for all cross-module testsafterEach to prevent pollution; seed minimal dataFetch the Medusa v2 testing documentation and @medusajs/test-utils reference for exact runner configuration, mock patterns, and test utility APIs before implementing.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.