Skip to content

Commit

Permalink
Add runIn* fixtures for browser-specific logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
onurtemizkan committed Dec 21, 2021
1 parent 2490499 commit 537da47
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,47 @@ import { getSentryRequest } from '../../../utils/helpers';

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

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

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' },
],
);
runInChromium(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'Function.httpCode' },
]);
});

runInFirefox(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'httpCode' },
]);
});

runInWebkit(() => {
expect(frames).toMatchObject([
{ function: 'global code' },
{ function: '?' },
{ function: 'decodeBlob' },
{ function: 'readFile' },
{ function: 'httpsCall' },
{ function: 'webpackDevServer' },
{ function: 'httpCode' },
]);
});
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,47 @@ import { getSentryRequest } from '../../../utils/helpers';

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

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

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' },
],
);
runInChromium(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'Function.http' },
]);
});

runInFirefox(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'http' },
]);
});

runInWebkit(() => {
expect(frames).toMatchObject([
{ function: 'global code' },
{ function: '?' },
{ function: 'blob' },
{ function: 'file' },
{ function: 'https' },
{ function: 'webpack' },
{ function: 'http' },
]);
});
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,54 @@ 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 });
sentryTest(
'should parse function identifiers correctly',
async ({ getLocalTestPath, page, runInChromium, runInFirefox, runInWebkit }) => {
const url = await getLocalTestPath({ testDir: __dirname });

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

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' },
],
);
});
runInChromium(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'qux' },
{ function: '?' },
{ function: '?' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'Function.baz' },
]);
});

runInFirefox(() => {
expect(frames).toMatchObject([
{ function: '?' },
{ function: '?' },
{ function: 'qux' },
{ function: 'qux/<' },
{ function: 'qux/</<' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'baz' },
]);
});

runInWebkit(() => {
expect(frames).toMatchObject([
{ function: 'global code' },
{ function: '?' },
{ function: 'qux' },
{ function: '?' },
{ function: '?' },
{ function: 'foo' },
{ function: 'bar' },
{ function: 'baz' },
]);
});
},
);

sentryTest('should not add any part of the function identifier inside filename', async ({ getLocalTestPath, page }) => {
const url = await getLocalTestPath({ testDir: __dirname });
Expand Down
34 changes: 28 additions & 6 deletions packages/integration-tests/utils/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-empty-pattern */
import { test as base } from '@playwright/test';
import fs from 'fs';
import path from 'path';
Expand All @@ -14,17 +15,20 @@ const getAsset = (assetDir: string, asset: string): string => {
return `${path.dirname(assetDir)}/${asset}`;
};

export type TestOptions = {
testDir: string;
};

export type TestFixtures = {
testDir: string;
getLocalTestPath: (options: TestOptions) => Promise<string>;
getLocalTestPath: (options: { testDir: string }) => Promise<string>;
runInChromium: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
runInFirefox: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
runInWebkit: (fn: (...args: unknown[]) => unknown, args?: unknown[]) => unknown;
runInSingleBrowser: (
browser: 'chromium' | 'firefox' | 'webkit',
fn: (...args: unknown[]) => unknown,
args?: unknown[],
) => unknown;
};

const sentryTest = base.extend<TestFixtures>({
// eslint-disable-next-line no-empty-pattern
getLocalTestPath: ({}, use, testInfo) => {
return use(async ({ testDir }) => {
const pagePath = `file:///${path.resolve(testDir, './dist/index.html')}`;
Expand All @@ -41,6 +45,24 @@ const sentryTest = base.extend<TestFixtures>({
return pagePath;
});
},
runInChromium: ({ runInSingleBrowser }, use) => {
return use((fn, args) => runInSingleBrowser('chromium', fn, args));
},
runInFirefox: ({ runInSingleBrowser }, use) => {
return use((fn, args) => runInSingleBrowser('firefox', fn, args));
},
runInWebkit: ({ runInSingleBrowser }, use) => {
return use((fn, args) => runInSingleBrowser('webkit', fn, args));
},
runInSingleBrowser: ({ browserName }, use) => {
return use((browser, fn, args = []) => {
if (browserName !== browser) {
return;
}

return fn(...args);
});
},
});

export { sentryTest };

0 comments on commit 537da47

Please sign in to comment.