Skip to content

Commit f08a252

Browse files
committed
fix integration tests, need to provide TextEncoder in global
1 parent 5c13f93 commit f08a252

File tree

9 files changed

+36
-0
lines changed

9 files changed

+36
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { EventType } from 'rrweb';
2+
import { TextEncoder } from 'util';
23

34
import type { RecordingEvent } from '../../src/types';
45
import { addEvent } from '../../src/util/addEvent';
@@ -8,6 +9,10 @@ import { useFakeTimers } from '../utils/use-fake-timers';
89
useFakeTimers();
910

1011
describe('Integration | autoSaveSession', () => {
12+
beforeAll(() => {
13+
(global as any).TextEncoder = TextEncoder;
14+
});
15+
1116
afterEach(() => {
1217
jest.clearAllMocks();
1318
});

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import type { Event } from '@sentry/types';
3+
import { TextEncoder } from 'util';
34

45
import { REPLAY_EVENT_NAME } from '../../../src/constants';
56
import { handleGlobalEventListener } from '../../../src/coreHandlers/handleGlobalEvent';
@@ -17,6 +18,10 @@ useFakeTimers();
1718
let replay: ReplayContainer;
1819

1920
describe('Integration | coreHandlers | handleGlobalEvent', () => {
21+
beforeAll(() => {
22+
(global as any).TextEncoder = TextEncoder;
23+
});
24+
2025
beforeEach(async () => {
2126
({ replay } = await resetSdkMock({
2227
replayOptions: {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { captureException } from '@sentry/core';
2+
import { TextEncoder } from 'util';
23

34
import { DEFAULT_FLUSH_MIN_DELAY, REPLAY_SESSION_KEY, VISIBILITY_CHANGE_TIMEOUT, WINDOW } from '../../src/constants';
45
import type { ReplayContainer } from '../../src/replay';
@@ -23,6 +24,10 @@ describe('Integration | errorSampleRate', () => {
2324
let mockRecord: RecordMock;
2425
let domHandler: DomHandler;
2526

27+
beforeAll(() => {
28+
(global as any).TextEncoder = TextEncoder;
29+
});
30+
2631
beforeEach(async () => {
2732
({ mockRecord, domHandler, replay } = await resetSdkMock({
2833
replayOptions: {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import type { Event, Hub, Scope } from '@sentry/types';
3+
import { TextEncoder } from 'util';
34

45
import { BASE_TIMESTAMP } from '..';
56
import { resetSdkMock } from '../mocks/resetSdkMock';
@@ -11,6 +12,10 @@ describe('Integration | eventProcessors', () => {
1112
let hub: Hub;
1213
let scope: Scope;
1314

15+
beforeAll(() => {
16+
(global as any).TextEncoder = TextEncoder;
17+
});
18+
1419
beforeEach(() => {
1520
hub = getCurrentHub();
1621
scope = hub.pushScope();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getCurrentHub } from '@sentry/core';
2+
import { TextEncoder } from 'util';
23

34
import { WINDOW } from '../../src/constants';
45
import type { ReplayContainer } from '../../src/replay';
@@ -27,6 +28,7 @@ describe('Integration | events', () => {
2728
let mockSendReplayRequest: MockSendReplayRequest;
2829

2930
beforeAll(async () => {
31+
(global as any).TextEncoder = TextEncoder;
3032
jest.setSystemTime(new Date(BASE_TIMESTAMP));
3133
jest.runAllTimers();
3234
});

packages/replay/test/integration/sendReplayEvent.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getCurrentHub } from '@sentry/core';
22
import type { Transport } from '@sentry/types';
33
import * as SentryUtils from '@sentry/utils';
4+
import { TextEncoder } from 'util';
45

56
import { DEFAULT_FLUSH_MIN_DELAY, SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
67
import type { ReplayContainer } from '../../src/replay';
@@ -27,6 +28,7 @@ describe('Integration | sendReplayEvent', () => {
2728
const { record: mockRecord } = mockRrweb();
2829

2930
beforeAll(async () => {
31+
(global as any).TextEncoder = TextEncoder;
3032
jest.setSystemTime(new Date(BASE_TIMESTAMP));
3133
jest.spyOn(SentryUtils, 'addInstrumentationHandler').mockImplementation((type, handler: (args: any) => any) => {
3234
if (type === 'dom') {

packages/replay/test/integration/session.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getCurrentHub } from '@sentry/core';
22
import type { Transport } from '@sentry/types';
3+
import { TextEncoder } from 'util';
34

45
import {
56
DEFAULT_FLUSH_MIN_DELAY,
@@ -31,6 +32,10 @@ describe('Integration | session', () => {
3132
let domHandler: (args: any) => any;
3233
let mockRecord: RecordMock;
3334

35+
beforeAll(() => {
36+
(global as any).TextEncoder = TextEncoder;
37+
});
38+
3439
beforeEach(async () => {
3540
({ mockRecord, domHandler, replay } = await resetSdkMock({
3641
replayOptions: {

packages/replay/test/integration/stop.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as SentryUtils from '@sentry/utils';
2+
import { TextEncoder } from 'util';
23

34
import type { Replay } from '../../src';
45
import { SESSION_IDLE_DURATION, WINDOW } from '../../src/constants';
@@ -22,6 +23,7 @@ describe('Integration | stop', () => {
2223
let mockAddInstrumentationHandler: MockAddInstrumentationHandler;
2324

2425
beforeAll(async () => {
26+
(global as any).TextEncoder = TextEncoder;
2527
jest.setSystemTime(new Date(BASE_TIMESTAMP));
2628
mockAddInstrumentationHandler = jest.spyOn(
2729
SentryUtils,

packages/replay/test/unit/util/createReplayEnvelope.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ReplayEvent } from '@sentry/types';
22
import { makeDsn } from '@sentry/utils';
3+
import { TextEncoder } from 'util';
34

45
import { createReplayEnvelope } from '../../../src/util/createReplayEnvelope';
56

@@ -41,6 +42,10 @@ describe('Unit | util | createReplayEnvelope', () => {
4142
publicKey: 'abc',
4243
});
4344

45+
beforeAll(() => {
46+
(global as any).TextEncoder = TextEncoder;
47+
});
48+
4449
it('creates an envelope for a given Replay event', () => {
4550
const envelope = createReplayEnvelope(replayEvent, payloadWithSequence, dsn);
4651

0 commit comments

Comments
 (0)