Skip to content

Commit 7d84dc3

Browse files
committed
Add initial integration tests for @sentry/browser public API.
1 parent 7f1fe2d commit 7d84dc3

File tree

88 files changed

+1108
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1108
-18
lines changed

packages/integration-tests/suites/demo/tmp/subject.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/integration-tests/suites/demo/tmp/test.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sentry.addBreadcrumb({});
2+
3+
Sentry.captureMessage('test_empty_obj');
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(
7+
'should add an empty breadcrumb initialized with a timestamp, when an empty object is given',
8+
async ({ getLocalTestPath, page }) => {
9+
const url = await getLocalTestPath({ testDir: __dirname });
10+
11+
const eventData = await getSentryRequest(page, url);
12+
13+
expect(eventData.breadcrumbs).toHaveLength(1);
14+
expect(eventData.breadcrumbs?.[0]).toMatchObject({
15+
timestamp: expect.any(Number),
16+
});
17+
18+
expect(eventData.message).toBe('test_empty_obj');
19+
},
20+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Sentry.addBreadcrumb({
2+
category: 'foo',
3+
message: 'bar',
4+
level: 'baz',
5+
});
6+
7+
Sentry.addBreadcrumb({
8+
category: 'qux',
9+
});
10+
11+
Sentry.captureMessage('test_multi_breadcrumbs');
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should add multiple breadcrumbs', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.breadcrumbs).toHaveLength(2);
12+
expect(eventData.breadcrumbs?.[0]).toMatchObject({
13+
category: 'foo',
14+
message: 'bar',
15+
level: 'baz',
16+
});
17+
expect(eventData.breadcrumbs?.[1]).toMatchObject({
18+
category: 'qux',
19+
});
20+
expect(eventData.message).toBe('test_multi_breadcrumbs');
21+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sentry.addBreadcrumb({
2+
category: 'foo',
3+
message: 'bar',
4+
level: 'baz',
5+
});
6+
7+
Sentry.captureMessage('test');
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should add a simple breadcrumb', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.breadcrumbs).toHaveLength(1);
12+
expect(eventData.breadcrumbs?.[0]).toMatchObject({
13+
category: 'foo',
14+
message: 'bar',
15+
level: 'baz',
16+
});
17+
expect(eventData.message).toBe('test');
18+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Sentry.addBreadcrumb();
2+
3+
Sentry.captureMessage('test_undefined_arg');
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(
7+
'should add an empty breadcrumb initialized with a timestamp, when no argument is given',
8+
async ({ getLocalTestPath, page }) => {
9+
const url = await getLocalTestPath({ testDir: __dirname });
10+
11+
const eventData = await getSentryRequest(page, url);
12+
13+
expect(eventData.breadcrumbs).toHaveLength(1);
14+
expect(eventData.breadcrumbs?.[0]).toMatchObject({
15+
timestamp: expect.any(Number),
16+
});
17+
18+
expect(eventData.message).toBe('test_undefined_arg');
19+
},
20+
);
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+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
beforeSend: (event, hint) => {
8+
event.hint = hint;
9+
return event;
10+
},
11+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
try {
2+
undefinedFn();
3+
} catch (err) {
4+
Sentry.captureException(err, { foo: 'bar' });
5+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect } from '@playwright/test';
2+
import { EventHint } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getSentryRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture an error with provided hint context', async ({ getLocalTestPath, page, browserName }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const eventData = await getSentryRequest(page, url);
11+
12+
expect(eventData.exception?.values).toHaveLength(1);
13+
expect(eventData.exception?.values?.[0]).toMatchObject({
14+
type: 'ReferenceError',
15+
value: browserName === 'webkit' ? `Can't find variable: undefinedFn` : 'undefinedFn is not defined',
16+
mechanism: {
17+
type: 'generic',
18+
handled: true,
19+
},
20+
stacktrace: {
21+
frames: expect.any(Array),
22+
},
23+
});
24+
expect((eventData as Event & { hint: EventHint }).hint.captureContext).toMatchObject({
25+
foo: 'bar',
26+
});
27+
});
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureMessage('foo');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 message string', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('foo');
12+
expect(eventData.level).toBe('info');
13+
});
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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
beforeSend: (event, hint) => {
8+
event.hint = hint;
9+
return event;
10+
},
11+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sentry.captureMessage('message_with_hint', { foo: 'bar', level: 'error' });
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from '@playwright/test';
2+
import { EventHint } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getSentryRequest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture a message with provided hint', async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
const eventData = await getSentryRequest(page, url);
10+
11+
expect(eventData.message).toBe('message_with_hint');
12+
expect(eventData.level).toBe('error');
13+
expect((eventData as Event & { hint: EventHint }).hint.captureContext).toMatchObject({
14+
foo: 'bar',
15+
level: 'error',
16+
});
17+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
window.events = [];
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
beforeSend: event => {
9+
window.events.push(event);
10+
},
11+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sentry.captureMessage('debug_message', 'debug');
2+
Sentry.captureMessage('info_message', 'info');
3+
Sentry.captureMessage('warning_message', 'warning');
4+
Sentry.captureMessage('error_message', 'error');
5+
Sentry.captureMessage('fatal_message', 'fatal');
6+
Sentry.captureMessage('critical_message', 'critical');
7+
Sentry.captureMessage('log_message', 'log');
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryEvents } from '../../../../utils/helpers';
5+
6+
sentryTest('should capture with different severity levels', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const events = await getSentryEvents(page, url);
10+
11+
expect(events[0].message).toBe('debug_message');
12+
expect(events[0].level).toBe('debug');
13+
14+
expect(events[1].message).toBe('info_message');
15+
expect(events[1].level).toBe('info');
16+
17+
expect(events[2].message).toBe('warning_message');
18+
expect(events[2].level).toBe('warning');
19+
20+
expect(events[3].message).toBe('error_message');
21+
expect(events[3].level).toBe('error');
22+
23+
expect(events[4].message).toBe('fatal_message');
24+
expect(events[4].level).toBe('fatal');
25+
26+
expect(events[5].message).toBe('critical_message');
27+
expect(events[5].level).toBe('critical');
28+
29+
expect(events[6].message).toBe('log_message');
30+
expect(events[6].level).toBe('log');
31+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Sentry.configureScope(scope => {
2+
scope.setTag('foo', 'bar');
3+
scope.setUser({ id: 'baz' });
4+
scope.setExtra('qux', 'quux');
5+
scope.clear();
6+
});
7+
8+
Sentry.captureMessage('cleared_scope');

0 commit comments

Comments
 (0)