Skip to content

Commit

Permalink
test(e2e): Avoid race conditions when waiting for captured message (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
krystofwoldrich authored Feb 26, 2025
1 parent cbb85b2 commit b4ee16b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
6 changes: 4 additions & 2 deletions samples/react-native/e2e/captureMessage.test.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Envelope, EventItem } from '@sentry/core';
import { device } from 'detox';
import {
createSentryServer,
containingEvent,
containingEventWithAndroidMessage,
} from './utils/mockedSentryServer';
import { tap } from './utils/tap';
import { getItemOfTypeFrom } from './utils/event';
Expand All @@ -17,7 +17,9 @@ describe('Capture message', () => {
beforeAll(async () => {
await device.launchApp();

const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
const envelopePromise = sentryServer.waitForEnvelope(
containingEventWithAndroidMessage('Captured message'),
);
await tap('Capture message');
envelope = await envelopePromise;
});
Expand Down
6 changes: 4 additions & 2 deletions samples/react-native/e2e/captureMessage.test.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Envelope, EventItem } from '@sentry/core';
import { device } from 'detox';
import {
createSentryServer,
containingEvent,
containingEventWithMessage,
} from './utils/mockedSentryServer';
import { tap } from './utils/tap';
import { getItemOfTypeFrom } from './utils/event';
Expand All @@ -17,7 +17,9 @@ describe('Capture message', () => {
beforeAll(async () => {
await device.launchApp();

const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
const envelopePromise = sentryServer.waitForEnvelope(
containingEventWithMessage('Captured message'),
);
await tap('Capture message');
envelope = await envelopePromise;
});
Expand Down
6 changes: 4 additions & 2 deletions samples/react-native/e2e/envelopeHeader.test.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Envelope } from '@sentry/core';
import { device } from 'detox';
import {
createSentryServer,
containingEvent,
containingEventWithAndroidMessage,
} from './utils/mockedSentryServer';
import { HEADER } from './utils/consts';
import { tap } from './utils/tap';
Expand All @@ -17,7 +17,9 @@ describe('Capture message', () => {
beforeAll(async () => {
await device.launchApp();

const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
const envelopePromise = sentryServer.waitForEnvelope(
containingEventWithAndroidMessage('Captured message'),
);

await tap('Capture message');
envelope = await envelopePromise;
Expand Down
6 changes: 4 additions & 2 deletions samples/react-native/e2e/envelopeHeader.test.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Envelope } from '@sentry/core';
import { device } from 'detox';
import {
createSentryServer,
containingEvent,
containingEventWithMessage,
} from './utils/mockedSentryServer';
import { HEADER } from './utils/consts';
import { tap } from './utils/tap';
Expand All @@ -17,7 +17,9 @@ describe('Capture message', () => {
beforeAll(async () => {
await device.launchApp();

const envelopePromise = sentryServer.waitForEnvelope(containingEvent);
const envelopePromise = sentryServer.waitForEnvelope(
containingEventWithMessage('Captured message'),
);

await tap('Capture message');
envelope = await envelopePromise;
Expand Down
21 changes: 21 additions & 0 deletions samples/react-native/e2e/utils/mockedSentryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,27 @@ export function containingEvent(envelope: Envelope) {
return envelope[1].some(item => itemHeaderIsType(item[0], 'event'));
}

export function containingEventWithAndroidMessage(message: string) {
return (envelope: Envelope) =>
envelope[1].some(
item =>
itemHeaderIsType(item[0], 'event') &&
itemBodyIsEvent(item[1]) &&
item[1].message &&
(item[1].message as unknown as { message: string }).message === message,
);
}

export function containingEventWithMessage(message: string) {
return (envelope: Envelope) =>
envelope[1].some(
item =>
itemHeaderIsType(item[0], 'event') &&
itemBodyIsEvent(item[1]) &&
item[1].message === message,
);
}

export function containingTransactionWithName(name: string) {
return (envelope: Envelope) =>
envelope[1].some(
Expand Down

0 comments on commit b4ee16b

Please sign in to comment.