From 16874c03e48d7e3daca38d5f5668d2541c3f6ee8 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 1 Jul 2024 11:55:22 +0200 Subject: [PATCH 1/2] test: Fix tsconfig for browser-integration-tests Not sure how this worked before, but there was a bunch of stuff that conflicted with `noUncheckedIndexedAccess` :thinking: --- .../browser-integration-tests/tsconfig.json | 2 +- .../utils/generatePlugin.ts | 58 ++++++++++--------- .../utils/helpers.ts | 20 +++++-- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/dev-packages/browser-integration-tests/tsconfig.json b/dev-packages/browser-integration-tests/tsconfig.json index 2587befcce14..aa450013ee95 100644 --- a/dev-packages/browser-integration-tests/tsconfig.json +++ b/dev-packages/browser-integration-tests/tsconfig.json @@ -9,5 +9,5 @@ "allowSyntheticDefaultImports": true }, "include": ["**/*.ts"], - "exclude": ["node_modules"] + "exclude": ["node_modules", "suites", "loader-suites"] } diff --git a/dev-packages/browser-integration-tests/utils/generatePlugin.ts b/dev-packages/browser-integration-tests/utils/generatePlugin.ts index 7b46faa1fd7d..7b4338fa907b 100644 --- a/dev-packages/browser-integration-tests/utils/generatePlugin.ts +++ b/dev-packages/browser-integration-tests/utils/generatePlugin.ts @@ -128,8 +128,9 @@ function generateSentryAlias(): Record { 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]; } @@ -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; @@ -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}`); @@ -215,10 +216,10 @@ class SentryScenarioGenerationPlugin { '__LOADER_OPTIONS__', JSON.stringify({ dsn: 'https://public@dsn.ingest.sentry.io/1337', - ...loaderConfig.options, + ...loaderConfig?.options, }), ) - .replace('__LOADER_LAZY__', loaderConfig.lazy ? 'true' : 'false'); + .replace('__LOADER_LAZY__', loaderConfig?.lazy ? 'true' : 'false'); }); } @@ -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', ); diff --git a/dev-packages/browser-integration-tests/utils/helpers.ts b/dev-packages/browser-integration-tests/utils/helpers.ts index ab55da449ad2..e0f72bdfacbc 100644 --- a/dev-packages/browser-integration-tests/utils/helpers.ts +++ b/dev-packages/browser-integration-tests/utils/helpers.ts @@ -65,13 +65,18 @@ const properFullEnvelopeParser = (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 = (request: Request | null, envelopeIndex = 1): T => { - return properEnvelopeParser(request)[0][envelopeIndex] as T; + return properEnvelopeParser(request)[0]?.[envelopeIndex] as T; }; export const properFullEnvelopeRequestParser = (request: Request | null): T => { @@ -361,7 +366,14 @@ async function getFirstSentryEnvelopeRequest( url?: string, requestParser: (req: Request) => T = envelopeRequestParser as (req: Request) => T, ): Promise { - return (await getMultipleSentryEnvelopeRequests(page, 1, { url }, requestParser))[0]; + const reqs = await getMultipleSentryEnvelopeRequests(page, 1, { url }, requestParser); + + const req = reqs[0]; + if (!req) { + throw new Error('No request found'); + } + + return req; } export { runScriptInSandbox, getMultipleSentryEnvelopeRequests, getFirstSentryEnvelopeRequest, getSentryEvents }; From b3f6437f54ff089f11ae414c2c101a224f885f55 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Mon, 1 Jul 2024 12:48:11 +0200 Subject: [PATCH 2/2] disable `noUncheckedIndexedAccess` for browser integration tests --- dev-packages/browser-integration-tests/tsconfig.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev-packages/browser-integration-tests/tsconfig.json b/dev-packages/browser-integration-tests/tsconfig.json index aa450013ee95..ecc3b11d5e32 100644 --- a/dev-packages/browser-integration-tests/tsconfig.json +++ b/dev-packages/browser-integration-tests/tsconfig.json @@ -6,8 +6,9 @@ "moduleResolution": "node", "noEmit": true, "strict": true, - "allowSyntheticDefaultImports": true + "allowSyntheticDefaultImports": true, + "noUncheckedIndexedAccess": false }, "include": ["**/*.ts"], - "exclude": ["node_modules", "suites", "loader-suites"] + "exclude": ["node_modules"] }