Skip to content

Commit 92ce821

Browse files
authored
test(replay): Switch to explicit vitest imports (#13027)
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 Replay SDK tests to do so. 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 non-browser tests are not polluted with jsdom globals, and that future writers have to explicitly opt-in to the behaviour.
1 parent d570c19 commit 92ce821

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+245
-33
lines changed

packages/replay-internal/test/integration/autoSaveSession.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, describe, expect, test, vi } from 'vitest';
26

37
import { EventType } from '@sentry-internal/rrweb';
48

packages/replay-internal/test/integration/beforeAddRecordingEvent.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
25
import type { MockInstance, MockedFunction } from 'vitest';
6+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
37

48
import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
59
import * as SentryCore from '@sentry/core';

packages/replay-internal/test/integration/coreHandlers/handleAfterSendEvent.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
25
import type { MockInstance } from 'vitest';
6+
import { afterEach, describe, expect, it, vi } from 'vitest';
7+
38
import { useFakeTimers } from '../../utils/use-fake-timers';
49

510
useFakeTimers();

packages/replay-internal/test/integration/coreHandlers/handleBeforeSendEvent.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, describe, expect, it, vi } from 'vitest';
26

37
import { handleBeforeSendEvent } from '../../../src/coreHandlers/handleBeforeSendEvent';
48
import type { ReplayContainer } from '../../../src/replay';

packages/replay-internal/test/integration/coreHandlers/handleGlobalEvent.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6+
17
import { getClient } from '@sentry/core';
28
import type { Event } from '@sentry/types';
39

packages/replay-internal/test/integration/earlyEvents.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { beforeEach, describe, expect, it, vi } from 'vitest';
6+
17
import { BASE_TIMESTAMP } from '..';
28
import { resetSdkMock } from '../mocks/resetSdkMock';
39
import { useFakeTimers } from '../utils/use-fake-timers';

packages/replay-internal/test/integration/errorSampleRate.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
6+
17
import { captureException, getClient } from '@sentry/core';
2-
import { vi } from 'vitest';
38

49
import {
510
BUFFER_CHECKOUT_TIME,

packages/replay-internal/test/integration/eventProcessors.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
26

37
import { getClient, getCurrentScope } from '@sentry/core';
48
import type { Event } from '@sentry/types';

packages/replay-internal/test/integration/events.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
5+
import type { MockInstance } from 'vitest';
6+
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
7+
18
import { getClient } from '@sentry/core';
29

310
import { WINDOW } from '../../src/constants';

packages/replay-internal/test/integration/flush.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { vi } from 'vitest';
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
25
import type { MockedFunction } from 'vitest';
6+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
37

48
import { useFakeTimers } from '../utils/use-fake-timers';
59

0 commit comments

Comments
 (0)