Setu-TS
    Preparing search index...

    Function createTestApp

    • 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.

      Parameters

      Returns Promise<IKernelApplication>

      A started (or un-started) kernel application

      // 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
      // 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)],
      });
      // Adding global middleware requires autoStart: false:
      const app = await createTestApp({
      plugins: [RuntimePlugin()],
      autoStart: false,
      });

      app.middleware.add(async (ctx, next) => { /* ... */ await next(); });
      await app.start();

      If without names a plugin the supplied app does not hold

      0.1.0