Skip to content

Commit

Permalink
Add integration tests for function identifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Dec 19, 2021
1 parent e232a4e commit fd20fd0
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/integration-tests/suites/stacktraces/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://public@dsn.ingest.sentry.io/1337',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function httpsCall() {
webpackDevServer();
}

const webpackDevServer = () => {
Response.httpCode();
};

class Response {
constructor() {}

static httpCode(params) {
throw new Error('test_err');
}
}

const decodeBlob = function() {
(function readFile() {
httpsCall();
})();
};

try {
decodeBlob();
} catch (err) {
Sentry.captureException(err);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@playwright/test';

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

sentryTest(
'should parse function identifiers that contain protocol names correctly',
async ({ getLocalTestPath, page, browserName }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
browserName === 'chromium'
? [
{ function: '?' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'Function.httpCode' },
]
: browserName === 'firefox'
? [
{ function: '?' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'httpCode' },
]
: [
{ function: 'global code' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'httpCode' },
],
);
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function https() {
webpack();
}

const webpack = () => {
File.http();
};

class File {
constructor() {}

static http(params) {
throw new Error('test_err');
}
}

const blob = function() {
(function file() {
https();
})();
};

try {
blob();
} catch (err) {
Sentry.captureException(err);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@playwright/test';

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

sentryTest(
'should parse function identifiers that are protocol names correctly',
async ({ getLocalTestPath, page, browserName }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
browserName === 'chromium'
? [
{ function: '?' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'Function.http' },
]
: browserName === 'firefox'
? [
{ function: '?' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'http' },
]
: [
{ function: 'global code' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'http' },
],
);
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function foo() {
bar();
}

const bar = () => {
Test.baz();
};

class Test {
constructor() {}

static baz(params) {
throw new Error('test_err');
}
}

const qux = function() {
(() => {
(function() {
foo();
})();
})();
};

try {
qux();
} catch (err) {
Sentry.captureException(err);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@playwright/test';

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

sentryTest('should parse function identifiers correctly', async ({ getLocalTestPath, page, browserName }) => {
const url = await getLocalTestPath({ testDir: __dirname });

const eventData = await getSentryRequest(page, url);

expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
browserName === 'chromium'
? [
{ function: '?' },
{ function: '?' },
{ function: 'qux' },
{ function: '?' },
{ function: '?' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'Function.baz' },
]
: browserName === 'firefox'
? [
{ function: '?' },
{ function: '?' },
{ function: 'qux' },
{ function: 'qux/<' },
{ function: 'qux/</<' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'baz' },
]
: [
{ function: 'global code' },
{ function: '?' },
{ function: 'qux' },
{ function: '?' },
{ function: '?' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'baz' },
],
);
});
11 changes: 11 additions & 0 deletions packages/integration-tests/suites/stacktraces/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>

0 comments on commit fd20fd0

Please sign in to comment.