Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add vitest plugin for testing full workflows without setting up a server#1237

Open
VaguelySerious wants to merge 40 commits intomainfrom
peter/vitest-working
Open

Add vitest plugin for testing full workflows without setting up a server#1237
VaguelySerious wants to merge 40 commits intomainfrom
peter/vitest-working

Conversation

@VaguelySerious
Copy link
Member

@VaguelySerious VaguelySerious commented Mar 2, 2026

Superseeds #822. This allows users to add a vitest plugin enabling running of a workflow without a server instance, so you can e2e test a full workflow with given inputs.

Also introduces test helpers for "expect and skip next wait" and "expect and resolve next hook with ".

New docs link

Note this doesn't allow mocking due to how SWC bundles the step/run separately. There's a callout for that and it's already not supported in the existing docs/setup. I added a separate markdown file to the workbench with what Claude thinks is the way forward for that, and my personal take is that it's hard and we should not worry about it right now

cursoragent and others added 26 commits January 21, 2026 15:56
- Add new packages/vitest package with Vitest plugin that reuses @workflow/rollup
- Add workbench/vitest app with simple workflow code and unit tests
- Add GitHub CI workflow step for vitest plugin tests
- Add vitest workbench to changeset ignore list
- Step functions (add, multiply) now tested with actual execution and assertions
- Workflow function tested for workflowId property and expected throw behavior
- Removed greetWorkflow, simplified to single calculateWorkflow example
- Add test server (src/server.ts) that loads compiled workflow bundles
- Update tests to use start() to invoke workflows and verify results
- Tests verify calculateWorkflow(2, 7) returns correct sum/product/combined
- Build step uses 'wf build' to compile workflow bundles
- Add .gitignore for generated files
…ckage

- Delete packages/vitest (not needed as separate package)
- Update vitest.config.ts to use workflowTransformPlugin from @workflow/rollup
- Remove changeset entry for vitest package
- Remove duplicate test case
- Use globalSetup to start Nitro dev server before tests
- Use workflow/vite plugin for transformations
- Tests directly use start() and await run.returnValue
- Remove custom server.ts and build step
- Much simpler setup matching the sdk-with-workflows example
The vitest workbench spawns a Nitro server which doesn't work in the
regular unit test CI context. It has its own dedicated CI job.
- Add testing to docs navigation
- Create testing/index.mdx with setup instructions
- Link to workbench/vitest example files
Add 'globalSetup' script and vitest config, and update docs for test debugging.

Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX
Co-authored-by: Pranay Prakash <[email protected]>
… sleeps

Exposes the existing `wakeUpRun` logic as an instance method on the `Run`
class, allowing users to skip sleep() calls in tests or custom UIs.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
- Fix JSDoc @returns to describe StopSleepResult object instead of number
- Clean up global world state in afterEach to prevent test leakage
- Add delay before wakeUp() in docs example to allow workflow replay

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The file was removed on main but still exists on the base branch.
Restoring it so this PR's diff only contains relevant changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The docs test type-checks each code block independently, so the
standalone wakeUp snippet needs its own imports and run variable.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Use the // @setup comment pattern to provide type context without
rendering the setup line, keeping the snippet lean.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Peter Wielander <[email protected]>
Signed-off-by: Peter Wielander <[email protected]>
@VaguelySerious VaguelySerious requested a review from a team as a code owner March 2, 2026 19:25
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: 6148d7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@workflow/world-local Patch
workflow Patch
@workflow/vitest Patch
@workflow/cli Patch
@workflow/core Patch
@workflow/world-postgres Patch
@workflow/world-testing Patch
@workflow/builders Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/web-shared Patch
@workflow/astro Patch
@workflow/nest Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
@workflow/vite Patch
@workflow/nuxt Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Contributor

vercel bot commented Mar 2, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

🧪 E2E Test Results

Some tests failed

Summary

Passed Failed Skipped Total
❌ ▲ Vercel Production 534 2 58 594
✅ 💻 Local Development 572 0 76 648
✅ 📦 Local Production 572 0 76 648
❌ 🐘 Local Postgres 571 1 76 648
✅ 🪟 Windows 51 0 3 54
❌ 🌍 Community Worlds 115 47 9 171
❌ 📋 Other 137 1 24 162
Total 2552 51 322 2925

❌ Failed Tests

▲ Vercel Production (2 failed)

nextjs-turbopack (1 failed):

  • error handling retry behavior workflow completes despite transient 5xx on step_completed

sveltekit (1 failed):

  • error handling retry behavior workflow completes despite transient 5xx on step_completed
🐘 Local Postgres (1 failed)

hono-stable (1 failed):

  • webhookWorkflow
🌍 Community Worlds (47 failed)

