Skip to content

@ogygia/core · API

@ogygia/core/plugin/testing

Run a plugin's server half in a unit test without a server. startPlugin, inRequest and the route config helpers.

On this page

This page is generated from the package’s own .d.ts files on every build, so the signatures, descriptions and examples below always match the source. ogygia/plugin/testing re-exports the same module. Plugin tests shows it in use.

Exports clear_route_config · inRequest · route_config · set_page_route_config · startPlugin · StartedPlugin

import { … } from '@ogygia/core/plugin/testing';

clear_route_config

function

Tests only.

function clear_route_config(): void;

inRequest

function

Runs fn inside a request, as Kit runs a hook or an endpoint: Kit's request store carries event through every await of it, so app.keepAlive finds its platform (a waitUntil at platform.context or platform.ctx).

function inRequest<T>(event: Partial<RequestEvent>, fn: () => T): T;

route_config

function

This request's value for key in its route's merged config, or undefined (use the plugin's default). A null routeId is never normalized to / — that would be a different route.

function route_config(key: string, route_id: string | null | undefined, pathname: string): unknown;

set_page_route_config

function

Core only (hooks.ts): the Kit pages' merged config, baked by the compiler.

function set_page_route_config(pages: Record<string, RouteConfig>): void;

startPlugin

function

Starts a plugin's server realm without a server, for unit tests: its app made, its shared hooks registered, its setup run (what the handle does at boot), and a request context to call its hooks with. The app signs with a real HMAC under a key made for this process, with ogygia's default hole lifetime (ttl an hour, maxPageAge eight days), and refuses a capability with the handle's 403.

const { app, ctx } = startPlugin(server, { name: '@ogygia/flags' });
await server.request?.(ctx(new Request('http://x/')));
function startPlugin<Options = undefined, State = undefined>(server: ServerPlugin<Options, State>, { name, options }?: {
  name?: string;
  options?: Options;
}): StartedPlugin<Options, State>;

StartedPlugin

interface

StartedPlugin.app

StartedPlugin.ctx

A request context for request (a bare event: url, request, cookies that read nothing).

interface StartedPlugin<Options, State> {/*…*/}
app: ServerApp<Options>;
ctx: (request: Request, event?: Partial<RequestEvent>) => RequestContext<Options, State>;