Skip to content
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
254 changes: 0 additions & 254 deletions packages/replay-internal/test.setup.ts

This file was deleted.

45 changes: 14 additions & 31 deletions packages/replay-internal/test/integration/errorSampleRate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import '../utils/mock-internal-setTimeout';
import { captureException, getClient } from '@sentry/core';
import type { MockInstance } from 'vitest';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. this was not imported but still worked, for whatever reason? Now it "correctly" complained about this.

import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
import {
BUFFER_CHECKOUT_TIME,
Expand Down Expand Up @@ -34,15 +35,15 @@ async function waitForFlush() {
}

describe('Integration | errorSampleRate', () => {
beforeAll(() => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated but also incorrect how it was, oops.

vi.useFakeTimers();
});

describe('basic', () => {
let replay: ReplayContainer;
let mockRecord: RecordMock;
let domHandler: DomHandler;

beforeAll(() => {
vi.useFakeTimers();
});

beforeEach(async () => {
({ mockRecord, domHandler, replay } = await resetSdkMock({
replayOptions: {
Expand Down Expand Up @@ -163,14 +164,14 @@ describe('Integration | errorSampleRate', () => {
const ADVANCED_TIME = 86400000;
const optionsEvent = createOptionsEvent(replay);

expect(replay.session.started).toBe(BASE_TIMESTAMP);
expect(replay.session?.started).toBe(BASE_TIMESTAMP);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was also incorrectly not flagged?? weird..


// advance time to make sure replay duration is invalid
vi.advanceTimersByTime(ADVANCED_TIME);

// full snapshot should update session start time
mockRecord.takeFullSnapshot(true);
expect(replay.session.started).toBe(BASE_TIMESTAMP + ADVANCED_TIME);
expect(replay.session?.started).toBe(BASE_TIMESTAMP + ADVANCED_TIME);
expect(replay.recordingMode).toBe('buffer');

// advance so we can flush
Expand Down Expand Up @@ -253,7 +254,7 @@ describe('Integration | errorSampleRate', () => {

await vi.advanceTimersToNextTimerAsync();

expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
replayEventPayload: expect.objectContaining({
replay_type: 'buffer',
Expand Down Expand Up @@ -339,7 +340,7 @@ describe('Integration | errorSampleRate', () => {

await vi.advanceTimersToNextTimerAsync();

expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
replayEventPayload: expect.objectContaining({
replay_type: 'buffer',
Expand All @@ -364,24 +365,6 @@ describe('Integration | errorSampleRate', () => {
},
]),
});

vi.advanceTimersByTime(DEFAULT_FLUSH_MIN_DELAY);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just removed this because it actually irrelevant to this specific test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this behavior get covered in another test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!

// Check that click will not get captured
domHandler({
name: 'click',
event: new Event('click'),
});

await waitForFlush();

// This is still the last replay sent since we passed `continueRecording:
// false`.
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 1 },
replayEventPayload: expect.objectContaining({
replay_type: 'buffer',
}),
});
});

// This tests a regression where we were calling flush indiscriminantly in `stop()`
Expand Down Expand Up @@ -672,7 +655,7 @@ describe('Integration | errorSampleRate', () => {
expect(replay.session?.id).toBe(oldSessionId);

// buffered events
expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
replayEventPayload: expect.objectContaining({
replay_type: 'buffer',
Expand Down Expand Up @@ -709,7 +692,7 @@ describe('Integration | errorSampleRate', () => {
vi.advanceTimersByTime(DEFAULT_FLUSH_MIN_DELAY);
await vi.advanceTimersToNextTimerAsync();

expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingData: JSON.stringify([
{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 },
optionsEvent,
Expand Down Expand Up @@ -762,7 +745,7 @@ describe('Integration | errorSampleRate', () => {
expect(replay.session?.started).toBe(BASE_TIMESTAMP + ELAPSED);

// Does not capture mouse click
expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
replayEventPayload: expect.objectContaining({
// Make sure the old performance event is thrown out
Expand Down Expand Up @@ -846,7 +829,7 @@ describe('Integration | errorSampleRate', () => {
await waitForFlush();

expect(replay.session?.id).toBe(sessionId);
expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
});

Expand Down Expand Up @@ -1047,7 +1030,7 @@ describe('Integration | errorSampleRate', () => {
await vi.advanceTimersToNextTimerAsync();

// Buffered events before error
expect(replay).toHaveSentReplay({
expect(replay).toHaveLastSentReplay({
recordingPayloadHeader: { segment_id: 0 },
recordingData: JSON.stringify([
{ data: { isCheckout: true }, timestamp: BASE_TIMESTAMP, type: 2 },
Expand Down
Loading
Loading