Перейти к содержимому
GitHubXDiscord

setDefaultRuntime

Стабильный · с 0.1.0

Заменяет рантайм, который возвращает getDefaultRuntime. Следующий вызов getDefaultRuntime() — и каждый хук-биндинг без провайдера в скоупе — увидит новый экземпляр.

Используй, когда нужно чистое состояние на каждый тест, когда твой boot-код приложения собирает кастомный рантайм, или когда поднимаешь несколько изолированных рантаймов и хочешь, чтобы один из них был дефолтным.

import { setDefaultRuntime } from '@triggery/core';
function setDefaultRuntime(runtime: Runtime): void;
ПараметрТипОписание
runtimeRuntimeЛюбой рантайм, созданный через createRuntime или createTestRuntime.

void. Только побочный эффект.

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. });

Замена на тестовый рантайм с mockCondition / mockAction

Заголовок раздела «Замена на тестовый рантайм с 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] }));