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: Always run Vitest in watch mode internally #29749

Merged
merged 8 commits into from
Dec 10, 2024

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Nov 29, 2024

What I did

Changed the Vitest logic to always run in watch mode, and then internally disable triggering tests on file changes when SB watch mode is disabled. This ensures that coverage is always re-intrumented on file changes, and Vitest module caches, even when SB watch mode is disabled.

Basically, when we want the flow where we're re-using the Vitest instance, we want to always enable watch mode too, as that is how Vitest expects to behave. Disabled watch-mode are only supported for single-use Vitest instances.

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 1.48 kB -0.3 0%
initSize 133 MB 133 MB 1.5 kB 2.97 0%
diffSize 55.1 MB 55.1 MB 24 B 2.95 0%
buildSize 6.87 MB 6.87 MB 0 B 1.16 0%
buildSbAddonsSize 1.51 MB 1.51 MB 0 B 3 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.86 MB 1.86 MB 0 B 2.95 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.57 MB 3.57 MB 0 B 3 0%
buildPreviewSize 3.3 MB 3.3 MB 0 B 1.13 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 7.4s 7.3s -122ms -0.54 -1.7%
generateTime 21.5s 21.2s -317ms 0.36 -1.5%
initTime 13.5s 15.5s 1.9s 1.62 🔺12.6%
buildTime 8.3s 12.2s 3.8s 5.99 🔺31.4%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 5.7s 5.4s -268ms 0.38 -4.9%
devManagerResponsive 4.2s 4s -234ms 0.61 -5.8%
devManagerHeaderVisible 576ms 692ms 116ms 1.76 🔺16.8%
devManagerIndexVisible 677ms 707ms 30ms 0.54 4.2%
devStoryVisibleUncached 1.9s 1.9s 12ms 0.63 0.6%
devStoryVisible 673ms 731ms 58ms 1.1 7.9%
devAutodocsVisible 686ms 462ms -224ms -0.9 -48.5%
devMDXVisible 562ms 677ms 115ms 2.28 🔺17%
buildManagerHeaderVisible 748ms 590ms -158ms 0.02 -26.8%
buildManagerIndexVisible 757ms 735ms -22ms 0.66 -3%
buildStoryVisible 596ms 518ms -78ms -0.16 -15.1%
buildAutodocsVisible 426ms 472ms 46ms 0.32 9.7%
buildMDXVisible 510ms 431ms -79ms -0.22 -18.3%

Greptile Summary

Modified Vitest test runner to always operate in watch mode internally while using Storybook's watch mode flag to control test execution, improving cache invalidation and coverage instrumentation.

  • Changed VitestManager to always use watch: true in Vitest configuration
  • Added guard in runAffectedTestsAfterChange to only trigger tests when Storybook watch mode is enabled
  • Set cleanOnRerun: false for coverage options to preserve instrumentation state
  • Updated TestManager to handle coverage mode changes without affecting watch mode state
  • Modified test suite to verify new watch mode and coverage behavior

@JReinhold JReinhold self-assigned this Nov 29, 2024
@JReinhold JReinhold changed the title always run vitest in watch mode Test: Always run Vitest in watch mode internally Nov 29, 2024
Copy link

nx-cloud bot commented Nov 29, 2024

☁️ Nx Cloud Report

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


🟥 Failed Commands
nx run-many -t build --parallel=3

Sent with 💌 from NxCloud.

@JReinhold JReinhold added maintenance User-facing maintenance tasks addon: test ci:normal labels Nov 29, 2024
@JReinhold JReinhold marked this pull request as ready for review November 29, 2024 12:14
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.

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

code/addons/test/src/node/test-manager.ts Outdated Show resolved Hide resolved
code/addons/test/src/node/test-manager.ts Outdated Show resolved Hide resolved
Base automatically changed from jeppe/vitest-coverage-backend to next November 29, 2024 14:27
Copy link
Member

@ghengeveld ghengeveld left a comment

Choose a reason for hiding this comment

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

Needs a bit of work, I think.

code/addons/test/src/node/test-manager.ts Outdated Show resolved Hide resolved
code/addons/test/src/node/test-manager.ts Outdated Show resolved Hide resolved
code/addons/test/src/node/test-manager.ts Outdated Show resolved Hide resolved
code/addons/test/src/node/vitest-manager.ts Show resolved Hide resolved
@storybook-pr-benchmarking
Copy link

storybook-pr-benchmarking bot commented Dec 2, 2024

Package Benchmarks

Commit: 12179c1, ran on 10 December 2024 at 09:35:23 UTC

No significant changes detected, all good. 👏

@JReinhold JReinhold marked this pull request as draft December 10, 2024 08:01
@JReinhold JReinhold marked this pull request as ready for review December 10, 2024 09:24
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.

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

Comment on lines 57 to +58
clean: false,
cleanOnRerun: !watchMode,
cleanOnRerun: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: cleanOnRerun:false could potentially lead to stale coverage data if files are deleted or renamed

Comment on lines +191 to +192
expect(createVitest).toHaveBeenCalledTimes(4);
expect(vitest.runFiles).toHaveBeenCalledWith([], true);
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: test expects 4 createVitest calls but only verifies empty test run. Should verify both coverage-disabled and coverage-enabled runs

Comment on lines +102 to 107
if (payload.config) {
this.handleConfigChange({
providerId: payload.providerId,
config: payload.config,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: handleConfigChange is called before checking if the config actually changed, which could trigger unnecessary restarts

@JReinhold JReinhold merged commit 76ce9db into next Dec 10, 2024
58 of 59 checks passed
@JReinhold JReinhold deleted the jeppe/always-watch-vitest branch December 10, 2024 12:47
@github-actions github-actions bot mentioned this pull request Dec 10, 2024
11 tasks
@shilman shilman changed the title Test: Always run Vitest in watch mode internally Addon Test: Always run Vitest in watch mode internally Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addon: test ci:normal maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants