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

@bitfinex/bfx-svc-test-helper

v1.1.0

Published

common test functions

Readme

bfx-svc-test-helper

Test helper to help with common day to day testing tasks.

Do you see yourself copy/pasting or doing the same setup code again?

Maybe it's time for a pull request or an issue! bfx-svc-test-helper is open for improvements and suggestions that make our day to day life as a team easier!

Usage in tests

The API supports Promise and callback based APIs. For a common example, see example.js.

You can also stub/mock Grenache services. See example-fauxgrenache.js for an example.

API

createGrapes([opts]) => Grapes

Creates an instance to manage Grapes for testing.

Arguments

  • opts is an object of additional options, there is able to pass:

    • ports is an array of object, for example:
    [{
      dht_port: 20002,
      dht_bootstrap: ['127.0.0.1:20001'],
      api_port: 40001
    }, {
      dht_port: 20001,
      dht_bootstrap: ['127.0.0.1:20002'],
      api_port: 30001
    }]

grapes.start([cb]) => Promise

Creates two "default Grapes" and calls the callback when the found each other.

grapes.onAnnounce([servicename], [cb]) => Promise

Calls the callback as soon as the service is announced on the network. Leave blank to match any announce.

grapes.stop([cb]) => Promise

Stops the Grapes.

createWorker(worker, [grapes]) => Worker

Creates an svc-js worker instance.

worker.start([cb]) => Promise

Starts the worker. If grapes were passed via createWorker, resolves as soon as the service name is announced on the network.

worker.stop([cb]) => Promise

Stops the worker.

createClient(worker) => Client

Sets up a typical PeerClient needed for most use cases. worker can be the name of the worker e.g. rest:util:net, or can be a <Worker> instance from createWorker

client.request(args, [opts], [cb]) => Promise

Makes a request to the configured worker.

client.stop([cb]) => Promise

Stops the client.

createFxGrenache(mocks, grapes|url, [opts]) => FauxGrenacheServer

Spins up Grenache service mocks.

opts.port - the port the server will listen to, defaults to 1557 opts.link - custom / own link, can be used for customised setups

Second parameter is either a Grapes instance or a http url pointing to the Grenache Grape HTTP Server.

fxgrenache.start([cb]) => Promise

Makes a request to the configured mockserver.

fxgrenache.stop([cb]) => Promise

Stops the server.

createServer(mocks, opts) => Server

Sets up a HTTP stub/mock server.

opts.port - the port the server will listen to. opts.debug - print the data sent from the client via post

opts.debug is useful when you are creating new mock definitions, especially if you use an external client library to send the request.

mocks can be a mock definition or an array of mock definitions.

The server can basically match, test and return anything on request/response, sent payloads etc. For convenience, there are shorthands that should suffice in most cases: example-server-simple.js.

For advanced route matching and testing of incoming requests, see example-server-advanced.js

server.start([cb]) => Promise

Makes a request to the configured mockserver.

server.stop([cb]) => Promise

Stops the server.

utils.getApi(worker) => Api

Returns the loc.api instance of the worker

utils.getGrapeApiPort(grapesWorker) => port

Gets the HTTP port of one of the Grape workers

Example:

const createGrapes = require('bfx-svc-test-helper/grapes')
const utils = require('bfx-svc-test-helper/utils')

const grapes = createGrapes()

;(async () => {
  await grapes.start()
  const port = utils.getGrapeApiPort(grapes)
  console.log(port) // 30001
})()