Add vitest plugin for testing full workflows without setting up a server#1237
Add vitest plugin for testing full workflows without setting up a server#1237VaguelySerious wants to merge 40 commits intomainfrom
Conversation
- 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
Signed-off-by: Cursor Agent <[email protected]>
Signed-off-by: Cursor Agent <[email protected]>
Create new 'testing/' section and update Foundations index page. Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX Co-authored-by: Pranay Prakash <[email protected]>
Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX Co-authored-by: Pranay Prakash <[email protected]>
Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX Co-authored-by: Pranay Prakash <[email protected]>
Update documentation to emphasize unit testing for steps only. Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX Co-authored-by: Pranay Prakash <[email protected]>
Move testing to top-level, fix content and update meta files. Slack-Thread: https://vercel.slack.com/archives/C09125LC4AX/p1772375177894629?thread_ts=1772375177.894629&cid=C09125LC4AX Co-authored-by: Pranay Prakash <[email protected]>
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]>
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]>
🦋 Changeset detectedLatest commit: 6148d7f The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
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 |
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests▲ Vercel Production (2 failed)nextjs-turbopack (1 failed):
sveltekit (1 failed):
🐘 Local Postgres (1 failed)hono-stable (1 failed):
🌍 Community Worlds (47 failed)turso (47 failed):
📋 Other (1 failed)e2e-local-postgres-nest-stable (1 failed):
Details by Category❌ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
❌ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
❌ 📋 Other
❌ Some E2E test jobs failed:
Check the workflow run for details. |
docs/content/docs/testing/index.mdx
Outdated
| ```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] |
There was a problem hiding this comment.
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.
Signed-off-by: Peter Wielander <[email protected]>
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