Skip to content

Commit 9c03ef6

Browse files
committed
test: attempt to fix test
1 parent 086be00 commit 9c03ef6

File tree

2 files changed

+79
-18
lines changed

2 files changed

+79
-18
lines changed

dev-packages/browser-integration-tests/utils/generatePlugin.ts

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ class SentryScenarioGenerationPlugin {
164164
public requiredIntegrations: string[] = [];
165165
public requiresWASMIntegration: boolean = false;
166166
public localOutPath: string;
167+
public isFeedbackTest: boolean;
167168

168169
private _name: string = 'SentryScenarioGenerationPlugin';
169170

170171
public constructor(localOutPath: string) {
171172
this.localOutPath = localOutPath;
173+
// Check if this is a feedback test by looking at the output path
174+
// The path structure is: testDir/dist/uuid, and testDir includes suites/feedback/...
175+
this.isFeedbackTest = localOutPath.includes('suites/feedback');
172176
}
173177

174178
public apply(compiler: Compiler): void {
@@ -248,19 +252,34 @@ class SentryScenarioGenerationPlugin {
248252
.replace('_feedback', '');
249253

250254
// For feedback bundle, make sure to add modal & screenshot integrations
251-
if (bundleKey.includes('_feedback')) {
255+
// Also symlink feedback bundles for feedback tests that use lazy loading
256+
if (bundleKey.includes('_feedback') || this.isFeedbackTest) {
252257
['feedback-modal', 'feedback-screenshot'].forEach(integration => {
253258
const fileName = `${integration}.bundle.js`;
254259

255-
// We add the files, but not a script tag - they are lazy-loaded
256-
symlinkAsset(
257-
path.resolve(
258-
PACKAGES_DIR,
259-
'feedback',
260-
BUNDLE_PATHS['feedback']?.[integrationBundleKey]?.replace('[INTEGRATION_NAME]', integration) || '',
261-
),
262-
path.join(this.localOutPath, fileName),
260+
// Lazy loading always requests .min.js files, so we need to use bundle_min
261+
// to get the .min.js version, even if the main bundle is not minified
262+
const feedbackBundleKey = integrationBundleKey === 'bundle' ? 'bundle_min' : integrationBundleKey;
263+
264+
const bundlePath = BUNDLE_PATHS['feedback']?.[feedbackBundleKey]?.replace(
265+
'[INTEGRATION_NAME]',
266+
integration,
263267
);
268+
if (!bundlePath) {
269+
throw new Error(
270+
`Could not find bundle path for feedback integration "${integration}" with bundle key "${feedbackBundleKey}" (derived from "${bundleKey}")`,
271+
);
272+
}
273+
274+
const originalPath = path.resolve(PACKAGES_DIR, 'feedback', bundlePath);
275+
if (!fs.existsSync(originalPath)) {
276+
throw new Error(
277+
`Feedback bundle file does not exist: ${originalPath}. Make sure to run 'yarn build:bundle' in packages/feedback first.`,
278+
);
279+
}
280+
281+
// We add the files, but not a script tag - they are lazy-loaded
282+
symlinkAsset(originalPath, path.join(this.localOutPath, fileName));
264283
});
265284
}
266285

@@ -279,14 +298,46 @@ class SentryScenarioGenerationPlugin {
279298
);
280299

281300
if (integration === 'feedback') {
282-
symlinkAsset(
283-
path.resolve(PACKAGES_DIR, 'feedback', 'build/bundles/feedback-modal.js'),
284-
path.join(this.localOutPath, 'feedback-modal.bundle.js'),
301+
// Lazy loading always requests .min.js files, so we need to use bundle_min
302+
// to get the .min.js version, even if the main bundle is not minified
303+
const feedbackBundleKey = integrationBundleKey === 'bundle' ? 'bundle_min' : integrationBundleKey;
304+
305+
const modalBundlePath = BUNDLE_PATHS['feedback']?.[feedbackBundleKey]?.replace(
306+
'[INTEGRATION_NAME]',
307+
'feedback-modal',
285308
);
286-
symlinkAsset(
287-
path.resolve(PACKAGES_DIR, 'feedback', 'build/bundles/feedback-screenshot.js'),
288-
path.join(this.localOutPath, 'feedback-screenshot.bundle.js'),
309+
if (!modalBundlePath) {
310+
throw new Error(
311+
`Could not find bundle path for feedback-modal with bundle key "${feedbackBundleKey}" (derived from "${bundleKey}")`,
312+
);
313+
}
314+
315+
const modalOriginalPath = path.resolve(PACKAGES_DIR, 'feedback', modalBundlePath);
316+
if (!fs.existsSync(modalOriginalPath)) {
317+
throw new Error(
318+
`Feedback modal bundle file does not exist: ${modalOriginalPath}. Make sure to run 'yarn build:bundle' in packages/feedback first.`,
319+
);
320+
}
321+
322+
const screenshotBundlePath = BUNDLE_PATHS['feedback']?.[feedbackBundleKey]?.replace(
323+
'[INTEGRATION_NAME]',
324+
'feedback-screenshot',
289325
);
326+
if (!screenshotBundlePath) {
327+
throw new Error(
328+
`Could not find bundle path for feedback-screenshot with bundle key "${feedbackBundleKey}" (derived from "${bundleKey}")`,
329+
);
330+
}
331+
332+
const screenshotOriginalPath = path.resolve(PACKAGES_DIR, 'feedback', screenshotBundlePath);
333+
if (!fs.existsSync(screenshotOriginalPath)) {
334+
throw new Error(
335+
`Feedback screenshot bundle file does not exist: ${screenshotOriginalPath}. Make sure to run 'yarn build:bundle' in packages/feedback first.`,
336+
);
337+
}
338+
339+
symlinkAsset(modalOriginalPath, path.join(this.localOutPath, 'feedback-modal.bundle.js'));
340+
symlinkAsset(screenshotOriginalPath, path.join(this.localOutPath, 'feedback-screenshot.bundle.js'));
290341
}
291342

292343
const integrationObject = createHtmlTagObject('script', {

dev-packages/browser-integration-tests/utils/staticAssets.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ export function addStaticAsset(localOutPath: string, fileName: string, cb: () =>
2424

2525
export function symlinkAsset(originalPath: string, targetPath: string): void {
2626
try {
27+
// Try hard link first (faster, works on same filesystem)
2728
fs.linkSync(originalPath, targetPath);
28-
} catch {
29-
// ignore errors here, probably means the file already exists
30-
// Since we always build into a new directory for each test, we can safely ignore this
29+
} catch (err) {
30+
// If hard link fails (e.g., cross-filesystem in CI), fall back to copying
31+
// This can happen in CI environments where source and target are on different filesystems
32+
try {
33+
fs.copyFileSync(originalPath, targetPath);
34+
} catch (copyErr) {
35+
// If copy also fails, it might mean the file already exists (from a previous test run)
36+
// Since we always build into a new directory for each test, we can safely ignore this
37+
if ((copyErr as NodeJS.ErrnoException).code !== 'EEXIST') {
38+
throw copyErr;
39+
}
40+
}
3141
}
3242
}

0 commit comments

Comments
 (0)