Skip to content

Commit 537da47

Browse files
committed
Add runIn* fixtures for browser-specific logic.
1 parent 2490499 commit 537da47

File tree

4 files changed

+148
-108
lines changed
  • packages/integration-tests

4 files changed

+148
-108
lines changed

packages/integration-tests/suites/stacktraces/protocol_containing_fn_identifiers/test.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,47 @@ import { getSentryRequest } from '../../../utils/helpers';
55

66
sentryTest(
77
'should parse function identifiers that contain protocol names correctly',
8-
async ({ getLocalTestPath, page, browserName }) => {
8+
async ({ getLocalTestPath, page, runInChromium, runInFirefox, runInWebkit }) => {
99
const url = await getLocalTestPath({ testDir: __dirname });
1010

1111
const eventData = await getSentryRequest(page, url);
12+
const frames = eventData.exception?.values?.[0].stacktrace?.frames;
1213

13-
expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
14-
browserName === 'chromium'
15-
? [
16-
{ function: '?' },
17-
{ function: '?' },
18-
{ function: 'decodeBlob' },
19-
{ function: 'readFile' },
20-
{ function: 'httpsCall' },
21-
{ function: 'webpackDevServer' },
22-
{ function: 'Function.httpCode' },
23-
]
24-
: browserName === 'firefox'
25-
? [
26-
{ function: '?' },
27-
{ function: '?' },
28-
{ function: 'decodeBlob' },
29-
{ function: 'readFile' },
30-
{ function: 'httpsCall' },
31-
{ function: 'webpackDevServer' },
32-
{ function: 'httpCode' },
33-
]
34-
: [
35-
{ function: 'global code' },
36-
{ function: '?' },
37-
{ function: 'decodeBlob' },
38-
{ function: 'readFile' },
39-
{ function: 'httpsCall' },
40-
{ function: 'webpackDevServer' },
41-
{ function: 'httpCode' },
42-
],
43-
);
14+
runInChromium(() => {
15+
expect(frames).toMatchObject([
16+
{ function: '?' },
17+
{ function: '?' },
18+
{ function: 'decodeBlob' },
19+
{ function: 'readFile' },
20+
{ function: 'httpsCall' },
21+
{ function: 'webpackDevServer' },
22+
{ function: 'Function.httpCode' },
23+
]);
24+
});
25+
26+
runInFirefox(() => {
27+
expect(frames).toMatchObject([
28+
{ function: '?' },
29+
{ function: '?' },
30+
{ function: 'decodeBlob' },
31+
{ function: 'readFile' },
32+
{ function: 'httpsCall' },
33+
{ function: 'webpackDevServer' },
34+
{ function: 'httpCode' },
35+
]);
36+
});
37+
38+
runInWebkit(() => {
39+
expect(frames).toMatchObject([
40+
{ function: 'global code' },
41+
{ function: '?' },
42+
{ function: 'decodeBlob' },
43+
{ function: 'readFile' },
44+
{ function: 'httpsCall' },
45+
{ function: 'webpackDevServer' },
46+
{ function: 'httpCode' },
47+
]);
48+
});
4449
},
4550
);
4651

packages/integration-tests/suites/stacktraces/protocol_fn_identifiers/test.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,47 @@ import { getSentryRequest } from '../../../utils/helpers';
55

66
sentryTest(
77
'should parse function identifiers that are protocol names correctly',
8-
async ({ getLocalTestPath, page, browserName }) => {
8+
async ({ getLocalTestPath, page, runInChromium, runInFirefox, runInWebkit }) => {
99
const url = await getLocalTestPath({ testDir: __dirname });
1010

1111
const eventData = await getSentryRequest(page, url);
12+
const frames = eventData.exception?.values?.[0].stacktrace?.frames;
1213

13-
expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
14-
browserName === 'chromium'
15-
? [
16-
{ function: '?' },
17-
{ function: '?' },
18-
{ function: 'blob' },
19-
{ function: 'file' },
20-
{ function: 'https' },
21-
{ function: 'webpack' },
22-
{ function: 'Function.http' },
23-
]
24-
: browserName === 'firefox'
25-
? [
26-
{ function: '?' },
27-
{ function: '?' },
28-
{ function: 'blob' },
29-
{ function: 'file' },
30-
{ function: 'https' },
31-
{ function: 'webpack' },
32-
{ function: 'http' },
33-
]
34-
: [
35-
{ function: 'global code' },
36-
{ function: '?' },
37-
{ function: 'blob' },
38-
{ function: 'file' },
39-
{ function: 'https' },
40-
{ function: 'webpack' },
41-
{ function: 'http' },
42-
],
43-
);
14+
runInChromium(() => {
15+
expect(frames).toMatchObject([
16+
{ function: '?' },
17+
{ function: '?' },
18+
{ function: 'blob' },
19+
{ function: 'file' },
20+
{ function: 'https' },
21+
{ function: 'webpack' },
22+
{ function: 'Function.http' },
23+
]);
24+
});
25+
26+
runInFirefox(() => {
27+
expect(frames).toMatchObject([
28+
{ function: '?' },
29+
{ function: '?' },
30+
{ function: 'blob' },
31+
{ function: 'file' },
32+
{ function: 'https' },
33+
{ function: 'webpack' },
34+
{ function: 'http' },
35+
]);
36+
});
37+
38+
runInWebkit(() => {
39+
expect(frames).toMatchObject([
40+
{ function: 'global code' },
41+
{ function: '?' },
42+
{ function: 'blob' },
43+
{ function: 'file' },
44+
{ function: 'https' },
45+
{ function: 'webpack' },
46+
{ function: 'http' },
47+
]);
48+
});
4449
},
4550
);
4651

