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: Serve staticDirs with Vitest #29811

Merged

Conversation

ghengeveld
Copy link
Member

@ghengeveld ghengeveld commented Dec 4, 2024

Closes #29772

What I did

Loads the staticDirs config and uses Vite's configureServer to add middleware to serve these static directories.

I refactored the existing logic to clean things up a bit and be able to reuse the most important parts.

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 -2.25 0%
initSize 130 MB 130 MB 6 B -0.99 0%
diffSize 52.5 MB 52.5 MB 6 B 1.61 0%
buildSize 6.75 MB 6.75 MB 0 B -0.5 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 1.09 0%
buildSbPreviewSize 0 B 0 B 0 B -0.5 -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.57 MB 3.57 MB 0 B -0.5 0%
buildPreviewSize 3.19 MB 3.19 MB 0 B 0.5 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 6.5s 6.4s -116ms -1 -1.8%
generateTime 18.3s 18.8s 456ms -0.99 2.4%
initTime 11.9s 12.1s 205ms -0.94 1.7%
buildTime 8.8s 8.9s 116ms -0.13 1.3%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 4.7s 4.6s -106ms -0.97 -2.3%
devManagerResponsive 3.4s 3.5s 7ms -0.57 0.2%
devManagerHeaderVisible 580ms 509ms -71ms -0.84 -13.9%
devManagerIndexVisible 873ms 573ms -300ms -0.9 -52.4%
devStoryVisibleUncached 1.7s 1.7s 0ms 0 0%
devStoryVisible 609ms 574ms -35ms -0.75 -6.1%
devAutodocsVisible 494ms 505ms 11ms -0.34 2.2%
devMDXVisible 403ms 499ms 96ms -0.24 19.2%
buildManagerHeaderVisible 532ms 530ms -2ms -0.47 -0.4%
buildManagerIndexVisible 607ms 606ms -1ms -0.31 -0.2%
buildStoryVisible 487ms 491ms 4ms -0.5 0.8%
buildAutodocsVisible 425ms 381ms -44ms -1.09 -11.5%
buildMDXVisible 429ms 403ms -26ms -0.7 -6.5%

Greptile Summary

Here's my concise review of the changes:

Refactored static file serving functionality to make Storybook's staticDirs API compatible with the Vitest plugin, enabling proper static asset serving during testing.

  • Exposed mapStaticDir utility in code/core/src/core-server/index.ts for use by Vitest plugin
  • Added static file serving middleware in code/addons/test/src/vitest-plugin/index.ts using sirv
  • Refactored parseStaticDir in code/core/src/core-server/utils/server-statics.ts to be synchronous
  • Updated code/core/src/core-server/utils/copy-all-static-files.ts to handle static directories without async/await
  • Added sirv dependency to code/addons/test/package.json for static file serving support

Copy link

nx-cloud bot commented Dec 4, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 5c403c7. 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.

@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Dec 4, 2024

Package Benchmarks

Commit: 5c403c7, ran on 6 December 2024 at 13:39:22 UTC

The following packages have significant changes to their size or dependencies:

@storybook/experimental-addon-test

Before After Difference
Dependency count 61 61 0
Self size 799 KB 833 KB 🚨 +34 KB 🚨
Dependency size 13.86 MB 13.86 MB 0 B
Bundle Size Analyzer Link Link

@ghengeveld ghengeveld marked this pull request as ready for review December 4, 2024 17:59
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.

7 file(s) reviewed, 11 comment(s)
Edit PR Review Bot Settings | Greptile

@ghengeveld ghengeveld force-pushed the 29772-bug-staticdirs-api-not-compatible-with-vitest-plugin branch from 63304de to a40adcc Compare December 6, 2024 09:25
@ghengeveld ghengeveld merged commit 3aa54a5 into next Dec 6, 2024
58 checks passed
@ghengeveld ghengeveld deleted the 29772-bug-staticdirs-api-not-compatible-with-vitest-plugin branch December 6, 2024 14:09
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] staticDirs API not compatible with vitest plugin
2 participants