/odin-typescript:fastify-inject-testingfrom ODIN TypeScript
Tests Fastify applications without network sockets using inject(). Covers auth, validation errors, uploads, streams, plugins, and hooks with isolated node:test suites.
Ships in ODIN TypeScript. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
| Field | Bound contract |
|---|---|
| Trigger | Testing Fastify applications without network sockets: auth, validation errors, uploads, streams, plugins, hooks. |
| Authority | Reversible local: write only test files under the project test tree and run node:test suites. Roll back by deleting the added test files and reverting test-only config; never mutate application source, credentials, or remote state. |
| Side effect | Writes test files; runs node:test suites. |
| Done | Integration tests exercise routes via inject() with no listener, covering auth, validation failure, and at least one stream/upload path, passing in parallel. |
buildApp() or buildTestApp(options)) that returns a ready FastifyInstance without calling listen(). Required.TEST_DATABASE_URL) or mocked dependency factories for isolation../test/fixtures/test.pdf).Fastify({ logger: false, ...options }), registers the real plugins and routes, calls await app.ready(), and returns { app, inject: app.inject.bind(app) }. Never call app.listen(); inject() simulates HTTP without a network socket.import Fastify from 'fastify';
import type { FastifyInstance } from 'fastify';
export async function buildTestApp(options = {}): Promise<{
app: FastifyInstance;
inject: FastifyInstance['inject'];
}> {
const app = Fastify({ logger: false, ...options });
app.register(import('../src/plugins/database.js'), {
connectionString: process.env.TEST_DATABASE_URL,
});
app.register(import('../src/routes/index.js'));
await app.ready();
return { app, inject: app.inject.bind(app) };
}
Done when: the factory returns { app, inject } without calling listen().
describe block, create a fresh app instance in before and close it in after so suites are isolated and can run in parallel.import { describe, it, before, after } from 'node:test';
let app;
before(async () => { app = await buildApp(); await app.ready(); });
after(async () => { await app.close(); });
Done when: each describe block creates and closes its own app instance.
Exercise routes via app.inject({ method, url, payload, headers, query }) and assert on response.statusCode, response.headers, response.json(), and response.rawPayload. Cover at minimum: an authenticated route, a validation failure, and one stream or upload path. Done when: at minimum an authenticated route, a validation failure, and one stream/upload path are exercised.
Test authentication by injecting without credentials (expect 401) and with an authorization: Bearer <token> header obtained from a login inject call.
const login = await app.inject({ method: 'POST', url: '/auth/login', payload: { email, password } });
const token = login.json().token;
const ok = await app.inject({ method: 'GET', url: '/profile', headers: { authorization: `Bearer ${token}` } });
t.assert.equal(ok.statusCode, 200);
Done when: the 401-without-credentials and 200-with-token cases are asserted.
statusCode === 400 with the field name in body.message.const res = await app.inject({ method: 'POST', url: '/users', payload: { name: 'John', email: 'not-an-email' } });
t.assert.equal(res.statusCode, 400);
t.assert.ok(res.json().message.includes('email'));
Done when: statusCode === 400 is asserted with the field name in body.message.
form-data instance with createReadStream and passing payload: form plus headers: form.getHeaders().import { createReadStream } from 'node:fs';
import FormData from 'form-data';
const form = new FormData();
form.append('file', createReadStream('./test/fixtures/test.pdf'));
const res = await app.inject({ method: 'POST', url: '/upload', payload: form, headers: form.getHeaders() });
t.assert.equal(res.statusCode, 200);
Done when: the form-data upload returns the expected status.
Test streaming responses by injecting the streaming route and asserting statusCode === 200 and response.rawPayload.length > 0. Done when: statusCode === 200 and rawPayload.length > 0 are asserted.
Mock external dependencies with node:test mock.fn() and decorate the app (app.decorate('db', mockDb)) before registering routes, then assert call counts via app.db.users.findAll.mock.calls.length. Done when: mock.fn is used and call counts are asserted.
Test plugins in isolation by registering only the plugin under test on a bare Fastify() instance and asserting decorators (app.hasDecorator('cache')) and behavior directly. Done when: the plugin is registered on a bare instance and decorators/behavior are asserted.
Test hooks by injecting a route and asserting side-effect headers (response.headers['x-request-id']) or captured log lines from a custom logger stream. Done when: side-effect headers or captured log lines are asserted.
For database integration, wrap each test in a transaction begun in beforeEach and rolled back in afterEach so tests stay isolated and parallel-safe.
beforeEach(async () => { transaction = await app.db.beginTransaction(); app.db.setTransaction(transaction); });
afterEach(async () => { await transaction.rollback(); });
Done when: each test begins and rolls back a transaction.
node --test (add --experimental-test-coverage or --watch as needed). Each describe block uses its own app instance so suites pass in parallel. Done when: the suite passes under node --test with suites running in parallel.app.ready() rejects: the factory or a plugin failed to boot. Do not call listen() as a workaround; fix the plugin registration or provide the missing option. Roll back by removing the added test file.describe builds and closes its own app instance; never share a module-level app across suites.A node:test suite that boots Fastify via inject() with no listener, covering authenticated routes, validation failures, and at least one stream or upload path, plus any plugin, hook, mock, or transaction-isolation cases requested. The suite passes under node --test with suites running in parallel. Terminal classification: done when every required path is exercised and green; otherwise a per-path failure report naming the unverified mechanism class.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
fastify-testing, inject-testing, integration-tests, node-test
npx claudepluginhub outlinedriven/odin-claude-plugin --plugin odin-typescript15 skills in this plugin
/eslint-to-biome-migrationUse when migrating a JavaScript or TypeScript project from ESLint, Prettier, Standard, or mixed legacy lint configuration to Biome 2.5./fastify-production-hardeningUse when asked to prepare a Fastify service for production load and exposure. Not for building the app: use fastify-schema-first-service./fastify-schema-first-serviceUse when building or extending a Fastify application: routes, plugins, hooks, database wiring. Not for testing: use fastify-inject-testing. Not for hardening: use fastify-production-hardening./multi-tenant-architectureUse when a request concerns multi-tenant scaffolding, tenant isolation, domain wiring, or SaaS architecture on Cloudflare or Vercel. Not for single-tenant apps: use scaffold-nextjs./node-internals-diagnosisUse when Node.js segfaults, addon crashes, leaks, event-loop anomalies, thread-pool saturation, V8 deoptimizations, or binding.gyp failures need diagnosis. Not for code edits or service restarts./nodejs-graceful-shutdownUse when asked to implement or fix service termination: SIGTERM or SIGINT, connection draining, health-check signaling. Not for general service scaffolding: use nodejs-service-foundations.Other plugins' skills for the same job