Skip to content

Commit df53722

Browse files
committed
test: Avoid race conditions with symlinks
Also, no need to double-symlink stuff, and since we now build into unique dirs, we can skip the check for existing symlinks as well.
1 parent 2b3e26f commit df53722

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Package } from '@sentry/types';
44
import HtmlWebpackPlugin, { createHtmlTagObject } from 'html-webpack-plugin';
55
import type { Compiler } from 'webpack';
66

7-
import { addStaticAsset, addStaticAssetSymlink } from './staticAssets';
7+
import { addStaticAsset, symlinkAsset } from './staticAssets';
88

99
const LOADER_TEMPLATE = fs.readFileSync(path.join(__dirname, '../fixtures/loader.js'), 'utf-8');
1010
const PACKAGES_DIR = path.join(__dirname, '..', '..', '..', 'packages');
@@ -214,7 +214,10 @@ class SentryScenarioGenerationPlugin {
214214
src: 'cdn.bundle.js',
215215
});
216216

217-
addStaticAssetSymlink(this.localOutPath, path.resolve(PACKAGES_DIR, bundleName, bundlePath), 'cdn.bundle.js');
217+
symlinkAsset(
218+
path.resolve(PACKAGES_DIR, bundleName, bundlePath),
219+
path.join(this.localOutPath, 'cdn.bundle.js'),
220+
);
218221

219222
if (useLoader) {
220223
const loaderConfig = LOADER_CONFIGS[bundleKey];
@@ -245,14 +248,13 @@ class SentryScenarioGenerationPlugin {
245248
const fileName = `${integration}.bundle.js`;
246249

247250
// We add the files, but not a script tag - they are lazy-loaded
248-
addStaticAssetSymlink(
249-
this.localOutPath,
251+
symlinkAsset(
250252
path.resolve(
251253
PACKAGES_DIR,
252254
'feedback',
253255
BUNDLE_PATHS['feedback']?.[integrationBundleKey]?.replace('[INTEGRATION_NAME]', integration) || '',
254256
),
255-
fileName,
257+
path.join(this.localOutPath, fileName),
256258
);
257259
});
258260
}
@@ -262,26 +264,23 @@ class SentryScenarioGenerationPlugin {
262264
if (baseIntegrationFileName) {
263265
this.requiredIntegrations.forEach(integration => {
264266
const fileName = `${integration}.bundle.js`;
265-
addStaticAssetSymlink(
266-
this.localOutPath,
267+
symlinkAsset(
267268
path.resolve(
268269
PACKAGES_DIR,
269270
'browser',
270271
baseIntegrationFileName.replace('[INTEGRATION_NAME]', integration),
271272
),
272-
fileName,
273+
path.join(this.localOutPath, fileName),
273274
);
274275

275276
if (integration === 'feedback') {
276-
addStaticAssetSymlink(
277-
this.localOutPath,
277+
symlinkAsset(
278278
path.resolve(PACKAGES_DIR, 'feedback', 'build/bundles/feedback-modal.js'),
279-
'feedback-modal.bundle.js',
279+
path.join(this.localOutPath, 'feedback-modal.bundle.js'),
280280
);
281-
addStaticAssetSymlink(
282-
this.localOutPath,
281+
symlinkAsset(
283282
path.resolve(PACKAGES_DIR, 'feedback', 'build/bundles/feedback-screenshot.js'),
284-
'feedback-screenshot.bundle.js',
283+
path.join(this.localOutPath, 'feedback-screenshot.bundle.js'),
285284
);
286285
}
287286

@@ -295,10 +294,9 @@ class SentryScenarioGenerationPlugin {
295294

296295
const baseWasmFileName = BUNDLE_PATHS['wasm']?.[integrationBundleKey];
297296
if (this.requiresWASMIntegration && baseWasmFileName) {
298-
addStaticAssetSymlink(
299-
this.localOutPath,
297+
symlinkAsset(
300298
path.resolve(PACKAGES_DIR, 'wasm', baseWasmFileName),
301-
'wasm.bundle.js',
299+
path.join(this.localOutPath, 'wasm.bundle.js'),
302300
);
303301

304302
const wasmObject = createHtmlTagObject('script', {

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,6 @@ export function addStaticAsset(localOutPath: string, fileName: string, cb: () =>
2222
symlinkAsset(newPath, path.join(localOutPath, fileName));
2323
}
2424

25-
export function addStaticAssetSymlink(localOutPath: string, originalPath: string, fileName: string): void {
26-
const newPath = path.join(STATIC_DIR, fileName);
27-
28-
// Only copy files once
29-
if (!fs.existsSync(newPath)) {
30-
fs.symlinkSync(originalPath, newPath);
31-
}
32-
33-
symlinkAsset(newPath, path.join(localOutPath, fileName));
34-
}
35-
36-
function symlinkAsset(originalPath: string, targetPath: string): void {
37-
try {
38-
fs.unlinkSync(targetPath);
39-
} catch {
40-
// ignore errors here
41-
}
42-
25+
export function symlinkAsset(originalPath: string, targetPath: string): void {
4326
fs.linkSync(originalPath, targetPath);
4427
}

0 commit comments

Comments
 (0)