npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@dever-labs/mockly-testcontainers

v0.13.1

Published

Testcontainers module for Mockly — run Mockly as a Docker container in tests

Readme

@dever-labs/mockly-testcontainers

Run Mockly in Docker-backed Node.js and TypeScript tests with testcontainers.

The package starts ghcr.io/dever-labs/mockly:latest, waits for the management API to be ready, and exposes helper methods for mocks, scenarios, faults, calls, state, and logs.

Requirements

  • Node 18+
  • Docker
  • testcontainers 10+

Install

npm i -D @dever-labs/mockly-testcontainers testcontainers

Quickstart

import assert from 'node:assert/strict'
import { MocklyContainerBuilder } from '@dever-labs/mockly-testcontainers'

const container = await new MocklyContainerBuilder().start()

try {
  await container.addMock({
    id: 'get-user',
    request: { method: 'GET', path: '/users/1' },
    response: { status: 200, body: '{"id":1}' },
  })

  const response = await fetch(`${container.getHttpBase()}/users/1`)
  assert.equal(response.status, 200)
  assert.equal(await response.text(), '{"id":1}')
} finally {
  await container.stop()
}

When to use the testcontainers module

Use @dever-labs/mockly-testcontainers when you want Docker-managed lifecycle, no native binary download, or a consistent Mockly environment across laptops and CI.

Use @dever-labs/mockly-driver when you want to run the Mockly binary directly in the test process instead.

Builder API

MocklyContainerBuilder configures the container before startup.

| Method | Description | |---|---| | new MocklyContainerBuilder() | Create a builder with the default image and default config. | | withImage(image) | Override the Docker image. | | withInlineConfig(yaml) | Replace /config/mockly.yaml with inline YAML. | | withOptions(options) | Generate /config/mockly.yaml from typed options such as scenarios. | | start() | Start the container and return a StartedMocklyContainer. |

Custom YAML config

const container = await new MocklyContainerBuilder()
  .withInlineConfig(`mockly:
  api:
    port: 9091
protocols:
  http:
    enabled: true
    port: 8090
`)
  .start()

Typed startup options

const container = await new MocklyContainerBuilder()
  .withOptions({
    scenarios: [
      {
        id: 'payments-down',
        name: 'Payments down',
        patches: [{ mock_id: 'charge', status: 503 }],
      },
    ],
  })
  .start()

Started container API

| Method | Description | |---|---| | getHttpBase() | Base URL of the mock HTTP server. | | getApiBase() | Base URL of the management API. | | stop() | Stop and remove the container. | | addMock(mock) | Register a dynamic HTTP mock. | | listMocks() | List configured HTTP mocks. | | updateMock(id, mock) | Replace a mock and return the updated value. | | patchMock(id, patch) | Patch a mock response and return the updated value. | | deleteMock(id) | Delete a mock by ID. | | getState() | Read the state map. | | setState(kvMap) | Merge/replace state and return the updated map. | | deleteState(key) | Delete a single state key. | | reset() | Remove dynamic mocks, deactivate scenarios, and clear faults. | | listScenarios() | List configured scenarios. | | createScenario(scenario) | Create a scenario. | | getScenario(id) | Read a scenario by ID. | | updateScenario(id, scenario) | Replace a scenario and return the updated value. | | deleteScenario(id) | Delete a scenario. | | listActiveScenarios() | Read active scenario state. | | activateScenario(id) | Activate a configured scenario. | | deactivateScenario(id) | Deactivate a configured scenario. | | setFault(config) | Apply a global HTTP fault. | | clearFault() | Remove the active fault. | | getLogs(matchedId?) | Read parsed request logs. | | getLogsCount(matchedId?) | Count request logs. | | clearLogs() | Clear stored request logs. | | getCalls(mockId) | Read recorded calls for one mock. | | clearCalls(mockId) | Clear recorded calls for one mock. | | clearAllCalls() | Clear recorded calls for all mocks. | | waitForCalls(mockId, count?, timeout?) | Wait for recorded calls on one mock. |

Exported types

The package also exports these TypeScript types:

  • ActiveScenariosResponse
  • CallEntry
  • CallSummary
  • FaultConfig
  • HttpMock
  • MockRequest
  • MockResponse
  • MockResponsePatch
  • MocklyServerOptions
  • Scenario
  • ScenarioPatch