{"_id":"@bitfinex/bfx-svc-test-helper","name":"@bitfinex/bfx-svc-test-helper","dist-tags":{"latest":"1.1.0"},"versions":{"1.1.0":{"name":"@bitfinex/bfx-svc-test-helper","version":"1.1.0","description":"common test functions","main":"index.js","scripts":{"test":"standard","start":"node server.js"},"repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-svc-test-helper.git"},"author":{"name":"Robert","email":"robert@bitfinex.com"},"license":"Apache-2.0","devDependencies":{"node-fetch":"^2.6.9","standard":"^17.0.0"},"dependencies":{"@bitfinex/bfx-svc-boot-js":"git+https://github.com/bitfinexcom/bfx-svc-boot-js.git","async":"3.2.6","grenache-grape":"1.0.0","grenache-nodejs-http":"1.0.1","grenache-nodejs-link":"1.0.2","raw-body":"2.5.2"},"_id":"@bitfinex/bfx-svc-test-helper@1.1.0","gitHead":"ccf66f123333e9969c0a28e75402d2a5174e22ee","bugs":{"url":"https://github.com/bitfinexcom/bfx-svc-test-helper/issues"},"homepage":"https://github.com/bitfinexcom/bfx-svc-test-helper#readme","_nodeVersion":"18.20.4","_npmVersion":"10.7.0","dist":{"integrity":"sha512-AJDhsQ9I3iKktdlxh5RjKfn4hvpeLoOYoQBciw7TJlu4PfBGLyeS2131tDRGRpMO5zg2B76Txzz1vdFpmQqjdQ==","shasum":"be12b3a2dea759491f37ef885fc44efb04999fb8","tarball":"https://registry.npmjs.org/@bitfinex/bfx-svc-test-helper/-/bfx-svc-test-helper-1.1.0.tgz","fileCount":13,"unpackedSize":20477,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIAs32085a00uQoREgNCCOXv+jJ8W4sk7gKI3f2j+G+c4AiEA5QUrfA7RZkPKBnScvfdJStUYO1rhfvwkeS5B7S9o6YA="}]},"_npmUser":{"name":"vigan-abd","email":"vigan.abd@gmail.com"},"directories":{},"maintainers":[{"name":"vigan-abd","email":"vigan.abd@gmail.com"},{"name":"bitfinexorg","email":"paolo@bitfinex.com"},{"name":"prdn","email":"paolo.ardoino@gmail.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bfx-svc-test-helper_1.1.0_1769788778656_0.6579178200120348"},"_hasShrinkwrap":false}},"time":{"created":"2026-01-30T15:59:38.594Z","1.1.0":"2026-01-30T15:59:38.804Z","modified":"2026-01-30T15:59:38.996Z"},"maintainers":[{"name":"vigan-abd","email":"vigan.abd@gmail.com"},{"name":"bitfinexorg","email":"paolo@bitfinex.com"},{"name":"prdn","email":"paolo.ardoino@gmail.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"}],"description":"common test functions","homepage":"https://github.com/bitfinexcom/bfx-svc-test-helper#readme","repository":{"type":"git","url":"git+https://github.com/bitfinexcom/bfx-svc-test-helper.git"},"author":{"name":"Robert","email":"robert@bitfinex.com"},"bugs":{"url":"https://github.com/bitfinexcom/bfx-svc-test-helper/issues"},"license":"Apache-2.0","readme":"# bfx-svc-test-helper\n\nTest helper to help with common day to day testing tasks.\n\n## Do you see yourself copy/pasting or doing the same setup code again?\n\nMaybe it's time for a pull request or an issue! `bfx-svc-test-helper` is open\nfor improvements and suggestions that make our day to day life as a team easier!\n\n## Usage in tests\n\nThe API supports Promise and callback based APIs. For a common example,\nsee [example.js](example.js).\n\nYou can also stub/mock Grenache services. See\n[example-fauxgrenache.js](example-fauxgrenache.js) for an example.\n\n## API\n\n### `createGrapes([opts]) => Grapes`\n\nCreates an instance to manage Grapes for testing.\n\n### Arguments\n\n- `opts` is an object of additional options, there is able to pass:\n  - `ports` is an array of object, for example:\n\n  ```js\n  [{\n    dht_port: 20002,\n    dht_bootstrap: ['127.0.0.1:20001'],\n    api_port: 40001\n  }, {\n    dht_port: 20001,\n    dht_bootstrap: ['127.0.0.1:20002'],\n    api_port: 30001\n  }]\n  ```\n\n### `grapes.start([cb]) => Promise`\n\nCreates two \"default Grapes\" and calls the callback when the found each other.\n\n### `grapes.onAnnounce([servicename], [cb]) => Promise`\n\nCalls the callback as soon as the service is announced on the network.\nLeave blank to match any announce.\n\n### `grapes.stop([cb]) => Promise`\n\nStops the Grapes.\n\n### `createWorker(worker, [grapes]) => Worker`\n\nCreates an svc-js worker instance.\n\n### `worker.start([cb]) => Promise`\n\nStarts the worker. If `grapes` were passed via `createWorker`, resolves as\nsoon as the service name is announced on the network.\n\n### `worker.stop([cb]) => Promise`\n\nStops the worker.\n\n### `createClient(worker) => Client`\n\nSets up a typical PeerClient needed for most use cases.\n`worker` can be the name of the worker e.g. `rest:util:net`, or can be a\n`<Worker>` instance from `createWorker`\n\n### `client.request(args, [opts], [cb]) => Promise`\n\nMakes a request to the configured worker.\n\n### `client.stop([cb]) => Promise`\n\nStops the client.\n\n### `createFxGrenache(mocks, grapes|url, [opts]) => FauxGrenacheServer`\n\nSpins up Grenache service mocks.\n\n  `opts.port` - the port the server will listen to, defaults to `1557`\n  `opts.link` - custom / own link, can be used for customised setups\n\nSecond parameter is either a `Grapes` instance or a http url pointing\nto the Grenache Grape HTTP Server.\n\n### `fxgrenache.start([cb]) => Promise`\n\nMakes a request to the configured mockserver.\n\n### `fxgrenache.stop([cb]) => Promise`\n\nStops the server.\n\n### `createServer(mocks, opts) => Server`\n\nSets up a HTTP stub/mock server.\n\n  `opts.port` - the port the server will listen to.\n  `opts.debug` - print the data sent from the client via post\n\n`opts.debug` is useful when you are creating new mock definitions, especially\nif you use an external client library to send the request.\n\n`mocks` can be a mock definition or an array of mock definitions.\n\nThe server can basically match, test and return anything on request/response,\nsent payloads etc. For convenience, there are shorthands that should suffice\nin most cases: [example-server-simple.js](example-server-simple.js).\n\nFor advanced route matching and testing of incoming requests, see [example-server-advanced.js](example-server-advanced.js)\n\n### `server.start([cb]) => Promise`\n\nMakes a request to the configured mockserver.\n\n### `server.stop([cb]) => Promise`\n\nStops the server.\n\n### `utils.getApi(worker) => Api`\n\nReturns the loc.api instance of the worker\n\n### `utils.getGrapeApiPort(grapesWorker) => port`\n\nGets the HTTP port of one of the Grape workers\n\nExample:\n\n```js\nconst createGrapes = require('bfx-svc-test-helper/grapes')\nconst utils = require('bfx-svc-test-helper/utils')\n\nconst grapes = createGrapes()\n\n;(async () => {\n  await grapes.start()\n  const port = utils.getGrapeApiPort(grapes)\n  console.log(port) // 30001\n})()\n```\n","readmeFilename":"README.md","_rev":"1-cb8e0a657e3604738f98a58002d8c37c"}