Skip to content

Commit 9ac9033

Browse files
committed
test(replay): Test against CDN bundles in Playwright integration tests
1 parent 56d3a74 commit 9ac9033

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

packages/integration-tests/suites/replay/captureReplay/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { sentryTest } from '../../../utils/fixtures';
66
import { getFirstSentryEnvelopeRequest } from '../../../utils/helpers';
77

88
sentryTest('captureReplay', async ({ getLocalTestPath, page }) => {
9-
// Currently bundle tests are not supported for replay
10-
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
9+
// Replay bundles are es6 only
10+
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_es5')) {
1111
sentryTest.skip();
1212
}
1313

packages/integration-tests/suites/replay/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as Sentry from '@sentry/browser';
2+
import { Replay } from '@sentry/replay';
23

34
window.Sentry = Sentry;
4-
window.Replay = new Sentry.Replay({
5+
window.Replay = new Replay({
56
flushMinDelay: 200,
67
initialFlushDelay: 200,
78
});

packages/integration-tests/suites/replay/sampling/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import * as Sentry from '@sentry/browser';
2+
import { Replay } from '@sentry/replay';
23

34
window.Sentry = Sentry;
4-
window.Replay = new Sentry.Replay({
5+
window.Replay = new Replay({
56
flushMinDelay: 200,
67
initialFlushDelay: 200,
78
});

packages/integration-tests/suites/replay/sampling/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { sentryTest } from '../../../utils/fixtures';
44
import { getReplaySnapshot } from '../../../utils/helpers';
55

66
sentryTest('sampling', async ({ getLocalTestPath, page }) => {
7-
// Currently bundle tests are not supported for replay
8-
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
7+
// Replay bundles are es6 only
8+
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_es5')) {
99
sentryTest.skip();
1010
}
1111

packages/integration-tests/utils/generatePlugin.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ const BUNDLE_PATHS: Record<string, Record<string, string>> = {
4040
bundle_es6: 'build/bundles/[INTEGRATION_NAME].js',
4141
bundle_es6_min: 'build/bundles/[INTEGRATION_NAME].min.js',
4242
},
43+
replay: {
44+
cjs: 'build/npm/cjs/index.js',
45+
esm: 'build/npm/esm/index.js',
46+
bundle_es6: 'build/bundles/replay.js',
47+
bundle_es6_min: 'build/bundles/replay.min.js',
48+
},
4349
};
4450

4551
/*
@@ -87,6 +93,7 @@ function generateSentryAlias(): Record<string, string> {
8793
class SentryScenarioGenerationPlugin {
8894
public requiresTracing: boolean = false;
8995
public requiredIntegrations: string[] = [];
96+
public requiresReplay = false;
9097

9198
private _name: string = 'SentryScenarioGenerationPlugin';
9299

@@ -99,6 +106,7 @@ class SentryScenarioGenerationPlugin {
99106
'@sentry/browser': 'Sentry',
100107
'@sentry/tracing': 'Sentry',
101108
'@sentry/integrations': 'Sentry.Integrations',
109+
'@sentry/replay': 'Sentry.Integrations',
102110
}
103111
: {};
104112

@@ -113,6 +121,8 @@ class SentryScenarioGenerationPlugin {
113121
this.requiresTracing = true;
114122
} else if (source === '@sentry/integrations') {
115123
this.requiredIntegrations.push(statement.specifiers[0].imported.name.toLowerCase());
124+
} else if (source === '@sentry/replay') {
125+
this.requiresReplay = true;
116126
}
117127
},
118128
);
@@ -140,6 +150,14 @@ class SentryScenarioGenerationPlugin {
140150
data.assetTags.scripts.unshift(integrationObject);
141151
});
142152

153+
if (this.requiresReplay && BUNDLE_PATHS['replay'][bundleKey]) {
154+
const replayObject = createHtmlTagObject('script', {
155+
src: path.resolve(PACKAGES_DIR, 'replay', BUNDLE_PATHS['replay'][bundleKey]),
156+
});
157+
158+
data.assetTags.scripts.unshift(replayObject);
159+
}
160+
143161
data.assetTags.scripts.unshift(bundleObject);
144162
}
145163

rollup/plugins/bundlePlugins.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ export function makeTerserPlugin() {
107107
'_driver',
108108
'_initStorage',
109109
'_support',
110+
// We want to keept he _replay variable unmangled to enable integration tests to access it
111+
'_replay',
110112
],
111113
},
112114
},

0 commit comments

Comments
 (0)