setDefaultRuntime
Стабильный · с 0.1.0
Замена на тестовый рантайм с
Заголовок раздела «Замена на тестовый рантайм с mockCondition / mockAction»
Заменяет рантайм, который возвращает getDefaultRuntime. Следующий вызов getDefaultRuntime() — и каждый хук-биндинг без провайдера в скоупе — увидит новый экземпляр.
Используй, когда нужно чистое состояние на каждый тест, когда твой boot-код приложения собирает кастомный рантайм, или когда поднимаешь несколько изолированных рантаймов и хочешь, чтобы один из них был дефолтным.
import { setDefaultRuntime } from '@triggery/core';
Сигнатура
Заголовок раздела «Сигнатура»function setDefaultRuntime(runtime: Runtime): void;Параметры
Заголовок раздела «Параметры»| Параметр | Тип | Описание |
|---|---|---|
runtime | Runtime | Любой рантайм, созданный через createRuntime или createTestRuntime. |
Возвращает
Заголовок раздела «Возвращает»void. Только побочный эффект.
Примеры
Заголовок раздела «Примеры»Свежий рантайм на каждый тест
Заголовок раздела «Свежий рантайм на каждый тест»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.
});Замена на тестовый рантайм с mockCondition / mockAction
Заголовок раздела «Замена на тестовый рантайм с 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.Кастомный рантайм при bootstrap-приложении
Заголовок раздела «Кастомный рантайм при 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 ] }));Замечания
Заголовок раздела «Замечания»См. также
Заголовок раздела «См. также» getDefaultRuntime Прочитать текущий синглтон (и лениво создать при первом вызове).
createRuntime Создать изолированный рантайм.
createTestRuntime Тестовый рантайм с mockCondition / mockAction.
TriggerRuntimeProvider Скоупоориентированный инжект рантайма в поддерево.