惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
C
CXSECURITY Database RSS Feed - CXSecurity.com
P
Privacy International News Feed
H
Heimdal Security Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Secure Thoughts
MyScale Blog
MyScale Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
L
LINUX DO - 最新话题
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Cloudflare Blog
美团技术团队
Recorded Future
Recorded Future
T
Tailwind CSS Blog
Latest news
Latest news
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
Know Your Adversary
Know Your Adversary
Cloudbric
Cloudbric
Schneier on Security
Schneier on Security
I
Intezer
L
LINUX DO - 热门话题
P
Palo Alto Networks Blog
云风的 BLOG
云风的 BLOG
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Attack and Defense Labs
Attack and Defense Labs
人人都是产品经理
人人都是产品经理
L
LangChain Blog
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
L
Lohrmann on Cybersecurity
S
SegmentFault 最新的问题
W
WeLiveSecurity
C
Cybersecurity and Infrastructure Security Agency CISA
S
Securelist
SecWiki News
SecWiki News
V2EX - 技术
V2EX - 技术
IT之家
IT之家
Cyberwarzone
Cyberwarzone
F
Full Disclosure
Spread Privacy
Spread Privacy
阮一峰的网络日志
阮一峰的网络日志

Workflow SDK Documentation

Patterns for Defining Tools Human-in-the-Loop Building Durable AI Agents Queueing User Messages Resumable Streams Sleep, Suspense, and Scheduling Streaming Updates from Tools API Reference Workflow Globals Changelog Resilient run start Cookbook Building a World Deploying Astro Express Fastify Hono Getting Started NestJS Next.js Nitro Nuxt Python SvelteKit Vite corrupted-event-log fetch-in-workflow hook-conflict Errors node-js-module-in-workflow serialization-failed start-invalid-workflow-function step-not-registered timeout-in-workflow webhook-invalid-respond-with-value webhook-response-not-sent workflow-not-registered Errors & Retrying Hooks & Webhooks Idempotency Foundations Serialization Starting Workflows Streaming Versioning Workflows and Steps How the Directives Work Encryption Event Sourcing Framework Integrations Understanding Directives Migration Guides Migrating from AWS Step Functions Migrating from Inngest Migrating from Temporal Observability Testing Server-Based Testing createHook createWebhook defineHook FatalError fetch getStepMetadata getWorkflowMetadata getWritable workflow RetryableError sleep DurableAgent @workflow/ai WorkflowChatTransport getHookByToken getRun getWorld workflow/api resumeHook resumeWebhook Chat Session Modeling runtime-decryption-failed Upgrading Workflows abort-signal-timeout-in-workflow Cancellation How Cancellation Works Internal Serializable AbortController and AbortSignal Eager Processing of Steps & Incremental Event Replay TanStack Start Agent Cancellation Sequential & Parallel Execution Workflow Composition Local World | Workflow SDK Postgres World | Workflow SDK Vercel World | Workflow SDK Migrating from trigger.dev Secure Credential Handling Local World | Workflow SDK Postgres World | Workflow SDK Vercel World | Workflow SDK
@workflow/vitest
2026-05-31 · via Workflow SDK Documentation

Vitest plugin and test helpers for integration testing workflows in-process.

The @workflow/vitest package provides a Vitest plugin and test helpers for running full workflow integration tests in-process — no server required.

workflow()

Returns a Vite plugin array that handles SWC transforms, bundle building, and in-process handler registration automatically.

import { defineConfig } from "vitest/config";
import { workflow } from "@workflow/vitest"; 

export default defineConfig({
  plugins: [workflow()], 
});

Pass a WorkflowTestOptions object when your project uses a non-standard layout — for example, a monorepo where workflows/ does not live at the Vitest config's directory, or when the default .workflow-data / .workflow-vitest output locations need to move. The plugin forwards these paths to buildWorkflowTests() and setupWorkflowTests() through Vitest's per-project provided context, so each Vitest workspace project stays isolated.

import { defineConfig } from "vitest/config";
import { workflow } from "@workflow/vitest";

