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

Test: Upgrade Vitest to v2 #28788

Merged
merged 25 commits into from
Aug 6, 2024
Merged

Test: Upgrade Vitest to v2 #28788

merged 25 commits into from
Aug 6, 2024

Conversation

yannbf
Copy link
Member

@yannbf yannbf commented Aug 2, 2024

What I did

Most of the vitest 2.0 changes were backwards compatible:
https://github.com/vitest-dev/vitest/releases/tag/v2.0.0

Except the new type definitions of fn and Mock:

import { type Mock, vi } from 'vitest'

const add = (x: number, y: number): number => x + y

// using vi.fn<T>
const mockAdd = vi.fn<Parameters<typeof add>, ReturnType<typeof add>>() // [!code --]
const mockAdd = vi.fn<typeof add>() // [!code ++]

// using Mock<T>
const mockAdd: Mock<Parameters<typeof add>, ReturnType<typeof add>> = vi.fn() // [!code --]
const mockAdd: Mock<typeof add> = vi.fn() // [!code ++]

For storybook 8.3, we made this backwards compatible, with the following workaround:

// TODO: Remove in 9.0
export type Mock<T extends Procedure | any[], R = any> = T extends Procedure
? MockV2<T>
: T extends any[]
? MockV2<(...args: T) => R>
: never;
// V2
export function fn<T extends Procedure = Procedure>(implementation?: T): Mock<T>;
// TODO: Remove in 9.0
// V1
export function fn<TArgs extends any[] = any, R = any>(): Mock<(...args: TArgs) => R>;
export function fn<TArgs extends any[] = any[], R = any>(
implementation: (...args: TArgs) => R
): Mock<(...args: TArgs) => R>;
export function fn<TArgs extends any[] = any[], R = any>(
implementation?: (...args: TArgs) => R
): Mock<(...args: TArgs) => R>;
export function fn(implementation?: Procedure) {
const mock = implementation ? vitestFn(implementation) : vitestFn();
return reactiveMock(mock);
}

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/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 76.3 MB 76.3 MB 0 B -0.09 0%
initSize 172 MB 171 MB -1.15 MB -1.62 -0.7%
diffSize 95.7 MB 94.5 MB -1.15 MB -1.62 -1.2%
buildSize 7.6 MB 7.42 MB -179 kB -39.35 -2.4%
buildSbAddonsSize 1.64 MB 1.61 MB -21.5 kB -6.72 -1.3%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 2.29 MB 2.29 MB 0 B -1.53 0%
buildSbPreviewSize 351 kB 351 kB 0 B 0.82 0%
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 4.47 MB 4.45 MB -21.5 kB -5.68 -0.5%
buildPreviewSize 3.13 MB 2.97 MB -158 kB -93.97 🔰-5.3%
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 23.7s 22.8s -861ms 1.08 -3.8%
generateTime 23.3s 19.3s -4s -1ms -2.11 🔰-20.7%
initTime 21.4s 17.7s -3s -666ms -1.82 🔰-20.6%
buildTime 12.3s 13.3s 987ms -0.57 7.4%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 11.2s 10.6s -609ms 1.04 -5.7%
devManagerResponsive 6.3s 6.3s -51ms 0.98 -0.8%
devManagerHeaderVisible 937ms 997ms 60ms 1.02 6%
devManagerIndexVisible 978ms 1s 56ms 1.01 5.4%
devStoryVisibleUncached 1.3s 1.4s 26ms 0.47 1.8%
devStoryVisible 1s 1s 52ms 0.93 4.9%
devAutodocsVisible 766ms 988ms 222ms 1.85 🔺22.5%
devMDXVisible 904ms 920ms 16ms 1.92 1.7%
buildManagerHeaderVisible 788ms 843ms 55ms 0.37 6.5%
buildManagerIndexVisible 799ms 846ms 47ms 0.35 5.6%
buildStoryVisible 858ms 912ms 54ms 0.44 5.9%
buildAutodocsVisible 796ms 765ms -31ms 0.5 -4.1%
buildMDXVisible 716ms 736ms 20ms 0.54 2.7%

Greptile Summary

Upgraded Vitest to version 2.0.5 and updated related dependencies to ensure compatibility and improve the testing framework.

  • Updated /code/addons/a11y/src/manager.test.tsx to use Vitest for testing A11yManager functionality.
  • Upgraded vitest dependency in scripts/package.json from ^1.6.0 to ^2.0.5.
  • Updated code/package.json to upgrade Vitest and related testing libraries, removing some outdated dependencies.

@yannbf yannbf added build Internal-facing build tooling & test updates ci:normal labels Aug 2, 2024
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

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

Copy link

nx-cloud bot commented Aug 2, 2024

☁️ Nx Cloud Report

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

@yannbf yannbf changed the title Upgrade Vitest to v2 Build: Upgrade Vitest to v2 Aug 5, 2024
@kasperpeulen kasperpeulen added maintenance User-facing maintenance tasks and removed build Internal-facing build tooling & test updates labels Aug 5, 2024
@kasperpeulen kasperpeulen changed the title Build: Upgrade Vitest to v2 Test: Upgrade Vitest to v2 Aug 5, 2024
@yannbf yannbf self-assigned this Aug 5, 2024
@kasperpeulen kasperpeulen merged commit 9a6b5c7 into next Aug 6, 2024
52 of 53 checks passed
@kasperpeulen kasperpeulen deleted the yann/upgrade-vitest-v2 branch August 6, 2024 11:36
@github-actions github-actions bot mentioned this pull request Aug 6, 2024
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:normal maintenance User-facing maintenance tasks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants