Skip to content

Commit 9f06d48

Browse files
authored
feat(tests): Inject @sentry/integrations bundles to Playwright templates (#6666)
1 parent 0adaff4 commit 9f06d48

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

packages/integration-tests/suites/integrations/httpclient/fetch/test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
77
sentryTest(
88
'should assign request and response context from a failed 500 fetch request',
99
async ({ getLocalTestPath, page }) => {
10-
// Skipping this test when running in bundle mode, because `@sentry/integrations` bundle
11-
// is not injected to the page with the current test setup.
12-
if (process.env.PW_BUNDLE?.includes('bundle')) {
13-
sentryTest.skip();
14-
}
15-
1610
const url = await getLocalTestPath({ testDir: __dirname });
1711

1812
await page.route('**/foo', route => {

packages/integration-tests/suites/integrations/httpclient/xhr/test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ import { getFirstSentryEnvelopeRequest } from '../../../../utils/helpers';
77
sentryTest(
88
'should assign request and response context from a failed 500 XHR request',
99
async ({ getLocalTestPath, page }) => {
10-
// Skipping this test when running in bundle mode, because `@sentry/integrations` bundle
11-
// is not injected to the page with the current test setup.
12-
if (process.env.PW_BUNDLE?.includes('bundle')) {
13-
sentryTest.skip();
14-
}
15-
1610
const url = await getLocalTestPath({ testDir: __dirname });
1711

1812
await page.route('**/foo', route => {

packages/integration-tests/utils/generatePlugin.ts

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
3232
bundle_es6: 'build/bundles/bundle.tracing.js',
3333
bundle_es6_min: 'build/bundles/bundle.tracing.min.js',
3434
},
35+
integrations: {
36+
cjs: 'build/npm/cjs/index.js',
37+
esm: 'build/npm/esm/index.js',
38+
bundle_es5: 'build/bundles/[INTEGRATION_NAME].es5.js',
39+
bundle_es5_min: 'build/bundles/[INTEGRATION_NAME].es5.min.js',
40+
bundle_es6: 'build/bundles/[INTEGRATION_NAME].js',
41+
bundle_es6_min: 'build/bundles/[INTEGRATION_NAME].min.js',
42+
},
3543
};
3644

3745
/*
@@ -78,6 +86,7 @@ function generateSentryAlias(): Record<string, string> {
7886

7987
class SentryScenarioGenerationPlugin {
8088
public requiresTracing: boolean = false;
89+
public requiredIntegrations: string[] = [];
8190

8291
private _name: string = 'SentryScenarioGenerationPlugin';
8392

@@ -89,18 +98,24 @@ class SentryScenarioGenerationPlugin {
8998
// To help Webpack resolve Sentry modules in `import` statements in cases where they're provided in bundles rather than in `node_modules`
9099
'@sentry/browser': 'Sentry',
91100
'@sentry/tracing': 'Sentry',
101+
'@sentry/integrations': 'Sentry.Integrations',
92102
}
93103
: {};
94104

95-
// Checking if the current scenario has imported `@sentry/tracing`.
105+
// Checking if the current scenario has imported `@sentry/tracing` or `@sentry/integrations`.
96106
compiler.hooks.normalModuleFactory.tap(this._name, factory => {
97107
factory.hooks.parser.for('javascript/auto').tap(this._name, parser => {
98108
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
99-
parser.hooks.import.tap(this._name, (_statement: unknown, source: string) => {
100-
if (source === '@sentry/tracing') {
101-
this.requiresTracing = true;
102-
}
103-
});
109+
parser.hooks.import.tap(
110+
this._name,
111+
(statement: { specifiers: [{ imported: { name: string } }] }, source: string) => {
112+
if (source === '@sentry/tracing') {
113+
this.requiresTracing = true;
114+
} else if (source === '@sentry/integrations') {
115+
this.requiredIntegrations.push(statement.specifiers[0].imported.name.toLowerCase());
116+
}
117+
},
118+
);
104119
});
105120
});
106121

@@ -113,6 +128,18 @@ class SentryScenarioGenerationPlugin {
113128
src: path.resolve(PACKAGES_DIR, bundleName, BUNDLE_PATHS[bundleName][bundleKey]),
114129
});
115130

131+
this.requiredIntegrations.forEach(integration => {
132+
const integrationObject = createHtmlTagObject('script', {
133+
src: path.resolve(
134+
PACKAGES_DIR,
135+
'integrations',
136+
BUNDLE_PATHS['integrations'][bundleKey].replace('[INTEGRATION_NAME]', integration),
137+
),
138+
});
139+
140+
data.assetTags.scripts.unshift(integrationObject);
141+
});
142+
116143
data.assetTags.scripts.unshift(bundleObject);
117144
}
118145

0 commit comments

Comments
 (0)