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

Switch test runner from Jest to Vitest #1694

Merged
merged 11 commits into from
Oct 3, 2024

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Aug 20, 2024

Pull Request

Why?

  • faster, more efficient (unless abused, misused)
  • TS/ESM support out of the box
  • very little configuration required
  • watch mode included
  • works on the same concepts as Jest when it comes to writing tests, so minimal changes needed in test files
  • better maintained due to its simplicity and modern web orientation
  • trusted by popular and battle-tested packages svelte, Nuxt, ...
  • ESM oriented, future proof

I am also getting rid of jsdom tests, we were already skipping Node.js tests when using jsdom and everything else is based on web standards so there isn't really much of a benefit to jsdom. This halves the time tests are running for. I am also planning to parallelize some tests by using multiple indexes on Meilisearch to further speed up tests.

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

@flevi29 flevi29 marked this pull request as ready for review August 20, 2024 13:27
Copy link

codecov bot commented Aug 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.55%. Comparing base (efbaa33) to head (849cdc3).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1694      +/-   ##
==========================================
+ Coverage   97.11%   97.55%   +0.44%     
==========================================
  Files          21       20       -1     
  Lines         831     1513     +682     
  Branches       84      319     +235     
==========================================
+ Hits          807     1476     +669     
- Misses         23       37      +14     
+ Partials        1        0       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flevi29
Copy link
Collaborator Author

flevi29 commented Aug 20, 2024

Coverage is being calculated differently it seems. Vitest uses v8 coverage by default as opposed to Jest which uses Babel with Istanbul. Since the v8 one is part of the engine that parses JS code, it might make some shortcuts, optimize some code away, thus less perceived hits with no real impact otherwise, or so I assume.

Here are some more details: jestjs/jest#11188

@flevi29 flevi29 requested a review from brunoocasali August 20, 2024 14:30
@flevi29
Copy link
Collaborator Author

flevi29 commented Aug 20, 2024

Related #1626

@flevi29 flevi29 added the maintenance Issue about maintenance (CI, tests, refacto...) label Aug 20, 2024
@@ -12,8 +13,6 @@ const index = {
uid: 'movies_test',
};

jest.setTimeout(100 * 1000);
Copy link
Collaborator Author

@flevi29 flevi29 Aug 20, 2024

Choose a reason for hiding this comment

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

EXPLAINER: This is replaced by a global setting in vitest.config.js testTimeout: 100_000, // 100 seconds.

@@ -1,3 +1,4 @@
import { afterAll, expect, test, describe, beforeEach } from 'vitest';
Copy link
Collaborator Author

@flevi29 flevi29 Aug 20, 2024

Choose a reason for hiding this comment

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

EXPLAINER: Vitest default and recommended way is to have explicit imports for these methods.

@flevi29
Copy link
Collaborator Author

flevi29 commented Aug 20, 2024

The biggest drop in coverage is because tests/utils/meilisearch-test-utils.ts is no longer measured. However this is not a source file so we do not care about it.

@flevi29 flevi29 changed the title Switch from Jest to Vitest Switch test runner from Jest to Vitest Aug 21, 2024
brunoocasali
brunoocasali previously approved these changes Sep 15, 2024
Copy link
Member

@brunoocasali brunoocasali left a comment

Choose a reason for hiding this comment

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

+1

Thanks for doing this, very appreciated!

bors merge

@brunoocasali
Copy link
Member

bors cancel

@brunoocasali
Copy link
Member

bors merge

@flevi29 flevi29 force-pushed the jest-to-vitest branch 3 times, most recently from 8c6d851 to ad9ced0 Compare September 24, 2024 14:35
@flevi29 flevi29 added the skip-changelog The PR will not appear in the release changelogs label Sep 25, 2024
@curquiza curquiza removed the skip-changelog The PR will not appear in the release changelogs label Oct 2, 2024
@curquiza
Copy link
Member

curquiza commented Oct 2, 2024

@flevi29 can you fix git conflicts?

@flevi29
Copy link
Collaborator Author

flevi29 commented Oct 2, 2024

@curquiza fixed.

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

bors merge

@@ -45,6 +45,7 @@ jobs:
cache: 'yarn'
- name: Install dependencies
run: yarn --dev
# @TODO: Need to clean up test scripts, they're confusing, and base test is expected to run coverage
Copy link
Member

Choose a reason for hiding this comment

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

Can you remove this and open an issue instead?

@curquiza
Copy link
Member

curquiza commented Oct 2, 2024

@flevi29 sorry, git conflicts again 🙈

@flevi29 flevi29 requested a review from curquiza October 2, 2024 20:00
@flevi29
Copy link
Collaborator Author

flevi29 commented Oct 3, 2024

@curquiza fixed again!

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

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

bors merge

Copy link
Contributor

meili-bors bot commented Oct 3, 2024

@meili-bors meili-bors bot merged commit f4bbd5a into meilisearch:main Oct 3, 2024
7 checks passed
@flevi29 flevi29 deleted the jest-to-vitest branch October 3, 2024 09:48
@flevi29 flevi29 linked an issue Oct 7, 2024 that may be closed by this pull request
2 tasks
@Strift Strift mentioned this pull request Jan 8, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Issue about maintenance (CI, tests, refacto...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move to ESM from CommonJS
3 participants