Skip to content

Addon-Vitest: Update Vitest plugin configuration to disable requireAssertions for expect#33693

Merged
valentinpalkovic merged 1 commit into
nextfrom
valentin/addon-vitest-requireassertions
Jan 28, 2026
Merged

Addon-Vitest: Update Vitest plugin configuration to disable requireAssertions for expect#33693
valentinpalkovic merged 1 commit into
nextfrom
valentin/addon-vitest-requireassertions

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented Jan 28, 2026

Closes #33692

What I did

SvelteKit's default Vitest configuration sets expect.requireAssertions: true. When using addon-vitest, stories without a play function are transformed into smoke tests that contain no assertions. This causes the test suite to fail with: Error: expected any number of assertion, but got none.

I modified the @storybook/addon-vitest plugin to internally override the test.expect.requireAssertions setting. This ensures that generated smoke tests pass regardless of the user's global Vitest strictness settings, while keeping the rest of the user's configuration intact via the config hook.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  1. Initialize a SvelteKit project: npm create svelte@latest my-app (Select "Library project", "TypeScript", and "Vitest").
  2. Verify vite.config.ts: Ensure the config contains:
test: {
    expect: { requireAssertions: true },
    // ... projects config
}
  1. Add Storybook: npx storybook@latest init
  2. npm run test (or the equivalent vitest command).
  3. Story tests should pass!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Jan 28, 2026

View your CI Pipeline Execution ↗ for commit d33b9c3

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 9m 56s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-28 13:32:38 UTC

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

A Vitest configuration property is added to the plugin, setting test.expect.requireAssertions to false within the base Vite configuration. This modifies the test runner's assertion validation behavior.

Changes

Cohort / File(s) Summary
Vitest Configuration
code/addons/vitest/src/vitest-plugin/index.ts
Adds test.expect.requireAssertions: false to the Vitest configuration under the base Vite config, disabling assertion requirement validation.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@valentinpalkovic valentinpalkovic merged commit b18d12e into next Jan 28, 2026
132 of 137 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/addon-vitest-requireassertions branch January 28, 2026 14:38
@github-actions github-actions Bot mentioned this pull request Jan 28, 2026
24 tasks
@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jan 30, 2026
@github-actions github-actions Bot mentioned this pull request Jan 30, 2026
10 tasks
valentinpalkovic added a commit that referenced this pull request Jan 30, 2026
…ireassertions

Addon-Vitest: Update Vitest plugin configuration to disable requireAssertions for expect
(cherry picked from commit b18d12e)
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jan 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: vitest bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Addon-vitest smoke tests fail when expect.requireAssertions is enabled in SvelteKit

2 participants