getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
8.02k stars 1.59k forks source link

Migrate from jest to vitest and stop using jsdom based tests #11084

Open AbhiPrasad opened 8 months ago

AbhiPrasad commented 8 months ago

After v8 gets merged in, let's look at migrating from jest to vitest. vitest is way faster, and doesn't fall into the same traps jest does in terms of esm compatibility. Example attempt with Vue SDK: https://github.com/getsentry/sentry-javascript/pull/11071

In addition, we should stop using jsdom based tests, and instead move tests that rely on the browser to use playwright instead. Simulating jsdom in an node environment always has it's faults, easier to not attempt to do that.

First we should align on a common vitest testing standard. Right now we use set globals via vitest/globals, but this is not recommended by vitest themselves. We should instead use direct imports like import { describe, test, expect } from 'vitest';.

https://github.com/getsentry/sentry-javascript/blob/780875fd9d13ef6be5f7f894b97c48777022f5e9/tsconfig.dev.json#L8

There's probably some other discussion that needs to be done here too. We can validate our decisions by changing our vitest usage in the Astro and SvelteKit SDKs.

### Update existing vitest usage
- [ ] https://github.com/getsentry/sentry-javascript/pull/13093
- [ ] https://github.com/getsentry/sentry-javascript/pull/13214
- [ ] Nuxt SDK
- [ ] https://github.com/getsentry/sentry-javascript/pull/13028
- [ ] SolidStart SDK
- [ ] https://github.com/getsentry/sentry-javascript/pull/13026
- [ ] https://github.com/getsentry/sentry-javascript/pull/12960
- [ ] https://github.com/getsentry/sentry-javascript/pull/13027

We can then tackle the following list in whatever order we want!

### Convert to using vitest
- [x] Angular https://github.com/getsentry/sentry-javascript/pull/11091
- [ ] https://github.com/getsentry/sentry-javascript/pull/13092
- [ ] https://github.com/getsentry/sentry-javascript/issues/13434
- [ ] Browser Utils
- [ ] Feedback
- [ ] Gatsby
- [ ] https://github.com/getsentry/sentry-javascript/issues/13605
- [ ] React
- [ ] https://github.com/getsentry/sentry-javascript/pull/12964
- [ ] https://github.com/getsentry/sentry-javascript/pull/11899
- [ ] https://github.com/getsentry/sentry-javascript/pull/12961
- [ ] https://github.com/getsentry/sentry-javascript/pull/12958
- [ ] https://github.com/getsentry/sentry-javascript/pull/12955
- [x] Wasm

We also have some packages that use mocha. We should try to drop that dependency and make them use vitest

### Remove mocha
- [ ] https://github.com/getsentry/sentry-javascript/pull/11296
- [ ] https://github.com/getsentry/sentry-javascript/pull/11412
- [ ] https://github.com/getsentry/sentry-javascript/pull/11436
- [ ] https://github.com/getsentry/sentry-javascript/pull/11449
- [ ] https://github.com/getsentry/sentry-javascript/pull/11666
- [ ] https://github.com/getsentry/sentry-javascript/pull/11688
- [ ] https://github.com/getsentry/sentry-javascript/pull/11733
- [ ] https://github.com/getsentry/sentry-javascript/pull/11758
AbhiPrasad commented 8 months ago

ref https://github.com/getsentry/sentry-javascript/issues/6040

s1gr1d commented 8 months ago

vistest was already added to Angular here: https://github.com/getsentry/sentry-javascript/pull/11091 I will check it on the list 👍🏻

billyvg commented 4 months ago

@AbhiPrasad Replay was migrated here: https://github.com/getsentry/sentry-javascript/pull/11899

edit though we are using globals and not importing everything from vitest

timfish commented 2 months ago

Looks like the task list needs updating because Node v14 doesn't support vitest?

AbhiPrasad commented 2 months ago

I updated it - looks like we are stuck with jest longer than I thought.