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 });FakeClientis aWatchTower15. Ingest pushes are answered with an accepted envelope; any other operation is answered fromqueue(operationId, answer), else the call throws naming the operation.calls(),assertCalled(operationId, { where, times }),assertNotCalled(),pushedPoints(),pushedLines(),assertPushed()andassertNothingPushed()read what happened.MockFetchis thefetchbehind it:append(), and the buildersjson(),problem(),envelope(),metricsAccepted()andlogsAccepted(). Recorded requests keep theAuthorizationmasked and the body decoded.FakeAggregatorrecordsincrements()andgauges()(assertIncremented(),assertGaugeSet(),assertNothingRecorded()); itsflush()is always final, into itsFakeClient, so the open minute reachesclient.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.