Skip to content

In-memory storage

InMemoryStorage is the default backend. It keeps all resources in plain JavaScript data structures in the current process.

import { CommercetoolsMock, InMemoryStorage } from '@labdigital/commercetools-mock'
const ctMock = new CommercetoolsMock({
defaultProjectKey: 'my-project',
storage: new InMemoryStorage(), // optional — this is the default
})
  • Fast — no I/O, everything is in RAM.
  • Isolated — state lives in the process and disappears when it exits.
  • Reset with clear() — call ctMock.clear() (typically in afterEach) to wipe all data between tests.

This is the right choice for essentially all testing. Reach for SQLite only if you specifically need persistence or want to work with larger datasets in the standalone server.

afterEach(async () => {
mswServer.resetHandlers()
await ctMock.clear()
})

clear() is async — always await it.