-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Migrate from jest to vitest and stop using jsdom based tests #11084
Comments
ref #6040 |
|
ref #11084 Removes usage of `mocha` from eslint plugin
#11412) I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 1: `packages/browser/test/integration/suites/api.js` We have decent coverage around singular calls to these methods, so I just added the tests that validate calling `captureException` and `captureMessage` multiple times. I also fixed a spelling mistake with `dev-packages/browser-integration-tests/suites/public-api/captureException/linkedErrors/subject.js`, `linkedErrrors` -> `linkedErrors` ref #11084
I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 2: `packages/browser/test/integration/suites/breadcrumbs.js` This adds console and history breadcrumb tests (which didn't exist before), and expands upon the dom and xhr/fetch tests, and cleans up some code here and there as well. ref #11084 day 1: #11412
I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 3: `packages/browser/test/integration/suites/config.js` I was surprised we never had `ignoreErrors` or `denyUrls` tests in playwright, so it's good to get the confidence that everything works here. ref #11084 day 2: #11436
This ports `packages/browser/test/integration/suites/loader.js` and `packages/browser/test/integration/suites/loader-specific.js` to playwright. Specifically it just adds tests for SDK source and breadcrumbs, which were missing previously. ref #11084
ref getsentry#11084 Removes usage of `mocha` from eslint plugin
getsentry#11412) I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 1: `packages/browser/test/integration/suites/api.js` We have decent coverage around singular calls to these methods, so I just added the tests that validate calling `captureException` and `captureMessage` multiple times. I also fixed a spelling mistake with `dev-packages/browser-integration-tests/suites/public-api/captureException/linkedErrors/subject.js`, `linkedErrrors` -> `linkedErrors` ref getsentry#11084
I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 2: `packages/browser/test/integration/suites/breadcrumbs.js` This adds console and history breadcrumb tests (which didn't exist before), and expands upon the dom and xhr/fetch tests, and cleans up some code here and there as well. ref getsentry#11084 day 1: getsentry#11412
…ry#11449) I want to remove the karma/mocha based tests in the browser package. To accomplish this, I'll be porting 1 test suite a day from the old integration tests to playwright. Today is Day 3: `packages/browser/test/integration/suites/config.js` I was surprised we never had `ignoreErrors` or `denyUrls` tests in playwright, so it's good to get the confidence that everything works here. ref getsentry#11084 day 2: getsentry#11436
ref #11084 This test ports `packages/browser/test/integration/suites/onunhandledrejection.js` playwright. Because of the same limitations as outlined with the on error tests #11666, I had to use calls to `window.onunhandledrejection` to simulate these tests instead of just using `Promise.reject` to test the handler. #11678 tracks being able to fix this so we can avoid directly calling `window.onunhandledrejection` to test. As `onunhandledrejection.js` was the last suite to use the old integration tests, I fully removed that code and the corresponding GH action workflow. I also removed the monorepo deps on `karma`, `chai` and `sinon`. Extremely satisfying.
Before: `Time: 2.621 s` After: `Duration 638ms (transform 343ms, setup 0ms, collect 1.61s, tests 22ms, environment 0ms, prepare 278ms)` ref #11084 Also removes `edge-runtime/jest-environment` which we weren't using anyway, removes a lot of unnecessary stuff in our `yarn.lock` (-151 lines!)
@AbhiPrasad Replay was migrated here: #11899 edit though we are using globals and not importing everything from |
As per https://vitest.dev/config/#globals > By default, vitest does not provide global APIs for explicitness I think we should follow vitest defaults here and explicitly import in the APIs that we need. This refactors our Solid SDK tests to do so. ref #11084 This change also removes `environment: 'jsdom'` from the vite config as it seems nothing needs this for solid. This should means that our tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour.
As per https://vitest.dev/config/#globals > By default, vitest does not provide global APIs for explicitness I think we should follow vitest defaults here and explicitly import in the APIs that we need. This refactors our Svelte SDK tests to do so. ref #11084 This change also removes `environment: 'jsdom'` from the vite config in favour of explicitly adding jsdom environment via the `@vitest-environment` pragma to the specific test file that needs it. This should means that our server tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour. I was also getting some ts errors in the tests, so addressed those as well.
As per https://vitest.dev/config/#globals > By default, vitest does not provide global APIs for explicitness I think we should follow vitest defaults here and explicitly import in the APIs that we need. This refactors our Nestjs SDK tests to do so. ref #11084
Looks like the task list needs updating because Node v14 doesn't support vitest? |
I updated it - looks like we are stuck with jest longer than I thought. |
Almost everything is now migrated to Vitest. There are a couple of packages where I've created branches to migrate them but got stuck on some blockers:
|
maybe you can try the hack I added for gatsby that patches sentry-javascript/packages/gatsby/test/gatsby-node.test.ts Lines 3 to 28 in ba4586f
These tests are so hard to debug 😬 I'd be open to try to just completely rewrite them.
let's open a draft PR for this one, we can ask Luca and Charly to help take a look given they have more experience with these tests. |
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 trapsjest
does in terms of esm compatibility. Example attempt with Vue SDK: #11071In 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 byvitest
themselves. We should instead use direct imports likeimport { describe, test, expect } from 'vitest';
.sentry-javascript/tsconfig.dev.json
Line 8 in 780875f
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
We can then tackle the following list in whatever order we want!
Convert to using vitest
@sentry/core
#13434vitest
instead of jest #11899We also have some packages that use
mocha
. We should try to drop that dependency and make them usevitest
Remove mocha
The text was updated successfully, but these errors were encountered: