Skip to content
v1
Docs

Node.js SDK

Testing your Node.js integration

@watchtower15/sdk/testing holds fakes for your tests. They hold only placeholder credentials, never sleep, and never reach a host.

import { FakeClient, MockFetch } from '@watchtower15/sdk/testing';
const wt15 = new FakeClient();
wt15.queue('public.servers.list', MockFetch.envelope({ data: [{ uuid: 'u1', name: 'web-1' }], current_page: 1, per_page: 25, last_page: 1, total: 1 }));
await reportCriticalServers(wt15);
wt15.assertCalled('public.servers.list', { times: 1 });
  • FakeClient is a WatchTower15. Ingest pushes are answered with an accepted envelope; any other operation is answered from queue(operationId, answer), else the call throws naming the operation. calls(), assertCalled(operationId, { where, times }), assertNotCalled(), pushedPoints(), pushedLines(), assertPushed() and assertNothingPushed() read what happened.
  • MockFetch is the fetch behind it: append(), and the builders json(), problem(), envelope(), metricsAccepted() and logsAccepted(). Recorded requests keep the Authorization masked and the body decoded.
  • FakeAggregator records increments() and gauges() (assertIncremented(), assertGaugeSet(), assertNothingRecorded()); its flush() is always final, into its FakeClient, so the open minute reaches client.pushedPoints() with no waiting.

A failed assertion throws an Error named AssertionError, which Vitest, Jest and node:test all report. A FakeClient builds under jsdom (Jest’s and Vitest’s jsdom environment), because it holds no real credential. For NestJS, WatchTower15Module.forTesting() from @watchtower15/nestjs/testing binds the fakes under the module’s classes and tokens: see NestJS.