packages/integration-tests/suites/stacktraces/regular_fn_identifiers/test.ts

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,54 @@ import { expect } from '@playwright/test';
33
import { sentryTest } from '../../../utils/fixtures';
44
import { getSentryRequest } from '../../../utils/helpers';
55

6-
sentryTest('should parse function identifiers correctly', async ({ getLocalTestPath, page, browserName }) => {
7-
const url = await getLocalTestPath({ testDir: __dirname });
6+
sentryTest(
7+
'should parse function identifiers correctly',
8+
async ({ getLocalTestPath, page, runInChromium, runInFirefox, runInWebkit }) => {
9+
const url = await getLocalTestPath({ testDir: __dirname });
810

9-
const eventData = await getSentryRequest(page, url);
11+
const eventData = await getSentryRequest(page, url);
12+
const frames = eventData.exception?.values?.[0].stacktrace?.frames;
1013

11-
expect(eventData.exception?.values?.[0].stacktrace?.frames).toMatchObject(
12-
browserName === 'chromium'
13-
? [
14-
{ function: '?' },
15-
{ function: '?' },
16-
{ function: 'qux' },
17-
{ function: '?' },
18-
{ function: '?' },
19-
{ function: 'foo' },
20-
{ function: 'bar' },
21-
{ function: 'Function.baz' },
22-
]
23-
: browserName === 'firefox'
24-
? [
25-
{ function: '?' },
26-
{ function: '?' },
27-
{ function: 'qux' },
28-
{ function: 'qux/<' },
29-
{ function: 'qux/</<' },
30-
{ function: 'foo' },
31-
{ function: 'bar' },
32-
{ function: 'baz' },
33-
]
34-
: [
35-
{ function: 'global code' },
36-
{ function: '?' },
37-
{ function: 'qux' },
38-
{ function: '?' },
39-
{ function: '?' },
40-
{ function: 'foo' },
41-
{ function: 'bar' },
42-
{ function: 'baz' },
43-
],
44-
);
45-
});
14+
runInChromium(() => {
15+
expect(frames).toMatchObject([
16+
{ function: '?' },
17+
{ function: '?' },
18+
{ function: 'qux' },
19+
{ function: '?' },
20+
{ function: '?' },
21+
{ function: 'foo' },
22+
{ function: 'bar' },
23+
{ function: 'Function.baz' },
24+
]);
25+
});
26+
27+
runInFirefox(() => {
28+
expect(frames).toMatchObject([
29+
{ function: '?' },
30+
{ function: '?' },
31+
{ function: 'qux' },
32+
{ function: 'qux/<' },
33+
{ function: 'qux/</<' },
34+
{ function: 'foo' },
35+
{ function: 'bar' },
36+
{ function: 'baz' },
37+
]);
38+
});
39+
40+
runInWebkit(() => {
41+
expect(frames).toMatchObject([
42+
{ function: 'global code' },
43+
{ function: '?' },
44+
{ function: 'qux' },
45+
{ function: '?' },
46+
{ function: '?' },
47+
{ function: 'foo' },
48+
{ function: 'bar' },
49+
{ function: 'baz' },
50+
]);
51+
});
52+
},
53+
);
4654

4755
sentryTest('should not add any part of the function identifier inside filename', async ({ getLocalTestPath, page }) => {
4856
const url = await getLocalTestPath({ testDir: __dirname });

packages/integration-tests/utils/fixtures.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-empty-pattern */
12
import { test as base } from '@playwright/test';
23
import fs from 'fs';
34
import path from 'path';
@@ -14,17 +15,20 @@ const getAsset = (assetDir: string, asset: string): string => {
1415
return `${path.dirname(assetDir)}/${asset}`;
1516
};
1617

17-
export type TestOptions = {
18-
testDir: string;
19-
};
20-
2118
export type TestFixtures = {
2219
testDir: string;
23-
getLocalTestPath: (options: TestOptions) => Promise<string>;
20+
getLocalTestPath: (options: { testDir: string }) => Promise<string>;
21+
runInChromium: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
22+
runInFirefox: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
23+
runInWebkit: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
24+
runInSingleBrowser: (
25+
browser: 'chromium' | 'firefox' | 'webkit',
26+
fn: (...args: unknown[]) => unknown,
27+
args?: unknown[],
28+
) => unknown;
2429
};
2530

2631
const sentryTest = base.extend<TestFixtures>({
27-
// eslint-disable-next-line no-empty-pattern
2832
getLocalTestPath: ({}, use, testInfo) => {
2933
return use(async ({ testDir }) => {
3034
const pagePath = `file:///${path.resolve(testDir, './dist/index.html')}`;
@@ -41,6 +45,24 @@ const sentryTest = base.extend<TestFixtures>({
4145
return pagePath;
4246
});
4347
},
48+
runInChromium: ({ runInSingleBrowser }, use) => {
49+
return use((fn, args) => runInSingleBrowser('chromium', fn, args));
50+
},
51+
runInFirefox: ({ runInSingleBrowser }, use) => {
52+
return use((fn, args) => runInSingleBrowser('firefox', fn, args));
53+
},
54+
runInWebkit: ({ runInSingleBrowser }, use) => {
55+
return use((fn, args) => runInSingleBrowser('webkit', fn, args));
56+
},
57+
runInSingleBrowser: ({ browserName }, use) => {
58+
return use((browser, fn, args = []) => {
59+
if (browserName !== browser) {
60+
return;
61+
}
62+
63+
return fn(...args);
64+
});
65+
},
4466
});
4567

4668
export { sentryTest };

0 commit comments

Comments
 (0)