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(e2e): Avoid race conditions when waiting for captured message #4595

Merged
merged 35 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cc9543f
chore(samples): Add package scripts for native builds, dsn and testing
krystofwoldrich Feb 18, 2025
c20ac08
Merge branch 'capture-app-start-errors' into kw-simplify-local-sample…
krystofwoldrich Feb 18, 2025
f2a14c9
fix ci
krystofwoldrich Feb 19, 2025
d9fec19
fix android archive path
krystofwoldrich Feb 19, 2025
6b8f314
fix ios build release
krystofwoldrich Feb 19, 2025
25ab23b
fix(sample-e2e): Fix type errors missing sentry/core and afterAll
krystofwoldrich Feb 19, 2025
20a132e
Merge branch 'kw-fix-bad-merge' into kw-simplify-local-sample-testing
krystofwoldrich Feb 19, 2025
8b2227a
fix IOS_DEVICE empty check
krystofwoldrich Feb 20, 2025
d5e8e92
Merge branch 'capture-app-start-errors' into kw-simplify-local-sample…
krystofwoldrich Feb 20, 2025
20e7f55
fix ios archive
krystofwoldrich Feb 20, 2025
56fe4b8
test(e2e): Verify captured Errors Screen transaction
krystofwoldrich Feb 20, 2025
4cfc937
add more tests
krystofwoldrich Feb 21, 2025
b484b07
Merge branch 'capture-app-start-errors' into kw-test-transactions
krystofwoldrich Feb 24, 2025
86a675e
revert dsn change
krystofwoldrich Feb 24, 2025
71fada9
fix lint
krystofwoldrich Feb 24, 2025
0d6f543
remove jest extended from sample e2e tests
krystofwoldrich Feb 24, 2025
c5c93d2
Relax test to expect any type of app start, remove native frames as m…
krystofwoldrich Feb 24, 2025
def6e30
add app, device and react native context smoke tests
krystofwoldrich Feb 24, 2025
3aae5bf
include transaction name in the tests
krystofwoldrich Feb 24, 2025
46782a8
test(e2e): Add auto init from JS tests
krystofwoldrich Feb 24, 2025
6b663e0
test(e2e): Add app start crash test for iOS
krystofwoldrich Feb 24, 2025
bf4ee0d
split ios test config to manual and auto
krystofwoldrich Feb 25, 2025
b7bb5fb
update test job name to include test type
krystofwoldrich Feb 25, 2025
d336903
add test-ios-auto sh script
krystofwoldrich Feb 25, 2025
97e1b30
remove jest extended
krystofwoldrich Feb 25, 2025
9d4c63a
Merge branch 'kw-test-transactions' into kw-add-auto-init-tests-ios
krystofwoldrich Feb 25, 2025
a97e5b3
Merge branch 'kw-add-auto-init-tests-ios' into kw-add-app-start-crash…
krystofwoldrich Feb 25, 2025
0dbd3dc
fix c format
krystofwoldrich Feb 25, 2025
b86c577
Merge remote-tracking branch 'origin/capture-app-start-errors' into k…
krystofwoldrich Feb 25, 2025
a0301bc
fix detox config name doesn't have auto yet
krystofwoldrich Feb 25, 2025
01e28d8
Merge branch 'kw-add-auto-init-tests-ios' into kw-add-app-start-crash…
krystofwoldrich Feb 25, 2025
03cd6ba
add auto postfix to the config
krystofwoldrich Feb 25, 2025
ea022c2
Merge remote-tracking branch 'origin/capture-app-start-errors' into k…
krystofwoldrich Feb 25, 2025
ed2bedb
test(e2e): Avoid race conditions when waiting for captured message
krystofwoldrich Feb 25, 2025
a880707
also apply to envelope header
krystofwoldrich Feb 25, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/sample-application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ jobs:
rn-architecture: 'new'
ios-use-frameworks: 'no-frameworks'
build-type: 'production'
test-command: 'yarn test-ios'
test-command: 'yarn test-ios-manual'

