Skip to content
GitHubXDiscord

setDefaultRuntime

Stable · since 0.1.0

Replaces the runtime returned by getDefaultRuntime. The next call to getDefaultRuntime() — and every binding hook with no provider in scope — sees the new instance.

Use this when you need a clean slate per test, when your app boot path constructs a customized runtime, or when you mount multiple isolated runtimes and want one of them to act as the default.

import { setDefaultRuntime } from '@triggery/core';
function setDefaultRuntime(runtime: Runtime): void;
ParamTypeDescription
runtimeRuntimeAny runtime created via createRuntime or createTestRuntime.

void. Side effect only.

import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime, setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void } from '@triggery/core';
import { afterEachfunction afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): void
Registers a callback function to be executed after each test within the current suite has completed. This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions. **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
@paramfn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.@paramtimeout - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.@returns@example```ts // Example of using afterEach to delete temporary files created during a test afterEach(async () => { await fileSystem.deleteTempFiles(); }); ```
, beforeEachfunction beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): void
Registers a callback function to be executed before each test within the current suite. This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables. **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
@paramfn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.@paramtimeout - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.@returns@example```ts // Example of using beforeEach to reset a database state beforeEach(async () => { await database.reset(); }); ```
} from 'vitest';
beforeEachbeforeEach<object>(fn: BeforeEachListener<object>, timeout?: number): void
Registers a callback function to be executed before each test within the current suite. This hook is useful for scenarios where you need to reset or reinitialize the test environment before each test runs, such as resetting database states, clearing caches, or reinitializing variables. **Note:** The `beforeEach` hooks are executed in the order they are defined one after another. You can configure this by changing the `sequence.hooks` option in the config file.
@paramfn - The callback function to be executed before each test. This function receives an `TestContext` parameter if additional test context is needed.@paramtimeout - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.@returns@example```ts // Example of using beforeEach to reset a database state beforeEach(async () => { await database.reset(); }); ```
(() => {
setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void(createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ inspectorBufferSizeinspectorBufferSize?: number | undefined
Inspector ring buffer size (default: 50). Ignored when the inspector is disabled.
: 100 }));
}); afterEachafterEach<object>(fn: AfterEachListener<object>, timeout?: number): void
Registers a callback function to be executed after each test within the current suite has completed. This hook is useful for scenarios where you need to clean up or reset the test environment after each test runs, such as deleting temporary files, clearing test-specific database entries, or resetting mocked functions. **Note:** The `afterEach` hooks are running in reverse order of their registration. You can configure this by changing the `sequence.hooks` option in the config file.
@paramfn - The callback function to be executed after each test. This function receives an `TestContext` parameter if additional test context is needed.@paramtimeout - Optional timeout in milliseconds for the hook. If not provided, the default hook timeout from the runner's configuration is used.@returns@example```ts // Example of using afterEach to delete temporary files created during a test afterEach(async () => { await fileSystem.deleteTempFiles(); }); ```
(() => {
// Optional — the next beforeEach will replace it anyway. });

Replace with a test runtime that has mockCondition / mockAction

Section titled “Replace with a test runtime that has mockCondition / mockAction”
import { setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void } from '@triggery/core';
import { createTestRuntimefunction createTestRuntime(options?: TestRuntimeOptions): TestRuntime } from '@triggery/testing';

const rtconst rt: TestRuntime = createTestRuntimefunction createTestRuntime(options?: TestRuntimeOptions): TestRuntime();
setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void(rtconst rt: TestRuntime);

// Any module that calls createTrigger() without an explicit runtime now binds
// to `rt` via the default-runtime fallback inside createTrigger.
import { createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime, setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void, type Middleware
type Middleware = {
    readonly name: string;
    onFire?(ctx: FireContext): void | {
        cancel: true;
        reason: string;
    };
    onBeforeMatch?(ctx: MatchContext): void;
    onSkip?(ctx: SkipContext): void;
    onActionStart?(ctx: ActionContext): void;
    onActionEnd?(ctx: ActionContext & {
        durationMs: number;
        result?: unknown;
    }): void;
    onError?(ctx: ActionContext & {
        error: unknown;
    }): void;
    onCascade?(ctx: CascadeContext): void;
}
} from '@triggery/core';
const tracingconst tracing: Middleware: Middleware
type Middleware = {
    readonly name: string;
    onFire?(ctx: FireContext): void | {
        cancel: true;
        reason: string;
    };
    onBeforeMatch?(ctx: MatchContext): void;
    onSkip?(ctx: SkipContext): void;
    onActionStart?(ctx: ActionContext): void;
    onActionEnd?(ctx: ActionContext & {
        durationMs: number;
        result?: unknown;
    }): void;
    onError?(ctx: ActionContext & {
        error: unknown;
    }): void;
    onCascade?(ctx: CascadeContext): void;
}
= {
namename: string: 'tracing', onFire
onFire?(ctx: FireContext): void | {
    cancel: true;
    reason: string;
}
({ eventNameeventName: string }) {
consolevar console: Console.debugConsole.debug(...data: any[]): void
The **`console.debug()`** static method outputs a message to the console at the 'debug' log level. [MDN Reference](https://developer.mozilla.org/docs/Web/API/console/debug_static)
('[event]', eventNameeventName: string);
}, }; setDefaultRuntimefunction setDefaultRuntime(runtime: Runtime): void(createRuntimefunction createRuntime(options?: RuntimeOptions): Runtime({ middlewaremiddleware?: readonly Middleware[] | undefined
Global middleware applied to every trigger in this runtime.
: [tracingconst tracing: Middleware] }));