Skip to content

test(browser): Add integration tests to LinkedErrors #4304

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
92 changes: 0 additions & 92 deletions packages/browser/test/unit/integrations/linkederrors.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { ExtendedError } from '@sentry/types';
import { stub } from 'sinon';

import { BrowserBackend } from '../../../src/backend';
import { LinkedErrors } from '../../../src/integrations/linkederrors';

let linkedErrors: any;
Expand Down Expand Up @@ -49,95 +47,5 @@ describe('LinkedErrors', () => {
linkedErrors._handler(event, hint);
expect(spy.calledOnce).toBe(true);
});

it('should recursively walk error to find linked exceptions and assign them to the event', async () => {
const three: ExtendedError = new SyntaxError('three');

const two: ExtendedError = new TypeError('two');
two.cause = three;

const one: ExtendedError = new Error('one');
one.cause = two;

const originalException = one;
const backend = new BrowserBackend({});
return backend.eventFromException(originalException).then(event => {
const result = linkedErrors._handler(event, {
originalException,
});

// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(result.exception.values.length).toBe(3);
expect(result.exception.values[0].type).toBe('SyntaxError');
expect(result.exception.values[0].value).toBe('three');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('TypeError');
expect(result.exception.values[1].value).toBe('two');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
expect(result.exception.values[2].type).toBe('Error');
expect(result.exception.values[2].value).toBe('one');
expect(result.exception.values[2].stacktrace).toHaveProperty('frames');
});
});

it('should allow to change walk key', async () => {
linkedErrors = new LinkedErrors({
key: 'reason',
});

const three: ExtendedError = new SyntaxError('three');

const two: ExtendedError = new TypeError('two');
two.reason = three;

const one: ExtendedError = new Error('one');
one.reason = two;

const originalException = one;
const backend = new BrowserBackend({});
return backend.eventFromException(originalException).then(event => {
const result = linkedErrors._handler(event, {
originalException,
});

expect(result.exception.values.length).toBe(3);
expect(result.exception.values[0].type).toBe('SyntaxError');
expect(result.exception.values[0].value).toBe('three');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('TypeError');
expect(result.exception.values[1].value).toBe('two');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
expect(result.exception.values[2].type).toBe('Error');
expect(result.exception.values[2].value).toBe('one');
expect(result.exception.values[2].stacktrace).toHaveProperty('frames');
});
});

it('should allow to change stack size limit', async () => {
linkedErrors = new LinkedErrors({
limit: 2,
});

const one: ExtendedError = new Error('one');
const two: ExtendedError = new TypeError('two');
const three: ExtendedError = new SyntaxError('three');
one.cause = two;
two.cause = three;

const backend = new BrowserBackend({});
return backend.eventFromException(one).then(event => {
const result = linkedErrors._handler(event, {
originalException: one,
});

expect(result.exception.values.length).toBe(2);
expect(result.exception.values[0].type).toBe('TypeError');
expect(result.exception.values[0].value).toBe('two');
expect(result.exception.values[0].stacktrace).toHaveProperty('frames');
expect(result.exception.values[1].type).toBe('Error');
expect(result.exception.values[1].value).toBe('one');
expect(result.exception.values[1].stacktrace).toHaveProperty('frames');
});
});
});
});
7 changes: 7 additions & 0 deletions packages/integration-tests/suites/linkederrors/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const three = new SyntaxError('three');

const two = new TypeError('two');
two.cause = three;

const one = new Error('one');
one.cause = two;

Sentry.captureException(one);
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../utils/fixtures';
import { getSentryRequest } from '../../../utils/helpers';

