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

hoverfly-ts-decorators

v0.3.0

Published

TypeScript helpers for loading Hoverfly simulations in Mocha tests

Readme

hoverfly-ts-decorators

Early development: This package is in early development. APIs may change and bugs may occur.

TypeScript helpers for loading Hoverfly simulations in Mocha test suites. Provides two simple functions — useSimulation() for suite-level setup and loadSimulation() for per-test control — that manage Hoverfly's simulation state via its admin API so your tests always run against a known, predictable set of mocked HTTP responses.

Installation

npm install hoverfly-ts-decorators

Prerequisites

Hoverfly must be running and accessible before your tests execute. The simplest way is Docker Compose (see Integration tests), but any running Hoverfly instance works.

By default the library connects to localhost:8888 (Hoverfly's admin API). Override this with environment variables or per-call options (see Configuration).

Quick start

Suite-level simulation with useSimulation()

Call useSimulation() inside a describe block to load a simulation once before all tests in that suite.

import { useSimulation } from 'hoverfly-ts-decorators';
import axios from 'axios';
import * as assert from 'assert';

describe('User service', function () {
  useSimulation('./simulations/users.json');

  it('returns all users', async function () {
    const res = await axios.get('http://localhost:8500/users');
    assert.strictEqual(res.status, 200);
    assert.strictEqual(res.data[0].name, 'Alice');
  });
});

Per-test simulation with loadSimulation()

Call loadSimulation() directly inside an it() body when different tests need different simulations.

import { loadSimulation } from 'hoverfly-ts-decorators';
import axios from 'axios';
import * as assert from 'assert';

describe('Product service', function () {
  it('returns products', async function () {
    await loadSimulation('./simulations/products.json');
    const res = await axios.get('http://localhost:8500/products');
    assert.strictEqual(res.data[0].name, 'Widget');
  });

  it('returns users after switching simulation', async function () {
    await loadSimulation('./simulations/users.json');
    const res = await axios.get('http://localhost:8500/users');
    assert.strictEqual(res.data[0].name, 'Alice');
  });
});

Appending simulations

Pass { append: true } to add pairs to the existing simulation without clearing it first.

await loadSimulation('./simulations/users.json');
await loadSimulation('./simulations/products.json', { append: true });
// Both /users and /products now respond correctly

API reference

useSimulation(filePath, options?)

Registers a Mocha before() hook in the enclosing describe block. The hook clears all Hoverfly simulations and loads the specified file before any test in the suite runs.

| Parameter | Type | Description | |---|---|---| | filePath | string | Path to the simulation JSON file. Relative paths are resolved against process.cwd(). | | options | SimulationOptions | Optional. See below. |

loadSimulation(filePath, options?)

Async function that clears and loads a simulation. Call directly inside it() for per-test control.

| Parameter | Type | Description | |---|---|---| | filePath | string | Path to the simulation JSON file. Relative paths are resolved against process.cwd(). | | options | SimulationOptions | Optional. See below. |

SimulationOptions

| Option | Type | Default | Description | |---|---|---|---| | host | string | HOVERFLY_HOST env var or 'localhost' | Hoverfly admin API host | | port | number | HOVERFLY_PORT env var or 8888 | Hoverfly admin API port | | authToken | string | HOVERFLY_AUTH_TOKEN env var | Bearer token for authenticated Hoverfly instances | | append | boolean | false | When true, POSTs to append pairs instead of clearing and replacing |

HoverflyClient

Lower-level class for direct admin API access.

import { createClient } from 'hoverfly-ts-decorators';

const client = createClient({ host: 'localhost', port: 8888 });
await client.clearSimulations();
await client.loadSimulation('./simulations/users.json');

Configuration

The library reads three environment variables as defaults. Any value passed in SimulationOptions takes precedence.

| Variable | Default | Description | |---|---|---| | HOVERFLY_HOST | localhost | Admin API hostname | | HOVERFLY_PORT | 8888 | Admin API port | | HOVERFLY_AUTH_TOKEN | (none) | Bearer token for authenticated instances |