Skip to content

Commit 21b0dae

Browse files
authored
test(browser): Switch from jest to vitest (#13092)
Before: `Time: 10.517 s` After: `Duration 3.65s (transform 2.76s, setup 7ms, collect 15.44s, tests 1.36s, environment 4.96s, prepare 3.63s)` We also change the folder structure of the browser unit tests, because we've removed the in-package integration tests. This change also removes `environment: 'jsdom'` from the central 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 tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour.
1 parent 6285808 commit 21b0dae

36 files changed

+303
-226
lines changed

packages/browser/jest.config.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/browser/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@
7070
"fix": "eslint . --format stylish --fix",
7171
"lint": "eslint . --format stylish",
7272
"size:check": "cat build/bundles/bundle.min.js | gzip -9 | wc -c | awk '{$1=$1/1024; print \"ES2017: \",$1,\"kB\";}'",
73-
"test": "yarn test:unit",
74-
"test:unit": "jest",
75-
"test:unit:watch": "jest --watch",
73+
"test": "vitest run",
74+
"test:watch": "vitest --watch",
7675
"yalc:publish": "yalc publish --push --sig"
7776
},
7877
"volta": {

packages/browser/test/unit/eventbuilder.test.ts renamed to packages/browser/test/eventbuilder.test.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import { defaultStackParser } from '../../src';
2-
import { eventFromUnknownInput } from '../../src/eventbuilder';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
34

4-
jest.mock('@sentry/core', () => {
5-
const original = jest.requireActual('@sentry/core');
5+
import { afterEach, describe, expect, it, vi } from 'vitest';
6+
7+
import { defaultStackParser } from '../src';
8+
import { eventFromUnknownInput } from '../src/eventbuilder';
9+
10+
vi.mock('@sentry/core', async requireActual => {
611
return {
7-
...original,
12+
...((await requireActual()) as any),
813
getClient() {
914
return {
1015
getOptions(): any {
@@ -21,7 +26,7 @@ class MyTestClass {
2126
}
2227

2328
afterEach(() => {
24-
jest.resetAllMocks();
29+
vi.resetAllMocks();
2530
});
2631

2732
describe('eventFromUnknownInput', () => {

packages/browser/test/unit/helper/browser-client-options.ts renamed to packages/browser/test/helper/browser-client-options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createTransport } from '@sentry/core';
22
import { resolvedSyncPromise } from '@sentry/utils';
33

4-
import type { BrowserClientOptions } from '../../../src/client';
4+
import type { BrowserClientOptions } from '../../src/client';
55

66
export function getDefaultBrowserClientOptions(options: Partial<BrowserClientOptions> = {}): BrowserClientOptions {
77
return {

packages/browser/test/unit/index.bundle.feedback.test.ts renamed to packages/browser/test/index.bundle.feedback.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { browserTracingIntegrationShim, replayIntegrationShim } from '@sentry-internal/integration-shims';
2-
import { feedbackAsyncIntegration } from '../../src';
4+
import { feedbackAsyncIntegration } from '../src';
35

4-
import * as FeedbackBundle from '../../src/index.bundle.feedback';
6+
import * as FeedbackBundle from '../src/index.bundle.feedback';
57

68
describe('index.bundle.feedback', () => {
79
it('has correct exports', () => {

packages/browser/test/unit/index.bundle.replay.test.ts renamed to packages/browser/test/index.bundle.replay.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { browserTracingIntegrationShim, feedbackIntegrationShim } from '@sentry-internal/integration-shims';
2-
import { replayIntegration } from '../../src';
4+
import { replayIntegration } from '../src';
35

4-
import * as ReplayBundle from '../../src/index.bundle.replay';
6+
import * as ReplayBundle from '../src/index.bundle.replay';
57

68
describe('index.bundle.replay', () => {
79
it('has correct exports', () => {

packages/browser/test/unit/index.bundle.test.ts renamed to packages/browser/test/index.bundle.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import {
24
browserTracingIntegrationShim,
35
feedbackIntegrationShim,
46
replayIntegrationShim,
57
} from '@sentry-internal/integration-shims';
68

7-
import * as Bundle from '../../src/index.bundle';
9+
import * as Bundle from '../src/index.bundle';
810

911
describe('index.bundle', () => {
1012
it('has correct exports', () => {

packages/browser/test/unit/index.bundle.tracing.replay.feedback.test.ts renamed to packages/browser/test/index.bundle.tracing.replay.feedback.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { browserTracingIntegration, feedbackAsyncIntegration, replayIntegration } from '../../src';
1+
import { describe, expect, it } from 'vitest';
22

3-
import * as TracingReplayFeedbackBundle from '../../src/index.bundle.tracing.replay.feedback';
3+
import { browserTracingIntegration, feedbackAsyncIntegration, replayIntegration } from '../src';
4+
5+
import * as TracingReplayFeedbackBundle from '../src/index.bundle.tracing.replay.feedback';
46

57
describe('index.bundle.tracing.replay.feedback', () => {
68
it('has correct exports', () => {

packages/browser/test/unit/index.bundle.tracing.replay.test.ts renamed to packages/browser/test/index.bundle.tracing.replay.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { feedbackIntegrationShim } from '@sentry-internal/integration-shims';
2-
import { browserTracingIntegration, replayIntegration } from '../../src';
4+
import { browserTracingIntegration, replayIntegration } from '../src';
35

4-
import * as TracingReplayBundle from '../../src/index.bundle.tracing.replay';
6+
import * as TracingReplayBundle from '../src/index.bundle.tracing.replay';
57

68
describe('index.bundle.tracing.replay', () => {
79
it('has correct exports', () => {

packages/browser/test/unit/index.bundle.tracing.test.ts renamed to packages/browser/test/index.bundle.tracing.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { describe, expect, it } from 'vitest';
2+
13
import { feedbackIntegrationShim, replayIntegrationShim } from '@sentry-internal/integration-shims';
2-
import { browserTracingIntegration } from '../../src';
4+
import { browserTracingIntegration } from '../src';
35

4-
import * as TracingBundle from '../../src/index.bundle.tracing';
6+
import * as TracingBundle from '../src/index.bundle.tracing';
57

68
describe('index.bundle.tracing', () => {
79
it('has correct exports', () => {

0 commit comments

Comments
 (0)