Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon Test: Support Storybook environment variables in Vitest #29792

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Dec 3, 2024

Closes #29779

What I did

Loads environment variables configured in Storybook's main config and adds them to the Vitest env config. Sets Vite's envPrevix to include STORYBOOK_ prefixed environment variables.

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

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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 canary-release-pr.yml --field pr=<PR_NUMBER>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 77.7 MB 77.7 MB 0 B 0.82 0%
initSize 130 MB 130 MB 68 B 0.21 0%
diffSize 52.4 MB 52.4 MB 68 B 0.07 0%
buildSize 6.75 MB 6.75 MB 0 B -1.73 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B - 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.86 MB 1.86 MB 0 B -0.41 0%
buildSbPreviewSize 0 B 0 B 0 B -1.73 -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.56 MB 3.56 MB 0 B -1.73 0%
buildPreviewSize 3.19 MB 3.19 MB 0 B 1.73 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 24.6s 7.2s -17s -412ms -1.08 -240.3%
generateTime 18.8s 19.8s 1s -0.69 5.2%
initTime 12s 12.9s 906ms -0.56 7%
buildTime 9.9s 8.1s -1s -797ms -1.1 -22.1%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 4.4s 5s 606ms -0.09 11.9%
devManagerResponsive 3.2s 3.6s 448ms -0.05 12.1%
devManagerHeaderVisible 531ms 589ms 58ms -0.13 9.8%
devManagerIndexVisible 580ms 622ms 42ms -0.46 6.8%
devStoryVisibleUncached 1.8s 1.1s -662ms -2.98 🔰-57.7%
devStoryVisible 559ms 624ms 65ms -0.37 10.4%
devAutodocsVisible 508ms 547ms 39ms 0.11 7.1%
devMDXVisible 462ms 542ms 80ms 0.06 14.8%
buildManagerHeaderVisible 501ms 803ms 302ms 1.54 🔺37.6%
buildManagerIndexVisible 577ms 902ms 325ms 1.79 🔺36%
buildStoryVisible 466ms 731ms 265ms 1.19 36.3%
buildAutodocsVisible 390ms 628ms 238ms 1.52 🔺37.9%
buildMDXVisible 394ms 512ms 118ms 0.4 23%

Greptile Summary

Based on the provided information, I'll create a concise summary of the pull request changes:

Adds support for Storybook environment variables in the Vitest plugin, enabling proper handling of both Storybook-configured and Vite environment variables during testing.

  • Added environment variable loading from Storybook's main config via presets.apply('env') in code/addons/test/src/vitest-plugin/index.ts
  • Added STORYBOOK_ to Vite's envPrefix array to support Storybook-prefixed variables
  • Added env extension to Presets interface in code/core/src/types/modules/core-common.ts
  • Maintains proper precedence by merging Storybook env variables with Vitest config
  • Handles edge cases with nullish coalescing for undefined config objects

@ghengeveld ghengeveld marked this pull request as ready for review December 3, 2024 16:05
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

2 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

Copy link

nx-cloud bot commented Dec 3, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 4baa486. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@ghengeveld ghengeveld merged commit 1370dc2 into next Dec 4, 2024
60 checks passed
@ghengeveld ghengeveld deleted the storybook-env-vars-in-vitest branch December 4, 2024 11:58
@github-actions github-actions bot mentioned this pull request Dec 4, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Storybook environment variables not fully supported in Vitest plugin
2 participants