Skip to content

Commit accf5af

Browse files
authored
test(browser): Add integration tests for captureException (#4352)
1 parent 4cd71c5 commit accf5af

File tree

8 files changed

+88
-0
lines changed

8 files changed

+88
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureException({});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should capture an empty object', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.exception?.values).toHaveLength(1);
12+
expect(eventData.exception?.values?.[0]).toMatchObject({
13+
type: 'Error',
14+
value: 'Non-Error exception captured with keys: [object has no keys]',
15+
mechanism: {
16+
type: 'generic',
17+
handled: true,
18+
},
19+
});
20+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
try {
2+
throw Error('test_simple_error');
3+
} catch (err) {
4+
Sentry.captureException(err);
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should capture a simple error with message', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.exception?.values).toHaveLength(1);
12+
expect(eventData.exception?.values?.[0]).toMatchObject({
13+
type: 'Error',
14+
value: 'test_simple_error',
15+
mechanism: {
16+
type: 'generic',
17+
handled: true,
18+
},
19+
stacktrace: {
20+
frames: expect.any(Array),
21+
},
22+
});
23+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
7+
</head>
8+
<body>
9+
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
10+
</body>
11+
</html>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureException();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should capture an undefined error when no arguments are provided', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.exception?.values).toHaveLength(1);
12+
expect(eventData.exception?.values?.[0]).toMatchObject({
13+
type: 'Error',
14+
value: 'undefined',
15+
mechanism: {
16+
type: 'generic',
17+
handled: true,
18+
},
19+
});
20+
});

0 commit comments

Comments
 (0)