Skip to content

Commit ab62810

Browse files
nicohrubecclaude
andcommitted
test(nuxt): Cover root-level option resolution and sourcemaps.disable
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 769aa9a commit ab62810

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

packages/nuxt/src/vite/sourceMaps.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ export function getPluginOptions(
163163
}
164164

165165
/**
166-
* Resolves the `filesToDeleteAfterUpload` value: the user-specified globs if provided, otherwise the
167-
* client/server fallback globs when Sentry enabled source maps itself. Logs the fallback in debug mode.
166+
* Users can set `filesToDeleteAfterUpload` themselves. If they don't, we fall back to deleting the
167+
* client/server source maps — but only the ones Sentry generated itself (i.e. when the user didn't
168+
* configure source maps at all). If the user explicitly set source maps, we leave their files alone.
168169
*/
169170
function resolveFilesToDeleteAfterUpload(
170171
moduleOptions: SentryNuxtModuleOptions,

packages/nuxt/test/vite/sourceMaps-nuxtHooks.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ describe('setupSourceMaps hooks', () => {
109109
expect(mockAddVitePlugin).not.toHaveBeenCalled();
110110
});
111111

112+
it('does not add plugins when source maps are disabled via `sourcemaps.disable`', async () => {
113+
const { setupSourceMaps } = await import('../../src/vite/sourceMaps');
114+
const mockNuxt = createMockNuxt({});
115+
const { mockAddVitePlugin } = createMockAddVitePlugin();
116+
117+
setupSourceMaps({ sourcemaps: { disable: true } }, mockNuxt as unknown as Nuxt, mockAddVitePlugin);
118+
await mockNuxt.triggerHook('modules:done');
119+
120+
expect(mockAddVitePlugin).not.toHaveBeenCalled();
121+
});
122+
112123
it.each([
113124
{ label: 'server (SSR) build', buildConfig: { build: { ssr: true }, plugins: [] } },
114125
{ label: 'client build', buildConfig: { build: { ssr: false }, plugins: [] } },

packages/nuxt/test/vite/sourceMaps.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,35 @@ describe('getPluginOptions', () => {
113113
);
114114
});
115115

116+
it('resolves root-level options into plugin options', () => {
117+
const errorHandler = (err: Error): void => {
118+
throw err;
119+
};
120+
const result = getPluginOptions({
121+
org: 'my-org',
122+
project: 'my-project',
123+
authToken: 'my-token',
124+
sentryUrl: 'https://my.sentry.io',
125+
telemetry: false,
126+
silent: true,
127+
errorHandler,
128+
headers: { 'X-Foo': 'bar' },
129+
release: { name: '1.2.3' },
130+
} as SentryNuxtModuleOptions);
131+
132+
expect(result).toMatchObject({
133+
org: 'my-org',
134+
project: 'my-project',
135+
authToken: 'my-token',
136+
url: 'https://my.sentry.io', // sentryUrl is resolved to the plugin's `url` option
137+
telemetry: false,
138+
silent: true,
139+
errorHandler,
140+
headers: { 'X-Foo': 'bar' },
141+
release: { name: '1.2.3' },
142+
});
143+
});
144+
116145
it('normalizes source paths via rewriteSources', () => {
117146
const options = getPluginOptions({} as SentryNuxtModuleOptions, undefined);
118147
const rewrite = options.sourcemaps?.rewriteSources as ((s: string) => string) | undefined;

0 commit comments

Comments
 (0)