- job-name: 'Test Android Release Manual Init'
platform: android
Expand Down
17 changes: 15 additions & 2 deletions samples/react-native/.detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,26 @@ module.exports = {
},
},
},
'ci.sim': {
'ci.sim.auto': {
device: 'ci.simulator',
app: 'ci.ios',
testRunner: {
args: {
$0: 'jest',
config: 'e2e/jest.config.ios.js',
config: 'e2e/jest.config.ios.auto.js',
},
jest: {
setupTimeout: 120000,
},
},
},
'ci.sim.manual': {
device: 'ci.simulator',
app: 'ci.ios',
testRunner: {
args: {
$0: 'jest',
config: 'e2e/jest.config.ios.manual.js',
},
jest: {
setupTimeout: 120000,
Expand Down
121 changes: 121 additions & 0 deletions samples/react-native/e2e/captureAppStartCrash.test.ios.manual.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { describe, it, beforeAll, expect, afterAll } from '@jest/globals';
import { Envelope, EventItem } from '@sentry/core';
import { device } from 'detox';
import {
createSentryServer,
containingEvent,
} from './utils/mockedSentryServer';
import { getItemOfTypeFrom } from './utils/event';

describe('Capture app start crash', () => {
let sentryServer = createSentryServer();
sentryServer.start();

let envelope: Envelope;

beforeAll(async () => {
const launchConfig = {
launchArgs: {
0: '--sentry-crash-on-start',
},
};

const envelopePromise = sentryServer.waitForEnvelope(containingEvent);

device.launchApp(launchConfig);
device.launchApp(launchConfig); // This launch sends the crash event before the app crashes again

envelope = await envelopePromise;
});

afterAll(async () => {
await sentryServer.close();
});

it('envelope contains sdk metadata', async () => {
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');

expect(item).toEqual([
{
length: expect.any(Number),
type: 'event',
},
expect.objectContaining({
platform: 'cocoa',
sdk: {
features: [],
integrations: [
'SessionReplay',
'WatchdogTerminationTracking',
'Screenshot',
'Crash',
'ANRTracking',
'ViewHierarchy',
'AutoBreadcrumbTracking',
'AutoSessionTracking',
'NetworkTracking',
'AppStartTracking',
'FramesTracking',
],
name: 'sentry.cocoa.react-native',
packages: [
{
name: 'cocoapods:getsentry/sentry.cocoa.react-native',
version: expect.any(String),
},
{
name: 'npm:@sentry/react-native',
version: expect.any(String),
},
],
version: expect.any(String),
},
tags: {
'event.environment': 'native',
'event.origin': 'ios',
},
}),
]);
});

it('envelope contains the expected exception', async () => {
const item = getItemOfTypeFrom<EventItem>(envelope, 'event');

expect(item).toEqual([
{
length: expect.any(Number),
type: 'event',
},
expect.objectContaining({
exception: {
values: expect.arrayContaining([
expect.objectContaining({
mechanism: expect.objectContaining({
handled: false,
meta: {
mach_exception: {
code: 0,
exception: 10,
name: 'EXC_CRASH',
subcode: 0,
},
signal: {
code: 0,
name: 'SIGABRT',
number: 6,
},
},
type: 'nsexception',
}),
stacktrace: expect.objectContaining({
frames: expect.any(Array),
}),
type: 'CrashOnStart',
value: 'This was intentional test crash before JS started.',
}),
]),
},
}),
]);
});
});
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
17 changes: 4 additions & 13 deletions samples/react-native/e2e/jest.config.android.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
const baseConfig = require('./jest.config.base');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
preset: 'ts-jest',
rootDir: '..',
testMatch: [
'<rootDir>/e2e/**/*.test.ts',
'<rootDir>/e2e/**/*.test.android.ts',
],
testTimeout: 120000,
maxWorkers: 1,
globalSetup: 'detox/runners/jest/globalSetup',
globalTeardown: 'detox/runners/jest/globalTeardown',
reporters: ['detox/runners/jest/reporter'],
testEnvironment: 'detox/runners/jest/testEnvironment',
verbose: true,
...baseConfig,
testMatch: [...baseConfig.testMatch, '<rootDir>/e2e/**/*.test.android.ts'],
};
11 changes: 11 additions & 0 deletions samples/react-native/e2e/jest.config.ios.auto.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const baseConfig = require('./jest.config.base');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
testMatch: [
...baseConfig.testMatch,
'<rootDir>/e2e/**/*.test.ios.ts',
'<rootDir>/e2e/**/*.test.ios.auto.ts',
],
};
13 changes: 0 additions & 13 deletions samples/react-native/e2e/jest.config.ios.js

This file was deleted.

11 changes: 11 additions & 0 deletions samples/react-native/e2e/jest.config.ios.manual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const baseConfig = require('./jest.config.base');

/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
...baseConfig,
testMatch: [
...baseConfig.testMatch,
'<rootDir>/e2e/**/*.test.ios.ts',
'<rootDir>/e2e/**/*.test.ios.manual.ts',
],
};
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@
argument = "--sentry-disable-native-start"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "--sentry-crash-on-start"
isEnabled = "NO">
</CommandLineArgument>
</CommandLineArguments>
</LaunchAction>
<ProfileAction
Expand Down
12 changes: 12 additions & 0 deletions samples/react-native/ios/sentryreactnativesample/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ - (BOOL)application:(UIApplication *)application
[RNSentrySDK start];
}

if ([self shoudCrashOnStart]) {
@throw [NSException exceptionWithName:@"CrashOnStart"
reason:@"This was intentional test crash before JS started."
userInfo:nil];
}

self.moduleName = @"sentry-react-native-sample";

self.dependencyProvider = [RCTAppDependencyProvider new];
Expand Down Expand Up @@ -83,4 +89,10 @@ - (BOOL)shouldStartSentry
return ![arguments containsObject:@"--sentry-disable-native-start"];
}

- (BOOL)shoudCrashOnStart
{
NSArray<NSString *> *arguments = [[NSProcessInfo processInfo] arguments];
return [arguments containsObject:@"--sentry-crash-on-start"];
}

@end
2 changes: 1 addition & 1 deletion samples/react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"set-test-dsn-android": "scripts/set-dsn-aos.mjs",
"set-test-dsn-ios": "scripts/set-dsn-ios.mjs",
"test-android": "scripts/test-android.sh",
"test-ios": "scripts/test-ios.sh",
"test-ios-manual": "scripts/test-ios-manual.sh",
"test-ios-auto": "scripts/test-ios-auto.sh",
"lint": "npx eslint . --ext .js,.jsx,.ts,.tsx",
"fix": "eslint . --ext .js,.jsx,.ts,.tsx --fix",
Expand Down
2 changes: 1 addition & 1 deletion samples/react-native/scripts/test-ios-auto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cd "${thisFilePath}/.."

"${thisFilePath}/detect-ios-sim.sh"

detox test --configuration ci.sim --app-launch-args="--sentry-disable-native-start"
detox test --configuration ci.sim.auto --app-launch-args="--sentry-disable-native-start"
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ cd "${thisFilePath}/.."

"${thisFilePath}/detect-ios-sim.sh"

detox test --configuration ci.sim
detox test --configuration ci.sim.manual
Loading