turso (47 failed):

  • addTenWorkflow
  • addTenWorkflow
  • wellKnownAgentWorkflow (.well-known/agent)
  • should work with react rendering in step
  • promiseAllWorkflow
  • promiseRaceWorkflow
  • promiseAnyWorkflow
  • hookWorkflow
  • webhookWorkflow
  • sleepingWorkflow
  • parallelSleepWorkflow
  • nullByteWorkflow
  • workflowAndStepMetadataWorkflow
  • fetchWorkflow
  • promiseRaceStressTestWorkflow
  • error handling error propagation workflow errors nested function calls preserve message and stack trace
  • error handling error propagation workflow errors cross-file imports preserve message and stack trace
  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
  • error handling retry behavior regular Error retries until success
  • error handling retry behavior FatalError fails immediately without retries
  • error handling retry behavior RetryableError respects custom retryAfter delay
  • error handling retry behavior maxRetries=0 disables retries
  • error handling retry behavior workflow completes despite transient 5xx on step_completed
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • hookCleanupTestWorkflow - hook token reuse after workflow completion
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars)
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument
  • closureVariableWorkflow - nested step functions with closure variables
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly
  • Calculator.calculate - static workflow method using static step methods from another class
  • AllInOneService.processNumber - static workflow method using sibling static step methods
  • ChainableService.processWithThis - static step methods using this to reference the class
  • thisSerializationWorkflow - step function invoked with .call() and .apply()
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE
  • instanceMethodStepWorkflow - instance methods with "use step" directive
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument
  • cancelRun - cancelling a running workflow
  • cancelRun via CLI - cancelling a running workflow
  • pages router addTenWorkflow via pages router
  • pages router promiseAllWorkflow via pages router
  • pages router sleepingWorkflow via pages router
📋 Other (1 failed)

e2e-local-postgres-nest-stable (1 failed):

  • webhookWorkflow

Details by Category

❌ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 48 0 6
✅ example 48 0 6
✅ express 48 0 6
✅ fastify 48 0 6
✅ hono 48 0 6
❌ nextjs-turbopack 51 1 2
✅ nextjs-webpack 52 0 2
✅ nitro 48 0 6
✅ nuxt 48 0 6
❌ sveltekit 47 1 6
✅ vite 48 0 6
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 46 0 8
✅ express-stable 46 0 8
✅ fastify-stable 46 0 8
✅ hono-stable 46 0 8
✅ nextjs-turbopack-canary 51 0 3
✅ nextjs-turbopack-stable 51 0 3
✅ nextjs-webpack-canary 51 0 3
✅ nextjs-webpack-stable 51 0 3
✅ nitro-stable 46 0 8
✅ nuxt-stable 46 0 8
✅ sveltekit-stable 46 0 8
✅ vite-stable 46 0 8
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 46 0 8
✅ express-stable 46 0 8
✅ fastify-stable 46 0 8
✅ hono-stable 46 0 8
✅ nextjs-turbopack-canary 51 0 3
✅ nextjs-turbopack-stable 51 0 3
✅ nextjs-webpack-canary 51 0 3
✅ nextjs-webpack-stable 51 0 3
✅ nitro-stable 46 0 8
✅ nuxt-stable 46 0 8
✅ sveltekit-stable 46 0 8
✅ vite-stable 46 0 8
❌ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 46 0 8
✅ express-stable 46 0 8
✅ fastify-stable 46 0 8
❌ hono-stable 45 1 8
✅ nextjs-turbopack-canary 51 0 3
✅ nextjs-turbopack-stable 51 0 3
✅ nextjs-webpack-canary 51 0 3
✅ nextjs-webpack-stable 51 0 3
✅ nitro-stable 46 0 8
✅ nuxt-stable 46 0 8
✅ sveltekit-stable 46 0 8
✅ vite-stable 46 0 8
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 51 0 3
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 3 0 0
✅ mongodb 51 0 3
✅ redis-dev 3 0 0
✅ redis 51 0 3
✅ turso-dev 3 0 0
❌ turso 4 47 3
❌ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 46 0 8
❌ e2e-local-postgres-nest-stable 45 1 8
✅ e2e-local-prod-nest-stable 46 0 8

📋 View full workflow run


Some E2E test jobs failed:

  • Vercel Prod: failure
  • Local Dev: success
  • Local Prod: success
  • Local Postgres: failure
  • Windows: success

Check the workflow run for details.

```typescript title="vitest.integration.config.ts" lineNumbers
import { defineConfig } from "vitest/config";
import { workflow } from "workflow/vite"; // [!code highlight]
import { workflow } from "workflow/vitest"; // [!code highlight]
Copy link
Contributor

@vercel vercel bot Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation prose still references removed workflow/vitest import path in 3 places (lines 95, 246 in index.mdx and line 44 in server-based.mdx) after the code-block imports were fixed in commit 516918a.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants