Tooling
Testing
createTestClient and createTestCluster from white-js/test.
import test from 'node:test';
import assert from 'node:assert/strict';
import { createTestClient } from 'white-js/test';
test('status', async () => {
const client = await createTestClient(); // runs on a free port, logging off
const res = await client.get('/api/status');
assert.equal(res.status, 200);
assert.equal(res.json.ok, true);
await client.close();
});get, post, put, patch and delete take { json, form, body, headers } and return { status, headers, text, json, location }. Redirects are not followed, so you can assert on them, and cookies are kept between calls.
To test services that call each other, start them together in one process. Links are two-way and get random secrets:
import { createTestCluster } from 'white-js/test';
const cluster = await createTestCluster({
web: { config: { dirs: { routes: 'test/web/routes' } }, peers: ['billing'] },
billing: { config: { dirs: { routes: 'test/billing/routes' } } },
});
const res = await cluster.services.web.get('/invoices'); // goes through the real mesh
await cluster.close();Run the library's own tests with npm test.