Installation
Install the package
Section titled “Install the package”Install the mock as a dev dependency — it is a testing tool and should not ship in your production bundle.
pnpm add -D @labdigital/commercetools-mocknpm install --save-dev @labdigital/commercetools-mockyarn add --dev @labdigital/commercetools-mockPeer dependencies
Section titled “Peer dependencies”The package declares two peer dependencies that you install alongside it:
| Package | Version | Why |
|---|---|---|
msw | ^2.14.6 | Intercepts the HTTP requests your code makes. |
@commercetools/platform-sdk | >= 8.25.0 | Provides the resource type definitions the mock is typed against. |
pnpm add -D msw @commercetools/platform-sdknpm install --save-dev msw @commercetools/platform-sdkyarn add --dev msw @commercetools/platform-sdkRequirements
Section titled “Requirements”- Node.js ≥ 22. The library is published as ESM (
"type": "module") and uses modern Node APIs (the optional SQLite backend relies on the built-innode:sqlitemodule). - A test runner such as Vitest or Jest — the examples in these docs use Vitest.
Entry points
Section titled “Entry points”The package exposes two entry points:
// Main entry — the mock, storage and helpersimport { CommercetoolsMock } from '@labdigital/commercetools-mock'
// Optional SQLite storage backendimport { SQLiteStorage } from '@labdigital/commercetools-mock/sqlite'Next: build a working test in the Quick start.