setDefaultRuntime
Stable · since 0.1.0
Replace with a test runtime that has
Section titled “Replace with a test runtime that has mockCondition / mockAction”
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
Section titled “Import”import { setDefaultRuntime } from '@triggery/core';
Signature
Section titled “Signature”function setDefaultRuntime(runtime: Runtime): void;Parameters
Section titled “Parameters”| Param | Type | Description |
|---|---|---|
runtime | Runtime | Any runtime created via createRuntime or createTestRuntime. |
Returns
Section titled “Returns”void. Side effect only.
Examples
Section titled “Examples”Fresh runtime per test
Section titled “Fresh runtime per test”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime , setDefaultRuntime function setDefaultRuntime(runtime: Runtime): void } from '@triggery/core';
import { afterEach function afterEach<ExtraContext = object>(fn: AfterEachListener<ExtraContext>, timeout?: number): voidRegisters 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. , beforeEach function beforeEach<ExtraContext = object>(fn: BeforeEachListener<ExtraContext>, timeout?: number): voidRegisters 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. } from 'vitest';
beforeEach beforeEach<object>(fn: BeforeEachListener<object>, timeout?: number): voidRegisters 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. (() => {
setDefaultRuntime function setDefaultRuntime(runtime: Runtime): void (createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ inspectorBufferSize inspectorBufferSize?: number | undefinedInspector ring buffer size (default: 50). Ignored when the inspector is disabled. : 100 }));
});
afterEach afterEach<object>(fn: AfterEachListener<object>, timeout?: number): voidRegisters 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. (() => {
// 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 { setDefaultRuntime function setDefaultRuntime(runtime: Runtime): void } from '@triggery/core';
import { createTestRuntime function createTestRuntime(options?: TestRuntimeOptions): TestRuntime } from '@triggery/testing';
const rt const rt: TestRuntime = createTestRuntime function createTestRuntime(options?: TestRuntimeOptions): TestRuntime ();
setDefaultRuntime function setDefaultRuntime(runtime: Runtime): void (rt const rt: TestRuntime );
// Any module that calls createTrigger() without an explicit runtime now binds
// to `rt` via the default-runtime fallback inside createTrigger.Custom runtime in app bootstrap
Section titled “Custom runtime in app bootstrap”import { createRuntime function createRuntime(options?: RuntimeOptions): Runtime , setDefaultRuntime function 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 tracing const 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;
}
= {
name name: string : 'tracing',
onFire onFire?(ctx: FireContext): void | {
cancel: true;
reason: string;
}
({ eventName eventName: string }) {
console var console: Console .debug Console.debug(...data: any[]): voidThe **`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]', eventName eventName: string );
},
};
setDefaultRuntime function setDefaultRuntime(runtime: Runtime): void (createRuntime function createRuntime(options?: RuntimeOptions): Runtime ({ middleware middleware?: readonly Middleware[] | undefinedGlobal middleware applied to every trigger in this runtime. : [tracing const tracing: Middleware ] }));Related
Section titled “Related” getDefaultRuntime Read the current singleton (and lazy-create on first call).
createRuntime Create an isolated runtime.
createTestRuntime Test-flavoured runtime with mockCondition / mockAction.
TriggerRuntimeProvider Subtree-scoped runtime injection.