Skip to content

docs(guides): add vitest integration example #937

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

danielpza
Copy link
Contributor

Added vitest integration example

Also linked to the https://github.com/danielpza/vitest-mms package which aims to make it easier to setup up mongodb-memory-server with vitest (DISCLAIMER: I'm the author of the package, I can drop it if that's an issue)

@danielpza danielpza requested review from hasezoey and nodkz as code owners July 20, 2025 07:15
Copy link

codecov bot commented Jul 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.85%. Comparing base (e4992fd) to head (c13aae9).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #937      +/-   ##
==========================================
+ Coverage   90.76%   90.85%   +0.09%     
==========================================
  Files          15       15              
  Lines        2035     2035              
  Branches      513      513              
==========================================
+ Hits         1847     1849       +2     
+ Misses        188      175      -13     
- Partials        0       11      +11     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hasezoey hasezoey added the docs This issue/pr is about documentation label Jul 20, 2025
Copy link
Member

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

Thanks for adding a integration example for vitest. Please note that i have not used vitest yet.

(DISCLAIMER: I'm the author of the package, I can drop it if that's an issue)

No problem, just as noted below, please update with a little description.

Comment on lines +146 to +148
## vitest

For [vitest](https://vitest.dev/), create a [global setup file](https://vitest.dev/config/#globalsetup).
Copy link
Member

Choose a reason for hiding this comment

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

Please add a badge similar to jest and mocha:

<span class="badge badge--secondary">jest version 29</span>

});
```

See also [vitest-mms](https://github.com/danielpza/vitest-mms)
Copy link
Member

@hasezoey hasezoey Jul 20, 2025

Choose a reason for hiding this comment

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

Instead of just a simple see also, could you add a simple explanation on why this should be a see also, like a little description of what this package is doing / can be used for?

});
```

See also [vitest-mms](https://github.com/danielpza/vitest-mms)
Copy link
Member

Choose a reason for hiding this comment

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

Please add a note similar to jests tests and global setup do not share a environment:

:::note
Keep in mind that jest's global-setup and global-teardown do **not** share a environment with the tests themself, and so require `setupFile` / `setupFilesAfterEnv` to actually connect.
:::

re:

Beware that the global setup is running in a different global scope, so your tests don't have access to variables defined here. However, you can pass down serializable data to tests via provide method:
Source: the warning

`globalSetup.ts`:

```ts
import type { TestProject } from 'vitest/node';
Copy link
Member

@hasezoey hasezoey Jul 20, 2025

Choose a reason for hiding this comment

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

Import for mongodb-memory-server missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue/pr is about documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants