Skip to content

Commit 859ec81

Browse files
Zen-cronicLms24
authored andcommitted
test(browser): Add error event test
1 parent cc67bfe commit 859ec81

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

dev-packages/e2e-tests/test-applications/default-browser/build.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ webpack(
1717
minimize: true,
1818
minimizer: [new TerserPlugin()],
1919
},
20-
plugins: [new webpack.EnvironmentPlugin(['E2E_TEST_DSN']), new HtmlWebpackPlugin()],
20+
plugins: [
21+
new webpack.EnvironmentPlugin(['E2E_TEST_DSN']),
22+
new HtmlWebpackPlugin({
23+
template: path.join(__dirname, 'public/index.html'),
24+
}),
25+
],
2126
mode: 'production',
2227
},
2328
(err, stats) => {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Default Browser App</title>
7+
</head>
8+
<body>
9+
<div id="app"></div>
10+
11+
<input type="button" value="Capture Exception" id="exception-button" />
12+
13+
<!-- The script tags for the bundled JavaScript files will be injected here by HtmlWebpackPlugin in build.mjs-->
14+
</body>
15+
</html>

dev-packages/e2e-tests/test-applications/default-browser/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Sentry.init({
77
integrations: [Sentry.browserTracingIntegration()],
88
});
99

10-
setTimeout(() => {
10+
document.getElementById('exception-button').addEventListener('click', () => {
1111
throw new Error('I am an error!');
12-
}, 2000);
12+
});
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
import { expect, test } from '@playwright/test';
2+
import { waitForError } from '@sentry-internal/test-utils';
23

3-
test('testing', () => {
4-
expect(true).toBe(true);
4+
test('Should send correct error event', async ({ page }) => {
5+
const errorEventPromise = waitForError('default-browser', event => {
6+
return !event.type && event.exception?.values?.[0]?.value === 'I am an error!';
7+
});
8+
9+
await page.goto('/');
10+
11+
const exceptionButton = page.locator('id=exception-button');
12+
await exceptionButton.click();
13+
14+
const errorEvent = await errorEventPromise;
15+
16+
expect(errorEvent.exception?.values).toHaveLength(1);
17+
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!');
18+
19+
expect(errorEvent.transaction).toBe('/');
20+
21+
expect(errorEvent.request).toEqual({
22+
url: 'http://localhost:3030/',
23+
headers: expect.any(Object),
24+
});
25+
26+
expect(errorEvent.contexts?.trace).toEqual({
27+
trace_id: expect.any(String),
28+
span_id: expect.any(String),
29+
});
530
});

0 commit comments

Comments
 (0)