From e0a3513e7389debdbd0d35215cafb6ce2cd3e47d Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Fri, 10 Jan 2025 13:50:24 +0100 Subject: [PATCH 1/2] feat(solidstart): Respect user-provided source map setting --- docs/migration/v8-to-v9.md | 2 +- packages/astro/src/integration/index.ts | 4 +- packages/astro/test/integration/index.test.ts | 4 +- .../src/vite/sentrySolidStartVite.ts | 11 +- packages/solidstart/src/vite/sourceMaps.ts | 149 +++++++++---- .../solidstart/test/config/withSentry.test.ts | 6 +- .../test/vite/sentrySolidStartVite.test.ts | 17 +- .../solidstart/test/vite/sourceMaps.test.ts | 201 +++++++++++++++--- 8 files changed, 306 insertions(+), 88 deletions(-) diff --git a/docs/migration/v8-to-v9.md b/docs/migration/v8-to-v9.md index 8d82fea6f0ad..4034e40f0cf5 100644 --- a/docs/migration/v8-to-v9.md +++ b/docs/migration/v8-to-v9.md @@ -98,7 +98,7 @@ In v9, an `undefined` value will be treated the same as if the value is not defi This behavior was changed because the Next.js Build ID is non-deterministic and the release name is injected into client bundles, causing build artifacts to be non-deterministic. This caused issues for some users. Additionally, because it is uncertain whether it will be possible to rely on a Build ID when Turbopack becomes stable, we decided to pull the plug now instead of introducing confusing behavior in the future. -### All Meta-Framework SDKs (`@sentry/astro`, `@sentry/nuxt`) +### All Meta-Framework SDKs (`@sentry/astro`, `@sentry/nuxt`, `@sentry/solidstart`) - Updated source map generation to respect the user-provided value of your build config, such as `vite.build.sourcemap`: diff --git a/packages/astro/src/integration/index.ts b/packages/astro/src/integration/index.ts index 5efeefa62153..79b74b8804c1 100644 --- a/packages/astro/src/integration/index.ts +++ b/packages/astro/src/integration/index.ts @@ -49,7 +49,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => { consoleSandbox(() => { // eslint-disable-next-line no-console console.log( - `[Sentry] Setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( + `[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( updatedFilesToDeleteAfterUpload, )}\` to delete generated source maps after they were uploaded to Sentry.`, ); @@ -226,7 +226,7 @@ export function getUpdatedSourceMapSettings( consoleSandbox(() => { // eslint-disable-next-line no-console console.warn( - `[Sentry] Source map generation are currently disabled in your Astro configuration (\`${settingKey}: false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, + `[Sentry] Source map generation is currently disabled in your Astro configuration (\`${settingKey}: false\`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, ); }); } else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { diff --git a/packages/astro/test/integration/index.test.ts b/packages/astro/test/integration/index.test.ts index d65cea37b261..6684a841ba4e 100644 --- a/packages/astro/test/integration/index.test.ts +++ b/packages/astro/test/integration/index.test.ts @@ -456,9 +456,7 @@ describe('getUpdatedSourceMapSettings', () => { astroConfig.vite.build.sourcemap = false; getUpdatedSourceMapSettings(astroConfig, sentryOptions); - expect(consoleWarnSpy).toHaveBeenCalledWith( - expect.stringContaining('Source map generation are currently disabled'), - ); + expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('Source map generation is currently disabled')); astroConfig.vite.build.sourcemap = 'hidden'; getUpdatedSourceMapSettings(astroConfig, sentryOptions); diff --git a/packages/solidstart/src/vite/sentrySolidStartVite.ts b/packages/solidstart/src/vite/sentrySolidStartVite.ts index 1bafc0cd07b5..b7248ad358b8 100644 --- a/packages/solidstart/src/vite/sentrySolidStartVite.ts +++ b/packages/solidstart/src/vite/sentrySolidStartVite.ts @@ -1,19 +1,22 @@ import type { Plugin, UserConfig } from 'vite'; import { makeBuildInstrumentationFilePlugin } from './buildInstrumentationFile'; -import { makeSourceMapsVitePlugin } from './sourceMaps'; +import { makeAddSentryVitePlugin, makeEnableSourceMapsVitePlugin } from './sourceMaps'; import type { SentrySolidStartPluginOptions } from './types'; /** * Various Sentry vite plugins to be used for SolidStart. */ -export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions = {}): Plugin[] => { +export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions = {}, viteConfig: UserConfig): Plugin[] => { const sentryPlugins: Plugin[] = []; sentryPlugins.push(makeBuildInstrumentationFilePlugin(options)); if (process.env.NODE_ENV !== 'development') { if (options.sourceMapsUploadOptions?.enabled ?? true) { - sentryPlugins.push(...makeSourceMapsVitePlugin(options)); + const sourceMapsPlugin = makeAddSentryVitePlugin(options, viteConfig); + const enableSourceMapsPlugin = makeEnableSourceMapsVitePlugin(options); + + sentryPlugins.push(...sourceMapsPlugin, ...enableSourceMapsPlugin); } } @@ -25,7 +28,7 @@ export const sentrySolidStartVite = (options: SentrySolidStartPluginOptions = {} */ export const addSentryPluginToVite = (config: UserConfig = {}, options: SentrySolidStartPluginOptions): UserConfig => { const plugins = Array.isArray(config.plugins) ? [...config.plugins] : []; - plugins.unshift(sentrySolidStartVite(options)); + plugins.unshift(sentrySolidStartVite(options, config)); return { ...config, diff --git a/packages/solidstart/src/vite/sourceMaps.ts b/packages/solidstart/src/vite/sourceMaps.ts index 0f8178356d88..1228249c193d 100644 --- a/packages/solidstart/src/vite/sourceMaps.ts +++ b/packages/solidstart/src/vite/sourceMaps.ts @@ -1,45 +1,37 @@ +import { consoleSandbox } from '@sentry/core'; import { sentryVitePlugin } from '@sentry/vite-plugin'; -import type { Plugin } from 'vite'; +import type { Plugin, UserConfig } from 'vite'; import type { SentrySolidStartPluginOptions } from './types'; /** - * A Sentry plugin for SolidStart to enable source maps and use - * @sentry/vite-plugin to automatically upload source maps to Sentry. - * @param {SourceMapsOptions} options + * A Sentry plugin for adding the @sentry/vite-plugin to automatically upload source maps to Sentry. */ -export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { +export function makeAddSentryVitePlugin(options: SentrySolidStartPluginOptions, viteConfig: UserConfig): Plugin[] { const { authToken, debug, org, project, sourceMapsUploadOptions } = options; - return [ - { - name: 'sentry-solidstart-source-maps', - apply: 'build', - enforce: 'post', - config(config) { - // TODO(v9): Remove this warning - if (config.build?.sourcemap === false) { - // eslint-disable-next-line no-console - console.warn( - "[Sentry SolidStart Plugin] You disabled sourcemaps with the `build.sourcemap` option. Currently, the Sentry SDK will override this option to generate sourcemaps. In future versions, the Sentry SDK will not override the `build.sourcemap` option if you explicitly disable it. If you want to generate and upload sourcemaps please set the `build.sourcemap` option to 'hidden' or undefined.", - ); - } - - // TODO(v9): Remove this warning and print warning in case source map deletion is auto configured - if (!sourceMapsUploadOptions?.filesToDeleteAfterUpload) { - // eslint-disable-next-line no-console - console.warn( - "[Sentry SolidStart Plugin] The Sentry SDK has enabled source map generation for your SolidStart app. If you don't want to serve Source Maps to your users, either configure the `filesToDeleteAfterUpload` option with a glob to remove source maps after uploading them, or manually delete the source maps after the build. In future Sentry SDK versions source maps will be deleted automatically after uploading them.", - ); - } - return { - ...config, - build: { - ...config.build, - sourcemap: true, - }, - }; - }, - }, + let updatedFilesToDeleteAfterUpload: string[] | undefined = undefined; + + if ( + typeof sourceMapsUploadOptions?.filesToDeleteAfterUpload === 'undefined' && + typeof sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps?.filesToDeleteAfterUpload === + 'undefined' && + // Only if source maps were previously not set, we update the "filesToDeleteAfterUpload" (as we override the setting with "hidden") + typeof viteConfig.build?.sourcemap === 'undefined' + ) { + // This also works for adapters, as the source maps are also copied to e.g. the .vercel folder + updatedFilesToDeleteAfterUpload = ['.*/**/*.map']; + + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.log( + `[Sentry] Automatically setting \`sourceMapsUploadOptions.filesToDeleteAfterUpload: ${JSON.stringify( + updatedFilesToDeleteAfterUpload, + )}\` to delete generated source maps after they were uploaded to Sentry.`, + ); + }); + } + + return [ ...sentryVitePlugin({ authToken: authToken ?? process.env.SENTRY_AUTH_TOKEN, bundleSizeOptimizations: options.bundleSizeOptimizations, @@ -47,7 +39,10 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions) org: org ?? process.env.SENTRY_ORG, project: project ?? process.env.SENTRY_PROJECT, sourcemaps: { - filesToDeleteAfterUpload: sourceMapsUploadOptions?.filesToDeleteAfterUpload ?? undefined, + filesToDeleteAfterUpload: + (sourceMapsUploadOptions?.filesToDeleteAfterUpload || + sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps?.filesToDeleteAfterUpload) ?? + updatedFilesToDeleteAfterUpload, ...sourceMapsUploadOptions?.unstable_sentryVitePluginOptions?.sourcemaps, }, telemetry: sourceMapsUploadOptions?.telemetry ?? true, @@ -60,3 +55,85 @@ export function makeSourceMapsVitePlugin(options: SentrySolidStartPluginOptions) }), ]; } + +/** + * A Sentry plugin for SolidStart to enable "hidden" source maps if they are unset. + */ +export function makeEnableSourceMapsVitePlugin(options: SentrySolidStartPluginOptions): Plugin[] { + return [ + { + name: 'sentry-solidstart-update-source-map-setting', + apply: 'build', + enforce: 'post', + config(viteConfig) { + return { + ...viteConfig, + build: { + ...viteConfig.build, + sourcemap: getUpdatedSourceMapSettings(viteConfig, options), + }, + }; + }, + }, + ]; +} + +/** There are 3 ways to set up source map generation (https://github.com/getsentry/sentry-j avascript/issues/13993) + * + * 1. User explicitly disabled source maps + * - keep this setting (emit a warning that errors won't be unminified in Sentry) + * - We won't upload anything + * + * 2. Users enabled source map generation (true, 'hidden', 'inline'). + * - keep this setting (don't do anything - like deletion - besides uploading) + * + * 3. Users didn't set source maps generation + * - we enable 'hidden' source maps generation + * - configure `filesToDeleteAfterUpload` to delete all .map files (we emit a log about this) + * + * --> only exported for testing + */ +export function getUpdatedSourceMapSettings( + viteConfig: UserConfig, + sentryPluginOptions?: SentrySolidStartPluginOptions, +): boolean | 'inline' | 'hidden' { + viteConfig.build = viteConfig.build || {}; + + const viteSourceMap = viteConfig?.build?.sourcemap; + let updatedSourceMapSetting = viteSourceMap; + + const settingKey = 'vite.build.sourcemap'; + + if (viteSourceMap === false) { + updatedSourceMapSetting = viteSourceMap; + + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.warn( + `[Sentry] Source map generation is currently disabled in your SolidStart configuration (\`${settingKey}: false \`). This setting is either a default setting or was explicitly set in your configuration. Sentry won't override this setting. Without source maps, code snippets on the Sentry Issues page will remain minified. To show unminified code, enable source maps in \`${settingKey}\` (e.g. by setting them to \`hidden\`).`, + ); + }); + } else if (viteSourceMap && ['hidden', 'inline', true].includes(viteSourceMap)) { + updatedSourceMapSetting = viteSourceMap; + + if (sentryPluginOptions?.debug) { + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.log( + `[Sentry] We discovered \`${settingKey}\` is set to \`${viteSourceMap.toString()}\`. Sentry will keep this source map setting. This will un-minify the code snippet on the Sentry Issue page.`, + ); + }); + } + } else { + updatedSourceMapSetting = 'hidden'; + + consoleSandbox(() => { + // eslint-disable-next-line no-console + console.log( + `[Sentry] Enabled source map generation in the build options with \`${settingKey}: 'hidden'\`. The source maps will be deleted after they were uploaded to Sentry.`, + ); + }); + } + + return updatedSourceMapSetting; +} diff --git a/packages/solidstart/test/config/withSentry.test.ts b/packages/solidstart/test/config/withSentry.test.ts index e554db45124f..8f6f02245553 100644 --- a/packages/solidstart/test/config/withSentry.test.ts +++ b/packages/solidstart/test/config/withSentry.test.ts @@ -79,13 +79,13 @@ describe('withSentry()', () => { const names = config?.vite.plugins.flat().map((plugin: Plugin) => plugin.name); expect(names).toEqual([ 'sentry-solidstart-build-instrumentation-file', - 'sentry-solidstart-source-maps', 'sentry-telemetry-plugin', 'sentry-vite-release-injection-plugin', 'sentry-debug-id-upload-plugin', 'sentry-vite-debug-id-injection-plugin', 'sentry-vite-debug-id-upload-plugin', 'sentry-file-deletion-plugin', + 'sentry-solidstart-update-source-map-setting', ]); }); @@ -107,13 +107,13 @@ describe('withSentry()', () => { const names = config?.vite.plugins.flat().map((plugin: Plugin) => plugin.name); expect(names).toEqual([ 'sentry-solidstart-build-instrumentation-file', - 'sentry-solidstart-source-maps', 'sentry-telemetry-plugin', 'sentry-vite-release-injection-plugin', 'sentry-debug-id-upload-plugin', 'sentry-vite-debug-id-injection-plugin', 'sentry-vite-debug-id-upload-plugin', 'sentry-file-deletion-plugin', + 'sentry-solidstart-update-source-map-setting', 'my-test-plugin', ]); }); @@ -139,13 +139,13 @@ describe('withSentry()', () => { .map((plugin: Plugin) => plugin.name); expect(names).toEqual([ 'sentry-solidstart-build-instrumentation-file', - 'sentry-solidstart-source-maps', 'sentry-telemetry-plugin', 'sentry-vite-release-injection-plugin', 'sentry-debug-id-upload-plugin', 'sentry-vite-debug-id-injection-plugin', 'sentry-vite-debug-id-upload-plugin', 'sentry-file-deletion-plugin', + 'sentry-solidstart-update-source-map-setting', 'my-test-plugin', ]); }); diff --git a/packages/solidstart/test/vite/sentrySolidStartVite.test.ts b/packages/solidstart/test/vite/sentrySolidStartVite.test.ts index 8915c5a70671..5e2d0f56232b 100644 --- a/packages/solidstart/test/vite/sentrySolidStartVite.test.ts +++ b/packages/solidstart/test/vite/sentrySolidStartVite.test.ts @@ -10,12 +10,15 @@ vi.spyOn(console, 'warn').mockImplementation(() => { }); function getSentrySolidStartVitePlugins(options?: Parameters[0]): Plugin[] { - return sentrySolidStartVite({ - project: 'project', - org: 'org', - authToken: 'token', - ...options, - }); + return sentrySolidStartVite( + { + project: 'project', + org: 'org', + authToken: 'token', + ...options, + }, + {}, + ); } describe('sentrySolidStartVite()', () => { @@ -24,13 +27,13 @@ describe('sentrySolidStartVite()', () => { const names = plugins.map(plugin => plugin.name); expect(names).toEqual([ 'sentry-solidstart-build-instrumentation-file', - 'sentry-solidstart-source-maps', 'sentry-telemetry-plugin', 'sentry-vite-release-injection-plugin', 'sentry-debug-id-upload-plugin', 'sentry-vite-debug-id-injection-plugin', 'sentry-vite-debug-id-upload-plugin', 'sentry-file-deletion-plugin', + 'sentry-solidstart-update-source-map-setting', ]); }); diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index e7d6c1bd598d..8996a908fbe9 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -1,6 +1,10 @@ import type { SentryVitePluginOptions } from '@sentry/vite-plugin'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { makeSourceMapsVitePlugin } from '../../src/vite/sourceMaps'; +import { + getUpdatedSourceMapSettings, + makeAddSentryVitePlugin, + makeEnableSourceMapsVitePlugin, +} from '../../src/vite/sourceMaps'; const mockedSentryVitePlugin = { name: 'sentry-vite-debug-id-upload-plugin', @@ -24,27 +28,33 @@ beforeEach(() => { describe('makeSourceMapsVitePlugin()', () => { it('returns a plugin to set `sourcemaps` to `true`', () => { - const [sourceMapsConfigPlugin, sentryVitePlugin] = makeSourceMapsVitePlugin({}); + const sourceMapsConfigPlugins = makeEnableSourceMapsVitePlugin({}); + const enableSourceMapPlugin = sourceMapsConfigPlugins[0]; - expect(sourceMapsConfigPlugin?.name).toEqual('sentry-solidstart-source-maps'); - expect(sourceMapsConfigPlugin?.apply).toEqual('build'); - expect(sourceMapsConfigPlugin?.enforce).toEqual('post'); - expect(sourceMapsConfigPlugin?.config).toEqual(expect.any(Function)); + expect(enableSourceMapPlugin?.name).toEqual('sentry-solidstart-update-source-map-setting'); + expect(enableSourceMapPlugin?.apply).toEqual('build'); + expect(enableSourceMapPlugin?.enforce).toEqual('post'); + expect(enableSourceMapPlugin?.config).toEqual(expect.any(Function)); - expect(sentryVitePlugin).toEqual(mockedSentryVitePlugin); + expect(sourceMapsConfigPlugins).toHaveLength(1); }); +}); - it('passes user-specified vite plugin options to vite plugin plugin', () => { - makeSourceMapsVitePlugin({ - org: 'my-org', - authToken: 'my-token', - sourceMapsUploadOptions: { - filesToDeleteAfterUpload: ['baz/*.js'], - }, - bundleSizeOptimizations: { - excludeTracing: true, +describe('makeAddSentryVitePlugin()', () => { + it('passes user-specified vite plugin options to vite plugin', () => { + makeAddSentryVitePlugin( + { + org: 'my-org', + authToken: 'my-token', + sourceMapsUploadOptions: { + filesToDeleteAfterUpload: ['baz/*.js'], + }, + bundleSizeOptimizations: { + excludeTracing: true, + }, }, - }); + {}, + ); expect(sentryVitePluginSpy).toHaveBeenCalledWith( expect.objectContaining({ @@ -60,25 +70,91 @@ describe('makeSourceMapsVitePlugin()', () => { ); }); - it('should override options with unstable_sentryVitePluginOptions', () => { - makeSourceMapsVitePlugin({ - org: 'my-org', - authToken: 'my-token', - bundleSizeOptimizations: { - excludeTracing: true, + it('should update `filesToDeleteAfterUpload` if source map generation was previously not defined', () => { + makeAddSentryVitePlugin( + { + org: 'my-org', + authToken: 'my-token', + bundleSizeOptimizations: { + excludeTracing: true, + }, }, - sourceMapsUploadOptions: { - unstable_sentryVitePluginOptions: { - org: 'unstable-org', - sourcemaps: { - assets: ['unstable/*.js'], - }, - bundleSizeOptimizations: { - excludeTracing: false, + {}, + ); + + expect(sentryVitePluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ + sourcemaps: expect.objectContaining({ + filesToDeleteAfterUpload: ['.*/**/*.map'], + }), + }), + ); + }); + + it('should not update `filesToDeleteAfterUpload` if source map generation was previously enabled', () => { + makeAddSentryVitePlugin( + { + org: 'my-org', + authToken: 'my-token', + bundleSizeOptimizations: { + excludeTracing: true, + }, + }, + { build: { sourcemap: true } }, + ); + + expect(sentryVitePluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ + sourcemaps: expect.objectContaining({ + filesToDeleteAfterUpload: undefined, + }), + }), + ); + }); + + it('should not update `filesToDeleteAfterUpload` if source map generation was previously disabled', () => { + makeAddSentryVitePlugin( + { + org: 'my-org', + authToken: 'my-token', + bundleSizeOptimizations: { + excludeTracing: true, + }, + }, + { build: { sourcemap: false } }, + ); + + expect(sentryVitePluginSpy).toHaveBeenCalledWith( + expect.objectContaining({ + sourcemaps: expect.objectContaining({ + filesToDeleteAfterUpload: undefined, + }), + }), + ); + }); + + it('should override options with unstable_sentryVitePluginOptions', () => { + makeAddSentryVitePlugin( + { + org: 'my-org', + authToken: 'my-token', + bundleSizeOptimizations: { + excludeTracing: true, + }, + sourceMapsUploadOptions: { + unstable_sentryVitePluginOptions: { + org: 'unstable-org', + sourcemaps: { + assets: ['unstable/*.js'], + }, + bundleSizeOptimizations: { + excludeTracing: false, + }, }, }, }, - }); + {}, + ); expect(sentryVitePluginSpy).toHaveBeenCalledWith( expect.objectContaining({ @@ -94,3 +170,64 @@ describe('makeSourceMapsVitePlugin()', () => { ); }); }); + +describe('getUpdatedSourceMapSettings', () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.spyOn(console, 'warn').mockImplementation(() => {}); + vi.spyOn(console, 'log').mockImplementation(() => {}); + }); + + describe('when sourcemap is false', () => { + it('should keep sourcemap as false and show warning', () => { + const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); + + expect(result).toBe(false); + expect(console.warn).toHaveBeenCalledWith( + expect.stringContaining('[Sentry] Source map generation is currently disabled'), + ); + }); + }); + + describe('when sourcemap is explicitly set to valid values', () => { + it.each([ + ['hidden', 'hidden'], + ['inline', 'inline'], + [true, true], + ])('should keep sourcemap as %s when set to %s', (input, expected) => { + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); + + expect(result).toBe(expected); + expect(console.log).toHaveBeenCalledWith( + expect.stringContaining(`[Sentry] We discovered \`vite.build.sourcemap\` is set to \`${input.toString()}\``), + ); + }); + }); + + describe('when sourcemap is undefined or invalid', () => { + it.each([[undefined], ['invalid'], ['something'], [null]])( + 'should set sourcemap to hidden when value is %s', + input => { + const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); + + expect(result).toBe('hidden'); + expect(console.log).toHaveBeenCalledWith( + expect.stringContaining( + "[Sentry] Enabled source map generation in the build options with `vite.build.sourcemap: 'hidden'`", + ), + ); + }, + ); + + it('should set sourcemap to hidden when build config is empty', () => { + const result = getUpdatedSourceMapSettings({}); + + expect(result).toBe('hidden'); + expect(console.log).toHaveBeenCalledWith( + expect.stringContaining( + "[Sentry] Enabled source map generation in the build options with `vite.build.sourcemap: 'hidden'`", + ), + ); + }); + }); +}); From 09cd3d3389ceb346618322f71523c31bac66cae0 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 13 Jan 2025 09:26:30 +0100 Subject: [PATCH 2/2] fix eslint --- packages/solidstart/test/vite/sourceMaps.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/solidstart/test/vite/sourceMaps.test.ts b/packages/solidstart/test/vite/sourceMaps.test.ts index 8996a908fbe9..7254b126ce93 100644 --- a/packages/solidstart/test/vite/sourceMaps.test.ts +++ b/packages/solidstart/test/vite/sourceMaps.test.ts @@ -183,6 +183,7 @@ describe('getUpdatedSourceMapSettings', () => { const result = getUpdatedSourceMapSettings({ build: { sourcemap: false } }); expect(result).toBe(false); + // eslint-disable-next-line no-console expect(console.warn).toHaveBeenCalledWith( expect.stringContaining('[Sentry] Source map generation is currently disabled'), ); @@ -194,10 +195,11 @@ describe('getUpdatedSourceMapSettings', () => { ['hidden', 'hidden'], ['inline', 'inline'], [true, true], - ])('should keep sourcemap as %s when set to %s', (input, expected) => { + ] as ('inline' | 'hidden' | boolean)[][])('should keep sourcemap as %s when set to %s', (input, expected) => { const result = getUpdatedSourceMapSettings({ build: { sourcemap: input } }, { debug: true }); expect(result).toBe(expected); + // eslint-disable-next-line no-console expect(console.log).toHaveBeenCalledWith( expect.stringContaining(`[Sentry] We discovered \`vite.build.sourcemap\` is set to \`${input.toString()}\``), ); @@ -211,6 +213,7 @@ describe('getUpdatedSourceMapSettings', () => { const result = getUpdatedSourceMapSettings({ build: { sourcemap: input as any } }); expect(result).toBe('hidden'); + // eslint-disable-next-line no-console expect(console.log).toHaveBeenCalledWith( expect.stringContaining( "[Sentry] Enabled source map generation in the build options with `vite.build.sourcemap: 'hidden'`", @@ -223,6 +226,7 @@ describe('getUpdatedSourceMapSettings', () => { const result = getUpdatedSourceMapSettings({}); expect(result).toBe('hidden'); + // eslint-disable-next-line no-console expect(console.log).toHaveBeenCalledWith( expect.stringContaining( "[Sentry] Enabled source map generation in the build options with `vite.build.sourcemap: 'hidden'`",