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

feat: Setup Vitest #3201

Merged
merged 42 commits into from
Sep 19, 2024
Merged

feat: Setup Vitest #3201

merged 42 commits into from
Sep 19, 2024

Conversation

nicholas-codecov
Copy link
Contributor

@nicholas-codecov nicholas-codecov commented Sep 16, 2024

Description

This PR introduces Vitest to the codebase. Vitest will only run tests that end in *.test.* whereas CRACO will run tests that end in *.spec.*. If you want to write a test for Vitest, it must end in *.test.*. Alongside the addition of Vitest, we're also migrating to MSW V2, reason being ... V1 doesn't work with Vitest, and the codemod didn't work out for migrating our Jest MSW mocks over.

This PR also contains examples for:

  • MSW V2 mocks
  • Mocking functions
  • Mocking a single function and leaving the remaining as their normal import
  • Mocking React Lazy imports

Here's a link to the MSW migration docs: https://mswjs.io/docs/migrations/1.x-to-2.x

Ticket: codecov/engineering-team#2126

Notable Changes

  • Add in Vitest, MSW V2
  • Configure our CI to run both CRACO and Vitest side by side
  • Tweak our codecov.yml to ignore files that we can't easily test like images
  • Couple of test migrations to ensure that our CI scripts work properly

@codecov-staging
Copy link

codecov-staging bot commented Sep 16, 2024

Bundle Report

Changes will increase total bundle size by 179 bytes ⬆️

Bundle name Size Change
gazebo-staging-array-push 6.0MB 179 bytes ⬆️

Copy link

codecov bot commented Sep 16, 2024

Bundle Report

Changes will increase total bundle size by 34 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
gazebo-production-array-push 6.0MB 34 bytes ⬆️

@codecov-qa
Copy link

codecov-qa bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.10%. Comparing base (8057aba) to head (8f7c013).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3201      +/-   ##
==========================================
+ Coverage   98.14%   99.10%   +0.96%     
==========================================
  Files         932      799     -133     
  Lines       14482    13975     -507     
  Branches     3958     3960       +2     
==========================================
- Hits        14213    13850     -363     
+ Misses        264      117     -147     
- Partials        5        8       +3     
Files with missing lines Coverage Δ
src/old_ui/Icon/Icon.jsx 100.00% <100.00%> (ø)