export default defineConfig({
  plugins: [
    workflow({
      cwd: "./apps/api",
      rootDir: "./apps/api/test-artifacts",
    }),
  ],
});

Parameters:

ParameterTypeDescription
options?WorkflowTestOptionsOptional configuration

Returns: Plugin[]

buildWorkflowTests()

Builds workflow and step bundles to disk. Called automatically by the workflow() plugin in globalSetup. Use directly only for manual setup.

import { buildWorkflowTests } from "@workflow/vitest";

export async function setup() {
  await buildWorkflowTests();
}

Parameters:

ParameterTypeDescription
options?WorkflowTestOptionsOptional configuration

setupWorkflowTests()

Sets up an in-process workflow runtime in each test worker. Imports pre-built bundles, creates a Local World instance with direct handlers, and sets it as the global world. Clears all workflow data on each invocation for full test isolation.

Called automatically by the workflow() plugin in setupFiles. Use directly only for manual setup.

import { beforeAll, afterAll } from "vitest";
import { setupWorkflowTests, teardownWorkflowTests } from "@workflow/vitest";

beforeAll(async () => {
  await setupWorkflowTests();
});

afterAll(async () => {
  await teardownWorkflowTests();
});

Parameters:

ParameterTypeDescription
options?WorkflowTestOptionsOptional configuration

teardownWorkflowTests()

Tears down the workflow test world. Clears the global world and closes the Local World instance. Called automatically by the workflow() plugin.

Returns: Promise<void>

WorkflowTestOptions

OptionTypeDefaultDescription
cwdstringprocess.cwd()The working directory of the project (where workflows/ lives). Relative paths resolve against process.cwd().
rootDirstringsame as cwdRoot directory used for default test artifacts. When set, dataDir and outDir default to <rootDir>/.workflow-data and <rootDir>/.workflow-vitest. Relative paths resolve against cwd.
dataDirstring<rootDir>/.workflow-dataDirectory for workflow runtime data written by the test world. Relative paths resolve against cwd.
outDirstring<rootDir>/.workflow-vitestDirectory for generated workflow and step bundles. Relative paths resolve against cwd.

waitForSleep()

Polls the event log until the workflow has a pending sleep() call — one with a wait_created event but no corresponding wait_completed event. Returns the correlation ID of the pending sleep, which can be passed to wakeUp() to target a specific sleep.

import { waitForSleep } from "@workflow/vitest"; 
import { start, getRun } from "workflow/api";

const run = await start(myWorkflow, []);
const sleepId = await waitForSleep(run); 
await getRun(run.runId).wakeUp({ correlationIds: [sleepId] }); 

Parameters:

ParameterTypeDescription
runRun<any>The workflow run to monitor
options?WaitOptionsPolling and timeout configuration

Returns: Promise<string> — The correlation ID of the first pending sleep. Pass this to wakeUp({ correlationIds: [id] }) to target a specific sleep.

Behavior with Multiple Sleeps

  • Sequential sleeps: waitForSleep() returns each sleep as the workflow reaches it. After waking one, call waitForSleep() again for the next.
  • Parallel sleeps: waitForSleep() returns whichever pending sleep is found first. After waking it, call waitForSleep() again to get the next one.

waitForHook()

Polls the hook list and event log until a hook matching the optional token filter exists that hasn't been received yet. Returns the matching hook object.

import { waitForHook } from "@workflow/vitest"; 
import { start, resumeHook } from "workflow/api";

const run = await start(myWorkflow, ["doc-1"]);
const hook = await waitForHook(run, { token: "approval:doc-1" }); 
await resumeHook(hook.token, { approved: true }); 

Parameters:

ParameterTypeDescription
runRun<any>The workflow run to monitor
options?WaitOptions & { token?: string }Polling, timeout, and optional token filter

Returns: Promise<Hook> — The first pending hook matching the filter. The hook object includes token, hookId, and runId.

WaitOptions

Both waitForSleep() and waitForHook() accept options for controlling polling behavior:

OptionTypeDefaultDescription
timeoutnumber30000Maximum time to wait in milliseconds
pollIntervalnumber100Polling interval in milliseconds