Testing applications
Test through the installed npm package and its public entry points, not
src/ or unpublished deep paths. Use the TypeScript setup
with strict checking and an ESM-aware test runner.
Pipeline test
import assert from 'node:assert/strict';
import {
MiddlewarePipeline,
createGenericContext,
type GenericContext,
} from '@tagna/udiot';
const pipeline = new MiddlewarePipeline<GenericContext>();
pipeline.use(async (context, next) => {
context.result = context.data.value * 2;
await next();
});
const result = await pipeline.execute(createGenericContext({ value: 21 }));
assert.equal(result.success, true);
assert.equal(result.result, 42);
Assert failures through the pipeline result envelope as well as thrown exceptions where appropriate. Verify short-circuiting, ordering and middleware side effects.
Isolation and integration
HTTP client and scenarios
createUdiotTestClient({ app }) from the root entry binds an Express app to
an ephemeral loopback port. It exercises the real middleware/controller path.
Always close the client in finally or your test runner's cleanup hook.
import assert from 'node:assert/strict';
import express from 'express';
import { createUdiotTestClient, scenario } from '@tagna/udiot';
const app = express();
app.get('/status', (_request, response) => response.json({ ready: true }));
const client = await createUdiotTestClient({ app });
try {
const result = await scenario('service status').get('/status').expect(200).run(client);
assert.deepEqual(result.steps[0].body, { ready: true });
} finally {
await client.close();
}
The current source client keeps cookies by default. getCookies() inspects them,
clearCookies() resets them and cookies: false disables the jar. Explicit
cookie headers take precedence. Responses expose the original redirect status;
follow Location explicitly when required. The jar is a simple name/value
store, not a complete browser cookie-policy simulator. Use this test client
only against trusted application endpoints: headers and cookies are not an
authorization or origin-isolation boundary.
These cookie/redirect corrections are present in the reviewed local source; the existing published RC's declarations do not expose the cookie helpers. Use the installed declarations to check your exact archive before relying on them. See source and release evidence.
Use scenario capture() to save values into ctx.values for later path/body
functions. Numeric expect() asserts HTTP status. See the complete
server composition recipe.
Integration boundaries
- Construct a fresh DI container/store for each test, and explicitly dispose application-owned resources/subscriptions.
- Test Express/controller routes over HTTP, including malformed bodies, missing authentication, forbidden tenant access, status codes and response headers.
- Test each selected database/queue/cache adapter against its real service; mocks alone do not establish transaction or distributed-cache behavior.
- Exercise browser bundles in actual browsers, including mount/unmount, subscriptions, storage and network failures.
- Test packaged imports and declarations against the exact version you deploy.
There is no public /ssr mock context, root EventBus class or
getTypeRegistry helper. Follow the event bus and
server APIs instead of development-only examples.
Framework documentation tests
Contributors run npm run build, npm run api:check, then npm run test:docs.
The documentation check covers local file links, public imports and the complete
examples marked typescript check. Other snippets may need application
fixtures or external services; passing this check is not proof that every
integration has been executed.