createTestApp(options?: TestAppOptions): Promise<IKernelApplication>
Creates a started test application that can be exercised via inject()
and fetch() without binding a socket.
Two arms. Pass plugins to assemble one by hand, or pass app to build from
the project's own composition root and subtract from it — the latter is what
keeps a test app's composition honest, since anything the root registers
(error handling included) is present in the test too.
Example 1
Example 1
// Hand-assembled: unit scope. import { createTestApp } from '@setu-ts/testing'; import { RuntimePlugin } from '@setu-ts/runtime'; const app = await createTestApp({ plugins: [RuntimePlugin()] }); app.router.get('/users', (ctx) => ctx.response.json([{ id: 1 }])); const res = await app.inject({ method: 'GET', url: '/users' }); console.log(res.statusCode); // 200
Example 2
Example 2
// Composition root: the real app, minus the database, plus a fake mailer. import { createTestApp, overrideCapability } from '@setu-ts/testing'; import { CAPABILITIES } from '@setu-ts/common'; import { createApp } from '../setu.config.ts'; const app = await createTestApp({ app: createApp(), without: ['database'], overrides: [overrideCapability(CAPABILITIES.MAIL, fakeMailer)], });
optional
options: TestAppOptions
Test application options
Promise<IKernelApplication>
A started (or un-started) kernel application