Skip to content
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

test(replay): Switch to explicit vitest imports #13027

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, describe, expect, test, vi } from 'vitest';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockInstance, MockedFunction } from 'vitest';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
import * as SentryCore from '@sentry/core';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockInstance } from 'vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';

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

useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, describe, expect, it, vi } from 'vitest';

import { handleBeforeSendEvent } from '../../../src/coreHandlers/handleBeforeSendEvent';
import type { ReplayContainer } from '../../../src/replay';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';
import type { Event } from '@sentry/types';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { BASE_TIMESTAMP } from '..';
import { resetSdkMock } from '../mocks/resetSdkMock';
import { useFakeTimers } from '../utils/use-fake-timers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { captureException, getClient } from '@sentry/core';
import { vi } from 'vitest';

import {
BUFFER_CHECKOUT_TIME,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient, getCurrentScope } from '@sentry/core';
import type { Event } from '@sentry/types';
Expand Down
7 changes: 7 additions & 0 deletions packages/replay-internal/test/integration/events.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @vitest-environment jsdom
*/

import type { MockInstance } from 'vitest';
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';

import { WINDOW } from '../../src/constants';
Expand Down
6 changes: 5 additions & 1 deletion packages/replay-internal/test/integration/flush.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockedFunction } from 'vitest';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { afterEach, describe, expect, it, vi } from 'vitest';

import { mockSdk } from '../mocks/mockSdk';
import { useFakeTimers } from '../utils/use-fake-timers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import type { MockInstance } from 'vitest';

import { mockSdk } from '../index';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @vitest-environment jsdom
*/

import type { MockedFunction } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';
import type { Transport, TransportMakeRequestResponse } from '@sentry/types';

Expand All @@ -14,7 +21,7 @@ async function advanceTimers(time: number) {
await new Promise(process.nextTick);
}

type MockTransportSend = vi.MockedFunction<Transport['send']>;
type MockTransportSend = MockedFunction<Transport['send']>;

describe('Integration | rate-limiting behaviour', () => {
let replay: ReplayContainer;
Expand Down
8 changes: 7 additions & 1 deletion packages/replay-internal/test/integration/rrweb.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { afterEach, describe, expect, it, vi } from 'vitest';

import { resetSdkMock } from '../mocks/resetSdkMock';
import { useFakeTimers } from '../utils/use-fake-timers';

Expand All @@ -15,7 +21,7 @@ describe('Integration | rrweb', () => {
stickySession: false,
},
});
expect(mockRecord.mock.calls[0][0]).toMatchInlineSnapshot(`
expect(mockRecord.mock.calls[0]?.[0]).toMatchInlineSnapshot(`
{
"blockSelector": ".sentry-block,[data-sentry-block],base[href="/"],img,image,svg,video,object,picture,embed,map,audio,link[rel="icon"],link[rel="apple-touch-icon"]",
"collectFonts": true,
Expand Down
6 changes: 6 additions & 0 deletions packages/replay-internal/test/integration/sampling.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';
import { resetSdkMock } from '../mocks/resetSdkMock';
import { useFakeTimers } from '../utils/use-fake-timers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockInstance, MockedFunction } from 'vitest';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import * as SentryBrowserUtils from '@sentry-internal/browser-utils';
import * as SentryCore from '@sentry/core';
Expand Down
6 changes: 5 additions & 1 deletion packages/replay-internal/test/integration/session.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';
import type { Transport } from '@sentry/types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { shouldFilterRequest } from '../../src/util/shouldFilterRequest';
import { mockSdk } from '../index';

Expand Down
6 changes: 5 additions & 1 deletion packages/replay-internal/test/integration/start.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { getClient } from '@sentry/core';
import type { Transport } from '@sentry/types';
Expand Down
6 changes: 5 additions & 1 deletion packages/replay-internal/test/integration/stop.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockInstance, MockedFunction } from 'vitest';
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';

import * as SentryBrowserUtils from '@sentry-internal/browser-utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { CONSOLE_ARG_MAX_SIZE } from '../../../src/constants';
import { normalizeBreadcrumb, normalizeConsoleBreadcrumb } from '../../../src/coreHandlers/handleBreadcrumbs';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, test, vi } from 'vitest';

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

useFakeTimers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { describe, expect, test } from 'vitest';

import type { HandlerDataDom } from '@sentry/types';

import { handleDom } from '../../../src/coreHandlers/handleDom';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { describe, expect, it } from 'vitest';

import { getKeyboardBreadcrumb } from '../../../src/coreHandlers/handleKeyboardEvent';

describe('Unit | coreHandlers | handleKeyboardEvent', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { SENTRY_XHR_DATA_KEY } from '@sentry-internal/browser-utils';
import type {
Breadcrumb,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, it, vi } from 'vitest';

import { BASE_TIMESTAMP } from '../../..';
import { addBreadcrumbEvent } from '../../../../src/coreHandlers/util/addBreadcrumbEvent';
import type { EventBufferArray } from '../../../../src/eventBuffer/EventBufferArray';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { describe, expect, it, vi } from 'vitest';

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

useFakeTimers();

import { vi } from 'vitest';

import { _getResponseInfo } from '../../../../src/coreHandlers/util/fetchUtils';

describe('Unit | coreHandlers | util | fetchUtils', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { expect, it } from 'vitest';

import { getAttributesToRecord } from '../../../../src/coreHandlers/util/getAttributesToRecord';

it('records only included attributes', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { describe, expect, it } from 'vitest';

import { NETWORK_BODY_MAX_SIZE } from '../../../../src/constants';
import {
buildNetworkRequestOrResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { describe, expect, it } from 'vitest';

import { _parseXhrResponse } from '../../../../src/coreHandlers/util/xhrUtils';

describe('Unit | coreHandlers | util | xhrUtils', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { REPLAY_MAX_EVENT_BUFFER_SIZE } from '../../../src/constants';
import { createEventBuffer } from '../../../src/eventBuffer';
import { EventBufferSizeExceededError } from '../../../src/eventBuffer/error';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/**
* @vitest-environment jsdom
*/

import 'jsdom-worker';

import { describe, expect, it, vi } from 'vitest';

import { BASE_TIMESTAMP } from '../..';
import { REPLAY_MAX_EVENT_BUFFER_SIZE } from '../../../src/constants';
import { createEventBuffer } from '../../../src/eventBuffer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/**
* @vitest-environment jsdom
*/

import 'jsdom-worker';

import type { MockInstance } from 'vitest';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { BASE_TIMESTAMP } from '../..';
import { EventBufferProxy } from '../../../src/eventBuffer/EventBufferProxy';
import { decompress } from '../../utils/compression';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { describe, expect, it } from 'vitest';

import { replayIntegration } from '../../src/integration';

describe('Unit | multipleInstances', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { vi } from 'vitest';
/**
* @vitest-environment jsdom
*/

import type { MockedFunction } from 'vitest';
import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest';

import * as Sentry from '@sentry/core';

Expand All @@ -16,7 +21,7 @@ vi.mock('@sentry/utils', async () => {
};
});

type CaptureEventMockType = vi.MockedFunction<typeof Sentry.captureEvent>;
type CaptureEventMockType = MockedFunction<typeof Sentry.captureEvent>;

describe('Unit | session | createSession', () => {
const captureEventMock: CaptureEventMockType = vi.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/**
* @vitest-environment jsdom
*/

import { afterEach, beforeAll, describe, expect, it } from 'vitest';

import { REPLAY_SESSION_KEY, WINDOW } from '../../../src/constants';
import { fetchSession } from '../../../src/session/fetchSession';

Expand Down
Loading
Loading