sentryTest('should associate linked exceptions to an event event', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

const exception = eventData.exception;
expect(eventData.exception).toBeDefined();

const exceptionValues = exception!.values!;
expect(exceptionValues).toBeDefined();

// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(exceptionValues.length).toBe(3);
expect(exceptionValues[0].type).toBe('SyntaxError');
expect(exceptionValues[0].value).toBe('three');
expect(exceptionValues[0].stacktrace).toHaveProperty('frames');
expect(exceptionValues[1].type).toBe('TypeError');
expect(exceptionValues[1].value).toBe('two');
expect(exceptionValues[1].stacktrace).toHaveProperty('frames');
expect(exceptionValues[2].type).toBe('Error');
expect(exceptionValues[2].value).toBe('one');
expect(exceptionValues[2].stacktrace).toHaveProperty('frames');
});

sentryTest('should associate linked exceptions to an event event', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

const exception = eventData.exception;
expect(eventData.exception).toBeDefined();

const exceptionValues = exception!.values!;
expect(exceptionValues).toBeDefined();

// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(exceptionValues.length).toBe(3);
expect(exceptionValues[0].type).toBe('SyntaxError');
expect(exceptionValues[0].value).toBe('three');
expect(exceptionValues[0].stacktrace).toHaveProperty('frames');
expect(exceptionValues[1].type).toBe('TypeError');
expect(exceptionValues[1].value).toBe('two');
expect(exceptionValues[1].stacktrace).toHaveProperty('frames');
expect(exceptionValues[2].type).toBe('Error');
expect(exceptionValues[2].value).toBe('one');
expect(exceptionValues[2].stacktrace).toHaveProperty('frames');
});
11 changes: 11 additions & 0 deletions packages/integration-tests/suites/linkederrors/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
</head>
<body>
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions packages/integration-tests/suites/linkederrors/variablekey/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [
new Sentry.Integrations.LinkedErrors({
key: 'reason',
}),
]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const three = new SyntaxError('three');

const two = new TypeError('two');
two.reason = three;

const one = new Error('one');
one.reason = two;

Sentry.captureException(one);
28 changes: 28 additions & 0 deletions packages/integration-tests/suites/linkederrors/variablekey/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../utils/fixtures';
import { getSentryRequest } from '../../../utils/helpers';

sentryTest('should allow to change walk key', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

const exception = eventData.exception;
expect(eventData.exception).toBeDefined();

const exceptionValues = exception!.values!;
expect(exceptionValues).toBeDefined();

// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(exceptionValues.length).toBe(3);
expect(exceptionValues[0].type).toBe('SyntaxError');
expect(exceptionValues[0].value).toBe('three');
expect(exceptionValues[0].stacktrace).toHaveProperty('frames');
expect(exceptionValues[1].type).toBe('TypeError');
expect(exceptionValues[1].value).toBe('two');
expect(exceptionValues[1].stacktrace).toHaveProperty('frames');
expect(exceptionValues[2].type).toBe('Error');
expect(exceptionValues[2].value).toBe('one');
expect(exceptionValues[2].stacktrace).toHaveProperty('frames');
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://[email protected]/1337',
integrations: [
new Sentry.Integrations.LinkedErrors({
limit: 2,
}),
]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const three = new SyntaxError('three');

const two = new TypeError('two');
two.cause = three;

const one = new Error('one');
one.cause = two;

Sentry.captureException(one);
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect } from '@playwright/test';

import { sentryTest } from '../../../utils/fixtures';
import { getSentryRequest } from '../../../utils/helpers';

sentryTest('should allow to change stack size limit', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

const exception = eventData.exception;
expect(eventData.exception).toBeDefined();

const exceptionValues = exception!.values!;
expect(exceptionValues).toBeDefined();

// It shouldn't include root exception, as it's already processed in the event by the main error handler
expect(exceptionValues.length).toBe(2);
expect(exceptionValues[0].type).toBe('TypeError');
expect(exceptionValues[0].value).toBe('two');
expect(exceptionValues[0].stacktrace).toHaveProperty('frames');
expect(exceptionValues[1].type).toBe('Error');
expect(exceptionValues[1].value).toBe('one');
expect(exceptionValues[1].stacktrace).toHaveProperty('frames');
});