Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dev-packages/browser-integration-tests/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"moduleResolution": "node",
"noEmit": true,
"strict": true,
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"noUncheckedIndexedAccess": false
},
"include": ["**/*.ts"],
"exclude": ["node_modules"]
Expand Down
58 changes: 32 additions & 26 deletions dev-packages/browser-integration-tests/utils/generatePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ function generateSentryAlias(): Record<string, string> {

const modulePath = path.resolve(PACKAGES_DIR, packageName);

if (useCompiledModule && bundleKey && BUNDLE_PATHS[packageName]?.[bundleKey]) {
const bundlePath = path.resolve(modulePath, BUNDLE_PATHS[packageName][bundleKey]);
const bundleKeyPath = bundleKey && BUNDLE_PATHS[packageName]?.[bundleKey];
if (useCompiledModule && bundleKeyPath) {
const bundlePath = path.resolve(modulePath, bundleKeyPath);

return [packageJSON['name'], bundlePath];
}
Expand Down Expand Up @@ -175,8 +176,8 @@ class SentryScenarioGenerationPlugin {
(statement: { specifiers: [{ imported: { name: string } }] }, source: string) => {
const imported = statement.specifiers?.[0]?.imported?.name;

if (imported && IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS[imported]) {
const bundleName = IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS[imported];
const bundleName = imported && IMPORTED_INTEGRATION_CDN_BUNDLE_PATHS[imported];
if (bundleName) {
this.requiredIntegrations.push(bundleName);
} else if (source === '@sentry/wasm') {
this.requiresWASMIntegration = true;
Expand All @@ -190,7 +191,7 @@ class SentryScenarioGenerationPlugin {
HtmlWebpackPlugin.getHooks(compilation).alterAssetTags.tapAsync(this._name, (data, cb) => {
if (useBundleOrLoader) {
const bundleName = 'browser';
const bundlePath = BUNDLE_PATHS[bundleName][bundleKey];
const bundlePath = BUNDLE_PATHS[bundleName]?.[bundleKey];

if (!bundlePath) {
throw new Error(`Could not find bundle or loader for key ${bundleKey}`);
Expand All @@ -215,10 +216,10 @@ class SentryScenarioGenerationPlugin {
'__LOADER_OPTIONS__',
JSON.stringify({
dsn: 'https://[email protected]/1337',
...loaderConfig.options,
...loaderConfig?.options,
}),
)
.replace('__LOADER_LAZY__', loaderConfig.lazy ? 'true' : 'false');
.replace('__LOADER_LAZY__', loaderConfig?.lazy ? 'true' : 'false');
});
}

Expand All @@ -240,36 +241,41 @@ class SentryScenarioGenerationPlugin {
path.resolve(
PACKAGES_DIR,
'feedback',
BUNDLE_PATHS['feedback'][integrationBundleKey].replace('[INTEGRATION_NAME]', integration),
BUNDLE_PATHS['feedback']?.[integrationBundleKey]?.replace('[INTEGRATION_NAME]', integration) || '',
),
fileName,
);
});
}

this.requiredIntegrations.forEach(integration => {
const fileName = `${integration}.bundle.js`;
addStaticAssetSymlink(
this.localOutPath,
path.resolve(
PACKAGES_DIR,
'browser',
BUNDLE_PATHS['integrations'][integrationBundleKey].replace('[INTEGRATION_NAME]', integration),
),
fileName,
);
const baseIntegrationFileName = BUNDLE_PATHS['integrations']?.[integrationBundleKey];

const integrationObject = createHtmlTagObject('script', {
src: fileName,
});
if (baseIntegrationFileName) {
this.requiredIntegrations.forEach(integration => {
const fileName = `${integration}.bundle.js`;
addStaticAssetSymlink(
this.localOutPath,
path.resolve(
PACKAGES_DIR,
'browser',
baseIntegrationFileName.replace('[INTEGRATION_NAME]', integration),
),
fileName,
);

data.assetTags.scripts.unshift(integrationObject);
});
const integrationObject = createHtmlTagObject('script', {
src: fileName,
});

data.assetTags.scripts.unshift(integrationObject);
});
}

if (this.requiresWASMIntegration && BUNDLE_PATHS['wasm'][integrationBundleKey]) {
const baseWasmFileName = BUNDLE_PATHS['wasm']?.[integrationBundleKey];
if (this.requiresWASMIntegration && baseWasmFileName) {
addStaticAssetSymlink(
this.localOutPath,
path.resolve(PACKAGES_DIR, 'wasm', BUNDLE_PATHS['wasm'][integrationBundleKey]),
path.resolve(PACKAGES_DIR, 'wasm', baseWasmFileName),
'wasm.bundle.js',
);

Expand Down
20 changes: 16 additions & 4 deletions dev-packages/browser-integration-tests/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,18 @@ const properFullEnvelopeParser = <T extends Envelope>(request: Request | null):
};

function getEventAndTraceHeader(envelope: EventEnvelope): EventAndTraceHeader {
const event = envelope[1][0][1] as Event;
const trace = envelope[0].trace;
const event = envelope[1][0]?.[1] as Event | undefined;
const trace = envelope[0]?.trace;

if (!event || !trace) {
throw new Error('Could not get event or trace from envelope');
}

return [event, trace];
}

export const properEnvelopeRequestParser = <T = Event>(request: Request | null, envelopeIndex = 1): T => {
return properEnvelopeParser(request)[0][envelopeIndex] as T;
return properEnvelopeParser(request)[0]?.[envelopeIndex] as T;
};

export const properFullEnvelopeRequestParser = <T extends Envelope>(request: Request | null): T => {
Expand Down Expand Up @@ -361,7 +366,14 @@ async function getFirstSentryEnvelopeRequest<T>(
url?: string,
requestParser: (req: Request) => T = envelopeRequestParser as (req: Request) => T,
): Promise<T> {
return (await getMultipleSentryEnvelopeRequests<T>(page, 1, { url }, requestParser))[0];
const reqs = await getMultipleSentryEnvelopeRequests<T>(page, 1, { url }, requestParser);

const req = reqs[0];
if (!req) {
throw new Error('No request found');
}

return req;
}

export { runScriptInSandbox, getMultipleSentryEnvelopeRequests, getFirstSentryEnvelopeRequest, getSentryEvents };