... and 140 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (+46.51%) ⬆️
Layouts 100.00% <ø> (+1.12%) ⬆️
Pages 98.88% <ø> (-0.02%) ⬇️
Services 99.41% <ø> (ø)
Shared 99.58% <ø> (-0.07%) ⬇️
UI 99.26% <ø> (+4.68%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8057aba...8f7c013. Read the comment docs.

Copy link

codecov bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.10%. Comparing base (8057aba) to head (8f7c013).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@               Coverage Diff                @@
##               main      #3201        +/-   ##
================================================
+ Coverage   98.14000   99.10000   +0.96000     
================================================
  Files           932        799       -133     
  Lines         14482      13975       -507     
  Branches       3877       3965        +88     
================================================
- Hits          14213      13850       -363     
+ Misses          264        117       -147     
- Partials          5          8         +3     
Files with missing lines Coverage Δ
src/old_ui/Icon/Icon.jsx 100.00% <100.00%> (ø)

... and 140 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (+46.51%) ⬆️
Layouts 100.00% <ø> (+1.12%) ⬆️
Pages 98.88% <ø> (-0.02%) ⬇️
Services 99.41% <ø> (ø)
Shared 99.58% <ø> (-0.07%) ⬇️
UI 99.26% <ø> (+4.68%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8057aba...8f7c013. Read the comment docs.

Copy link

codecov-public-qa bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.10%. Comparing base (8057aba) to head (8f7c013).

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3201      +/-   ##
==========================================
+ Coverage   98.14%   99.10%   +0.96%     
==========================================
  Files         932      799     -133     
  Lines       14482    13975     -507     
  Branches     3958     3965       +7     
==========================================
- Hits        14213    13850     -363     
+ Misses        264      117     -147     
- Partials        5        8       +3     
Files Coverage Δ
src/old_ui/Icon/Icon.jsx 100.00% <100.00%> (ø)

... and 140 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (+46.51%) ⬆️
Layouts 100.00% <ø> (+1.12%) ⬆️
Pages 98.88% <ø> (-0.02%) ⬇️
Services 99.41% <ø> (ø)
Shared 99.58% <ø> (-0.07%) ⬇️
UI 99.26% <ø> (+4.68%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8057aba...8f7c013. Read the comment docs.

@codecov-notifications
Copy link

codecov-notifications bot commented Sep 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3201      +/-   ##
==========================================
+ Coverage   98.14%   99.10%   +0.96%     
==========================================
  Files         932      799     -133     
  Lines       14482    13975     -507     
  Branches     3958     3960       +2     
==========================================
- Hits        14213    13850     -363     
+ Misses        264      117     -147     
- Partials        5        8       +3     
Files Coverage Δ
src/old_ui/Icon/Icon.jsx 100.00% <100.00%> (ø)

... and 140 files with indirect coverage changes

Components Coverage Δ
Assets 100.00% <ø> (+46.51%) ⬆️
Layouts 100.00% <ø> (+1.12%) ⬆️
Pages 98.88% <ø> (-0.02%) ⬇️
Services 99.41% <ø> (ø)
Shared 99.58% <ø> (-0.07%) ⬇️
UI 99.26% <ø> (+4.68%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8057aba...8f7c013. Read the comment docs.

@codecov-releaser
Copy link
Contributor

codecov-releaser commented Sep 16, 2024

✅ Deploy preview for gazebo ready!

Previews expire after 1 month automatically.

Storybook

Commit Created Cloud Enterprise
22f7703 Mon, 16 Sep 2024 18:12:08 GMT Expired Expired
89f1162 Mon, 16 Sep 2024 18:19:16 GMT Expired Expired
63ea5f4 Mon, 16 Sep 2024 18:38:17 GMT Expired Expired
6e76768 Mon, 16 Sep 2024 18:51:41 GMT Expired Expired
7e11df0 Mon, 16 Sep 2024 19:04:11 GMT Expired Expired
2bae740 Tue, 17 Sep 2024 10:41:47 GMT Expired Expired
2bae740 Tue, 17 Sep 2024 10:42:11 GMT Expired Expired
fac7172 Tue, 17 Sep 2024 11:02:46 GMT Expired Expired
455d738 Tue, 17 Sep 2024 13:25:26 GMT Expired Expired
41d3897 Tue, 17 Sep 2024 17:23:42 GMT Expired Expired
9288a62 Tue, 17 Sep 2024 18:01:39 GMT Expired Expired
9ea79b8 Wed, 18 Sep 2024 11:35:58 GMT Expired Expired
53616b2 Wed, 18 Sep 2024 12:01:58 GMT Expired Expired
0a5ed38 Wed, 18 Sep 2024 12:46:55 GMT Expired Expired
6e656c5 Wed, 18 Sep 2024 14:07:54 GMT Expired Expired
31b1335 Wed, 18 Sep 2024 14:43:50 GMT Expired Expired
9f73de4 Thu, 19 Sep 2024 12:25:43 GMT Expired Expired
1c2aebc Thu, 19 Sep 2024 12:56:17 GMT Expired Expired
5d6b24e Thu, 19 Sep 2024 13:13:34 GMT Expired Expired
8f7c013 Thu, 19 Sep 2024 13:22:02 GMT Cloud Enterprise

@nicholas-codecov nicholas-codecov marked this pull request as ready for review September 18, 2024 14:37
Copy link
Contributor

Choose a reason for hiding this comment

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

This will likely affect our after_n_builds setting in codecov. Not a huge deal though.

Copy link
Contributor

Choose a reason for hiding this comment

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

fine with living with this until we move over to vitest completely

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wait you already updated it LOL. In that case, we should just remember to update it when we're done the transition.

ctx.status(200),
ctx.data({ me: { owner: { isAdmin: true } } })
graphql.query('owner', (info) => {
return HttpResponse.json(
Copy link
Contributor

Choose a reason for hiding this comment

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

Codecov is showing me line coverage for this file, which is unexpected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeaaa the test files were being included in the coverage reporting, this should be fixed. It was also causing downstream issues

<IconSvg className={cs(iconClass ? iconClass : IconClasses[size])} />
<IconSvg
className={cs(iconClass ? iconClass : IconClasses[size])}
data-testid={`${name}-svg`}
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a massive W

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So with Vite + Vitest, it actually inlines the svg's so our old way of trying to grab them with findByText('icon.svg) just doesn't work hah


export default setupTestGlobal

process.env.REACT_APP_ZOD_IGNORE_TESTS = 'true'
Copy link
Contributor

Choose a reason for hiding this comment

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

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied over from the Jest test setups ... something I believe @ajay-sentry added in.

Copy link
Contributor

@spalmurray-codecov spalmurray-codecov left a comment

Choose a reason for hiding this comment

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

lgtm couple notes/questions

@nicholas-codecov nicholas-codecov added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit 9d66eb1 Sep 19, 2024
64 checks passed
@nicholas-codecov nicholas-codecov deleted the gh-eng-2126-vitest-setup branch September 19, 2024 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants